blob: e41210497561c4b9324df16204a21ec50c0d8adf (
plain)
1
2
3
4
5
6
7
8
|
Compile ttt.c in whatever manner you like, and run it. Enter coordinates in the form a2, or 1c to select your move.
The minimax AI will perform a tree search to determine its move. The AI will never lose, and may win if you make a mistake.
The AI is limited in the sense that it assumes you will play perfectly. It will not attempt to trick you into playing a poor move.
If you wish to modify the code, it should be fairly self-explanatory. There is an array named get_move_ptrs which is defined in main(). This array gives pointers to functions that get input.
When an X is to be placed, the function pointed to by get_move_ptrs[0] is called. When a Y is to be placed, get_move_ptrs[1].
To have two human players play against each other, replace each pointer with user_input_pos. For two minimax bots, ai_input_pos.
To implement a new AI model or new player interface, simply define a function accepting a 2d array (the current board state) and an int (the player whose turn it is). This function must return an int*, with the X coordinate of the move in [0] and the Y coordinate in [1].
|