// A C++ Program to play tic-tac-toe #include using namespace std; #define COMPUTER 1 #define HUMAN 2 #define SIDE 3 // Length of the board // Computer will move with 'O' // and human with 'X' #define COMPUTERMOVE 'O' #define HUMANMOVE 'X' // A function to show the current board status void showBoard(char board[][SIDE]) { printf("\n\n"); printf("\t\t\t %c | %c | %c \n", board[0][0], board[0][1], board[0][2]); printf("\t\t\t--------------\n"); printf("\t\t\t %c | %c | %c \n", board[1][0], board[1][1], board[1][2]); printf("\t\t\t--------------\n"); printf("\t\t\t %c | %c | %c \n\n", board[2][0], board[2][1], board[2][2]); return; } // A function to show the instructions void showInstructions() { printf("\t\t\t Tic-Tac-Toe\n\n"); printf("Choose a cell numbered from 1 to 9 as below" " and play\n\n"); printf("\t\t\t 1 | 2 | 3 \n"); printf("\t\t\t--------------\n"); printf("\t\t\t 4 | 5 | 6 \n"); printf("\t\t\t--------------\n"); printf("\t\t\t 7 | 8 | 9 \n\n"); printf("-\t-\t-\t-\t-\t-\t-\t-\t-\t-\n\n"); return; } // A function to initialise the game void initialise(char board[][SIDE], int moves[]) { // Initiate the random number generator so that // the same configuration doesn't arises srand(time(NULL)); // Initially the board is empty for (int i=0; i