当前位置: 首页>>代码示例>>Python>>正文


Python Player.minValue方法代码示例

本文整理汇总了Python中Player.minValue方法的典型用法代码示例。如果您正苦于以下问题:Python Player.minValue方法的具体用法?Python Player.minValue怎么用?Python Player.minValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Player的用法示例。


在下文中一共展示了Player.minValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: minimaxMove

# 需要导入模块: import Player [as 别名]
# 或者: from Player import minValue [as 别名]
 def minimaxMove(self, board, ply):
     """ Choose the best minimax move.  Returns (score, move) """
     move = -1
     score = -INFINITY
     turn = self
     for m in board.legalMoves(self):
         #for each legal move
         if ply == 0:
             #if we're at ply 0, we need to call our eval function & return
             return (self.score(board), m)
         if board.gameOver():
             return (-1, -1)  # Can't make a move, the game is over
         nb = deepcopy(board)
         #make a new board
         nb.makeMove(self, m)
         #try the move
         opp = Player(self.opp, self.type, self.ply)
         s = opp.minValue(nb, ply-1, turn)
         #and see what the opponent would do next
         if s > score:
             #if the result is better than our best score so far, save that move,score
             move = m
             score = s
     #return the best score and move so far
     return score, move
开发者ID:tenaciousj,项目名称:NUAssignments,代码行数:27,代码来源:TicTacToe.py

示例2: maxValue

# 需要导入模块: import Player [as 别名]
# 或者: from Player import minValue [as 别名]
 def maxValue(self, board, ply, turn):
     """ Find the minimax value for the next move for this player
     at a given board configuation. Returns score."""
     if board.gameOver():
         return turn.score(board)
     score = -INFINITY
     for m in board.legalMoves(self):
         if ply == 0:
             #print "turn.score(board) in max value is: " + str(turn.score(board))
             return turn.score(board)
         # make a new player to play the other side
         opponent = Player(self.opp, self.type, self.ply)
         # Copy the board so that we don't ruin it
         nextBoard = deepcopy(board)
         nextBoard.makeMove(self, m)
         s = opponent.minValue(nextBoard, ply-1, turn)
         #print "s in maxValue is: " + str(s)
         if s > score:
             score = s
     return score
开发者ID:tenaciousj,项目名称:NUAssignments,代码行数:22,代码来源:TicTacToe.py


注:本文中的Player.minValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。