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


Python Player.minValueAB方法代码示例

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


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

示例1: alphaBetaMove

# 需要导入模块: import Player [as 别名]
# 或者: from Player import minValueAB [as 别名]
    def alphaBetaMove(self, board, ply):
        """ Choose a move with alpha beta pruning.  Returns (score, move) """
        move = -1
        score = -INFINITY
        turn = self
        alpha = -INFINITY
        beta = INFINITY
        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.minValueAB(nb, ply-1, alpha, beta, 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

        
        print "Alpha Beta Move not yet implemented"
        #returns the score adn the associated moved
        return (-1,1)
开发者ID:tenaciousj,项目名称:NUAssignments,代码行数:34,代码来源:TicTacToe.py

示例2: maxValueAB

# 需要导入模块: import Player [as 别名]
# 或者: from Player import minValueAB [as 别名]
 def maxValueAB(self, board, ply, alpha, beta, turn):
     if board.gameOver():
         return turn.score(board)
     v = -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)
         v = max(v,opponent.minValueAB(nextBoard, ply-1, alpha, beta, turn))
         #print "s in maxValue is: " + str(s)
         if v >= beta:
             return v 
         alpha = max(alpha, v)
     return v
开发者ID:tenaciousj,项目名称:NUAssignments,代码行数:21,代码来源:TicTacToe.py


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