gpt4 book ai didi

algorithm - 简化 Tic Tac Toe 的 MiniMax 算法

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:00:26 25 4
gpt4 key购买 nike

我有一个运行完美的井字游戏,但有什么方法可以改变我拥有的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com