本文整理汇总了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)
示例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