From d35f46765a7611cc1559080a151a5cd3ed08dd88 Mon Sep 17 00:00:00 2001 From: shivaligakhar-123 <42827109+shivaligakhar-123@users.noreply.github.com> Date: Wed, 7 Oct 2020 23:57:18 +0530 Subject: [PATCH] Create tictactoe.cpp --- Games/tic tac toe/tictactoe.cpp | 196 ++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 Games/tic tac toe/tictactoe.cpp diff --git a/Games/tic tac toe/tictactoe.cpp b/Games/tic tac toe/tictactoe.cpp new file mode 100644 index 0000000..1f48e36 --- /dev/null +++ b/Games/tic tac toe/tictactoe.cpp @@ -0,0 +1,196 @@ +#include +using namespace std; + +#define COMPUTER 1 +#define HUMAN 2 + +#define SIDE 3 // Length of the board + +#define COMPUTERMOVE 'O' +#define HUMANMOVE 'X' + + +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; +} + + +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; +} + + +void initialise(char board[][SIDE], int moves[]) +{ + + srand(time(NULL)); + + for (int i=0; i