本文整理汇总了Python中gamestate.GameState.copyState方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.copyState方法的具体用法?Python GameState.copyState怎么用?Python GameState.copyState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gamestate.GameState
的用法示例。
在下文中一共展示了GameState.copyState方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recBestMove
# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import copyState [as 别名]
def recBestMove(self, gameState, evalAsPlayer, options, depth=0, st=""):
if depth == 0: return [0,None,None,gameState];
arr = [];
for commandList in options.enumerateAll(deferToPlayer=evalAsPlayer):
newGameState = GameState();
newGameState.copyState(gameState);
outputList = [];
anyChoices = False;
for i,command in enumerate(commandList):
if isinstance(command, Command):
outputList.append(command);
newGameState.processCommand(command.command);
continue;
#it's a CommandOption
score, _, chosenList, newGameState = self.recBestMove(newGameState, command.evalAsPlayer, command, depth=1);
outputList.extend(chosenList);
anyChoices = True;
score = self.evaluateGameState(evalAsPlayer, newGameState);
if anyChoices == False: del outputList; outputList = commandList;
arr.append( [score, commandList, outputList, newGameState] );
arr.sort(reverse=True);
if depth > 1:
for i in xrange(len(arr)):
oldGameState = arr[i][-1];
if oldGameState.currentPlayer == gameState.currentPlayer: oldGameState.nextPlayer();
options = oldGameState.generateOperations(oldGameState.currentPlayer);
_, _, _, newGameState = self.recBestMove(oldGameState, oldGameState.currentPlayer, options, depth-1);
if self.keepCalculating() == False: break;
if oldGameState == newGameState: continue;
arr[i][0] = self.evaluateGameState(evalAsPlayer, newGameState, display=False);
arr.sort(reverse=True);
return arr[0];