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

前端 未结 5 1282
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

    If you want to generate the tree in memory (which is not necessary), perhaps an algorithm like the following could be used (pseudo-code):

    GenTree(State s):
      T <- empty tree  // T is a tree of States
      SetRoot(T, s)
    
      ForEach (s' in Successors(s)):
        AddChild(T, GenTree(s'))
    
      return T
    
    // Call it
    GenTree(currentMove)
    

    where

    Successors(s)  // returns a list of successor states of s
    AddChild(p, n)  // adds n to the list of p's children
    

提交回复
热议问题