2

I am building an application of checkers.

I have started to build the AI and I've read alot about minimax.

There is something that i couldn't understand, what type of tree should I use to build the "game tree" (I'm programming in JAVA)

nivik
  • 51
  • 1
  • 5
  • Notice that unlike other trees like binary trees, 2-3 trees, and heap trees, a node in the minimax game tree can have any number of children, depending on the game situation. This tree consists of a single root node with multiple children, which can have again multiple children, depending on their outcome. To support this graphically. http://commons.wikimedia.org/wiki/File:Plminmax.gif –  Jan 07 '15 at 09:21
  • ok thanks and what is the name of this tree in the API of java? or should i build this tree's class on my own? – nivik Jan 07 '15 at 09:24
  • I would recommend to build a tree on your own, this will give you much more insight how trees are actual working and how you can traverse trough one. –  Jan 07 '15 at 12:00
  • Use this as a starting point: http://stackoverflow.com/questions/3522454/java-tree-data-structure –  Jan 07 '15 at 12:06
  • Duplicate of http://stackoverflow.com/questions/27249304/tree-representation-in-java-for-minimax-algorithm/. You don't need actually need a tree data structure for minimax - the algorithm traverses a tree, but you don't need to store it. You can use a list to store the children of a node while you're evaluating it. – Andy Thomas Jan 08 '15 at 15:33

2 Answers2

2

In general minimax game trees are simple: each node represents a state of the game and contains a collection of all child nodes representing all the allowed moves from that state.

Here is a possible implementation:

class Node {
    private Board state;
    private Map<Move, Node> children;
}
sprinter
  • 27,148
  • 6
  • 47
  • 78
  • I'm not sure I understand how this should be used. Why `Map`? – garci560 Aug 28 '17 at 17:57
  • The `Node` represents a potential state of play. `Move` represents a potential move from that state. The `children` map maps all potential moves from one state to another. So in chess, if the state represents the staring position, `children` would map the 18 legal first moves to the state resulting after that move. – sprinter Aug 29 '17 at 03:45
  • Also note that in many (possibly most) cases you don't actually need a tree like this to implement minimax because you can store the required state as you calculate. There are lots of examples of code like this in various tutorials. – sprinter Aug 29 '17 at 03:47
0

The minimax algorithm can also be implemented without explicitly encoding the game tree. In each recursive step, the move is actually done on some representation of the game board, then recusively calling the evaluation again, and after evaluation un-doing the move to evaluate. This approach is more memory efficient as only the node of the game tree in consideration is explicitly represented. In this approach, the call stack and the game board representation together can be interpreted as node iterator for the game tree.

Codor
  • 17,447
  • 9
  • 29
  • 56