Return bestMove in minimax algorithm for tictactoe

前端 未结 3 2055
遥遥无期
遥遥无期 2020-12-29 00:35

I have tried to code the minimax algorithm for tic-tac-toe given in Russel Norvig\'s book on Artificial Intelligence. It had everything except that the way to return the bes

3条回答
  •  攒了一身酷
    2020-12-29 01:14

    Your code finds the correct value but then overwrites it by passing the same reference down.

    int curValue = min_move(state,bestMove);
    

    should become

    moveT nextMove; // No need to actually do anything with this value
    int curValue = min_move(state,nextMove);
    

    You also need to make the same kind of change in your min_move function.

    NB: in min_move your code calls max_move with more arguments than you've defined for the function.

提交回复
热议问题