我有一个Tic-Tac-Toe游戏,它工作得很好,但是有没有一种方法可以改变我的MiniMax算法所以它在某种程度上更简单,甚至更简短。
def maximized_move(self,gameinstance):
''' Find maximized move'''
bestscore = None
bestmove = None
for m in gameinstance.get_free_positions():
gameinstance.mark(self.marker,m)
if gameinstance.is_gameover():
score = self.get_score(gameinstance)
else:
move_position,score = self.minimized_move(gameinstance)
gameinstance.revert_last_move()
if bestscore == None or score > bestscore:
bestscore = score
bestmove = m
return bestmove, bestscore
def minimized_move(self,gameinstance):
''' Find the minimized move'''
bestscore = None
bestmove = None
for m in gameinstance.get_free_positions():
gameinstance.mark(self.opponentmarker,m)
if gameinstance.is_gameover():
score = self.get_score(gameinstance)
else:
move_position,score = self.maximized_move(gameinstance)
gameinstance.revert_last_move()
if bestscore == None or score < bestscore:
bestscore = score
bestmove = m
return bestmove, bestscore
最佳答案
如果你想优化/加速Min Max,看看Alpha Beta剪枝-同样的算法,但有最佳的快捷方式
关于algorithm - 简化Tic Tac Toe的MiniMax算法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23080241/