0

我有一个完美运行的井字游戏,但是有没有办法可以改变我拥有的 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
4

2 回答 2

1

我想有人可能已经为你做了这个......请参阅关于Negamax的维基百科,“一种依赖于两人游戏的零和属性的极小极大搜索的变体形式。”

来自弗赖恩

SEARCHING_FUNCTION {
  Decrease depth by 1
  Loop through all moves
    Play move
    if ( depth = 0 ) move_score = static_position_score
    else move_score = - Opponent's_best_move_score    
    if ( move_score > best_move_score ) then ( best_move = move )        
    Undo Move     
  End of Loop
  Return best_move_score
} END
于 2014-04-15T20:11:42.480 回答
1

如果您正在寻找优化/加速 Min Max 看看 Alpha Beta Pruning - 相同的算法,但具有最佳快捷方式

于 2014-04-15T09:57:35.860 回答