2021年4月1日星期四

Bug in MiniMax Algorithm in Othello Program

pline is used to collect principal variation

I had used this link: Collecting pline from alphabeta for collecting pline

Here is the Code:

def minimax(board,player,is_max_player,depth,pline):      line = []      bestvalue = Data.MIN_INT if is_max_player else Data.MAX_INT       if depth == 0:          return Evaluator.evaluate(board,player)               move_list = MoveGen.get_move_list(board,player)      if MoveGen.is_move_possible(board,player): ## If the player has move then make move for player                history_list  = []          for move in move_list:              bestmove = None              MoveGen.make_move(board,history_list,move)              value = minimax(board,Utils.get_opponent(player),False,depth-1,line)               MoveGen.unmake_move(board,history_list)              if is_max_player:                  bestvalue = max(value,bestvalue)                  bestmove  = move              else:                     bestvalue = min(value,bestvalue)                  bestmove  = move              bestmove['value'] = bestvalue              pline[:] = [bestmove] + line              return bestvalue      else:          if MoveGen.is_move_possible(board,Utils.get_opponent(player)): #if opponent has move then return minimax for opponent                     return minimax(board,Utils.get_opponent(player),False,depth-1,line)          else: #gameover Neither player nor opponent has move              return Evaluator.evaluate(board,player)           

Initial Call

def think(board,player,depth):      pline = []      score = minimax(board,player,True,depth,pline)      return pline  

Its always return the first items of the list in each depth.

https://stackoverflow.com/questions/66913443/bug-in-minimax-algorithm-in-othello-program April 02, 2021 at 09:32AM

没有评论:

发表评论