# saveing moves

• 10-13-2002
Neoground1
saveing moves
I was wondering how to save a move (from the tic tac toe game) to a specific area in an array. For example when the player makes his first move i want to store the number of the square that he chose in the array moves[0] (while moves[9] has goes from 0-9) and so on like that? Any suggestions? Understand the question?
• 10-13-2002
Eibro
enum tictac { player1, player2, empty };

tictac board[9] = { empty };

//...

if (it_is_player_1s_ turn())
{
board[move] = player1;
} else if (it_is_player_2s_turn()) {
board[move] = player2;
}

Understand?
• 10-13-2002
Neoground1
I think I do. R u saying make two arrays. One for the players and one for the board, and then say that if it is player1s turn then use the board array (for the first move it would be board[0]) to equal player1. Witch mean it would be player1's turn. If not then do the same for player two. Right? But do i actually write "empty" in the board array when i delcare it?
• 10-13-2002
Neoground1
O and what exactly is enum? We never talked about it in class and theres not much about it in my book. All it says is its a way to declare simple data types. But what exactly is it used for?
• 10-13-2002
Eibro
enum is an enumerative type, it's just a new data type. The one we declare tictac is basically an int, which can hold the values 0, 1 or 2.

Kinda like a bool, but with 3 different values.
If I have a bool variable, I can go

bool myBool = false;
or
bool myBool = 0;
The two expressions are exactly the same!

Likewise, for our enum tictac, I can go

tictac myTicTac = player1;
or
tictac myTicTac = 0;

If I wanted to declare my own boolean data type, I could go
enum boolean { TRUE, FALSE };

Get it? So basically we have a tictac array, which is empty. Each time a player moves, we find the correct position in our tictac array and set it equal to the moving player.
• 10-13-2002
Neoground1
Ok I get that. I know how to set the moves to the two differant players. But what I dont get is how I can save the moves so that I can recall them later on to check to see who won. Unless what your telling me will do that and Im juz not getting it, any suggestions?
• 10-14-2002
Eibro
Just set up an algorithm which will loop through your tictac array and check for wins. Three in a row is all you need. So if board[0] && board[1] && board[2] are all equal to the same player, they have won.
• 10-14-2002
Neoground1
I tried that exact method, but it only detects a win if squre 1,2,3 are taken in that order. Any suggesitons?