TicTacToe AI Making Incorrect Decisions

后端 未结 4 1256
攒了一身酷
攒了一身酷 2021-02-08 12:30

A little background: as a way to learn multinode trees in C++, I decided to generate all possible TicTacToe boards and store them in a tree such that the branch beginning at a n

4条回答
  •  面向向阳花
    2021-02-08 13:08

    The (usually) correct way to implement AI based on a decision tree is to use the "Minimax" algorithm:

    1. Assign each leaf node a score (+1=player wins, -1=player loses, 0=tie)
    2. Work your way up the tree, applying the following rules to each node:

      • For even depths (when the player would make a move), pick the child with the highest score, and copy that score to the node.
      • For odd depths (when the computer would make a move), pick the child with the lowest score, and copy that score to the node.

    Of course, even and odd might need to be reversed, depending on who you decide goes first.

    You can read more at:

    • http://ai-depot.com/articles/minimax-explained/
    • http://en.wikipedia.org/wiki/Minimax

提交回复
热议问题