Need Urgent Help! Tic Tac Toe

Out of nowhere, my professor has assigned me a project where i have to construct a tic tac toe game, implementing a simple AI which presents 3 scenarios:

In the following example, X takes a winning move:

Enter board as state of 9 integers, 0-2:
1 1 0 2 0 0 0 2 0
C u r r e n t b o a r d :
+−+−+−+
|1|1|0|
+−+−+−+
|2|0|0|
+−+−+−+
|0|2|0|
+−+−+−+
X moves to C to win! New board
+−+−+−+
|1|1|1|
+−+−+−+
|2|0|0|
+−+−+−+
|0|2|0|
+−+−+−+

In this scenario, the X is the AI occupying integer 1, and sees a winning spot and claims it.


There are 2 other scenarios, where X, the AI makes a move to block the player from winning, and another scenario where there are no winning/losing moves to make so the AI makes a random move


I am at a complete loss here, and the project is due tomorrow. Can someone give me a starting point?

The board can be simply stored in an array such as:

1
2
3
4
5
6
7
char myBoard[3][3] = {

	1, 2, 3,
	4, 5, 6,
	7, 8, 9

};


The numbers could be used to show the user what key to press to enter their move thus placing a X or O there provided there isn't already one or the other there already.

Then you could check all the possible winning combinations.

The array would be accessed by myBoard[row][column] remembering that arrays start at index 0 therefore if we wanted row one and second column (value 2) we would use myBoard[0][1]

Hope this gives you some idea what direction you need to take.

Topic archived. No new replies allowed.