So I was recently looking at the minimax function which is used in zero sum games. I understood it perfectly, other then how the board is implemented for the actual function:
For example this sample implementation I found has this declaration:
int miniMax(Board eval, int iterations)
My only question is what exactly is Board? Is it a struct, class, array or some other structure? Also how would I implement a sample board for mini-max, like a tic-tac-toe board (As a example)? Couldn’t find anything on Wikipedia or Google.
Board is just the current board game. It could be any structure you use to represent the board of the game.
When called first, the minimax function would receive the current board configuration, reached by the different plays made so far (the current state of the game). In the minimax function what you do is modify the board, each modification should represent a possible move according to the game rules. Each of those modified boards should be passed as argument to a new minimax call. Once you reach a certain depth (this is, a number of iterations), you select the best move using an evaluation function to give a score to every modified board and choosing the one with the highest score.
The algorithm you are reading is generic and could work for any game. You might define Board according to convenience, that is, what suits best for the board of the game you want to represent.
For tic-tac-toe, you might want to represent the board with a 3×3 array so you might change Board:
Or perhaps, you may want to represent your board using 2 bits for each square:
Though, for tic-tac-toe you don’t need a lightweight board representation since its maximum depth is just 9. I’m just giving you examples to let you understand it can be any structure you use to represent the board game.
If you are going to deal with minimax function and the game is much more complex than tic-tac-toe, you should seriously consider using alpha-beta pruning which is a big improvement.
EDIT: I think you shouldn’t call your board “eval” since that can be confused with the evaluation function which is a totally different thing.