Tic-Tac-Toe AI: How to Make the Tree?

前端 未结 5 1278
Happy的楠姐
Happy的楠姐 2021-02-01 08:11

I\'m having a huge block trying to understand \"trees\" while making a Tic-Tac-Toe bot. I understand the concept, but I can\'t figure out to implement them.

Can someone

5条回答
  •  执笔经年
    2021-02-01 09:03

    I don't think you need to keep a tree in memory. You simply need to implement a recursive function that works something like:

    Move getBestMove(Board state, boolean myTurn)
    

    Then you simply recurse until you've reached a winning, losing or draw-state.

    The call-stack would over time look like a tree if you drew it on paper. You should return the move that leads to a node at which the opponent (definitely / most likely) looses (even though he also plays using getBestMove)

    For a state-space as little as tic-tac-toe however, you could simply do a full look-up-table with the best moves! :-)

提交回复
热议问题