Tic Tac Toe Program

Pages: 12
greater beings then us have devised the MiniMax algorithm that you could use to create a smart computer. Its very complicated but if you are determined, you will learn how to make a computer AI not just for tic tac dou but also connect 4, checkers, and even chess. any game basically that is turn based and you can count its possibilities, and you can evaluate your score can be programmed using this algorithm.

you could implement the minimax algorithm recursively,

you will have a function that recieves a board, and whos turn it is. and return to you the best move for that player on that turn.

looks something like this.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

struct Move{
   int row, col;
   int player;
   int chance_to_win;
};

Move foo(char board[3][3],wf){
   

   //calculate all possible moves, if you have a victory move return it, if its a last turn tie move return it.

   //for each possible move do
   //calculate board after move
   Move opponent_move = foo( board_after_move, 3-wf );

   //your chance to win is 100 - biggest opponent chance.

   //return move with the biggest chance_to_win.
}



anyway, this is very complex thing to do for the first time, and the second.

all what you said is done except AI Algorithm :D
thanks for tips :)
Topic archived. No new replies allowed.
Pages: 12