//Steffen, Jordan - stej4019 //cs201-807 //prog14.cc //An exciting two player //tic-tac-toe game that will //provide hours of fun! #include using namespace std; void printMyBoard(string board); //prints the board whilst displaying current moves bool move(string &board, char turn, int square); //tests for valid move and updates board bool win(string board, char turn); //tests for win int main() { cout<<"Welcome to Tic-Tac-Toe!"<>square; if(move(board, turn, square)) //runs test (see function move) { if(win(board, turn)) //runs test (see function win) { cout<<"---------------------------------------"<=1 && square <=9) //tests between 1 and 9 { if(board[square] == 'X' || 'O') //tests if space already occupied { return false; } else { board[square] = turn; //updates board return true; } } else { return false; } } /* Tests all possible three way combinations of a win in a 3 x 3 tic-tac-toe game. If one is found the function exits, returning true, without running the rest of the tests. If there is no win found, false is returned. */ bool win(string board, char turn) { if(board[1] == turn && board[2] == turn && board[3] == turn) { return true; } if(board[1] == turn && board[4] == turn && board[7] == turn) { return true; } if(board[1] == turn && board[5] == turn && board[9] == turn) { return true; } if(board[2] == turn && board[5] == turn && board[8] == turn) { return true; } if(board[3] == turn && board[6] == turn && board[9] == turn) { return true; } if(board[3] == turn && board[5] == turn && board[7] == turn) { return true; } if(board[4] == turn && board[5] == turn && board[6] == turn) { return true; } if(board[7] == turn && board[8] == turn && board[9] == turn) { return true; } return false; }