Im trying to create my first game using the minimax algorithm but i dont know how to implement this using a tree.
The game rules are the following:
On table there are M cubes(for example 40) and each player must take from the table 1 or L cubes (L is defined in program. for example L=5).
The winner is the player who takes the last cube from table.
The player who plays first is MAX(the computer) and second plays the MIN(human).
Firstly we must run the minimax algorithm and then the player MAX plays with the best move.
This is the game but i cant imagine how to implement this with tree. Can anyone help me and give me an idea?
It's not that you create a tree, but that your search can be described as a tree.
Say it's Tic-Tac-Toe, to take a more familiar example. You are X. You have 9 options, 9 possible moves.
After that, as it happens, O will have 8 possible moves. And so on.
You can perform a depth-first search (with a depth limit to be sure), and each time you get the results back from the children, you take the min (or the max) result.
This page discusses it with a Tic-Tac-Toe example at greater length: http://neverstopbuilding.com/minimax . Note that their algorithm is recursive, which makes accumulating the children's scores relatively simple.