< Previous | Contents | Next >
As you can see, the main() function is almost exactly the pseudocode I created earlier.
// main function int main()
{
int move;
const int NUM_SQUARES = 9;
vector<char> board(NUM_SQUARES, EMPTY);
instructions();
char human = humanPiece();
char computer = opponent(human); char turn = X; displayBoard(board);
while (winner(board) == NO_ONE)
{
if (turn == human)
{
move = humanMove(board, human); board[move] = human;
208 Chapter 6 n References: Tic-Tac-Toe
}
else
{
}
move = computerMove(board, computer); board[move] = computer;
displayBoard(board); turn = opponent(turn);
}
announceWinner(winner(board), computer, human);
return 0;
}