Académique Documents
Professionnel Documents
Culture Documents
#include <string>
#define GRID_SIZE 9
char gameGrid[GRID_SIZE];
initialiseGame(gameGrid);
int currentTurn = 0;
cout << "Tic Tac Toe by Bryan Lean" << endl << endl;
printGame(gameGrid);
while (!isFull(gameGrid)) {
int slotChoice;
currentTurn += 1;
// Prompt
if (isP2) {
cout << "Player 2 turn..." << endl << "Insert to slot > ";
} else {
cout << "Player 1 turn..." << endl << "Insert to slot > ";
while (!isEmpty(gameGrid[slotChoice])) {
cout << "Slot occupied. Please select another slot > ";
// Insert
if (isP2) {
gameGrid[slotChoice] = 'o';
} else {
gameGrid[slotChoice] = 'x';
printGame(gameGrid);
// Check Winner
if (checkWon(gameGrid)) {
if (isP2) {
} else {
break;
if (!checkWon(gameGrid)) {
if ((i+1) % 3 == 0 && i != 0) {
cout << "|" << endl;
gameGrid[slot] = choice;
return false;
return true;
return true;
return false;
return true;
} else if (columnWon(gameGrid)) {
return true;
} else if (diagonalWon(gameGrid)) {
return true;
return false;
return true;
return false;
return true;
return false;
return true;
return true;
return false;
}