CS60 Project Assignment 1 ------------------------- Due: Oct 10th at Midnight Two Player TicTacToe -------------------- The goal of this project is to design and implement a two player tic tac toe game in C. The project should exercise working knowledge of variables, variable arrays, control and loop structures, and functions. TicTacToe --------- TicTacToe is a simple two player game traditionally played on a 3x3 game board with one player 'X' and one player 'O'. The game board is laid out as follows: | _ | _ | _ | | _ | _ | _ | | _ | _ | _ | For simplicity, we can index the board with (x,y) coordinates in the following way: | X | _ | _ | | _ | _ | _ | | _ | O | _ | Where the coordinates of 'X' are (0,0) and the coordinates of 'O' are (2,1). Players take turns, one move per turn, at placing their symbol on an empty place on the board (anywhere where there is a '_' character in the drawings above). For instance, player 'X', who goes first, could place their symbol in any space on the first round: | X | _ | _ | | _ | _ | _ | | _ | _ | _ | or | _ | _ | _ | | _ | X | _ | | _ | _ | _ | etc. On the next turn, player 'O' places their symbol on any remaining empty spaces: | X | _ | _ | | _ | _ | O | | _ | _ | _ | The game continues until either player 'X' or player 'O' wins, or there is a draw. A player wins if they have successfully filled an entire row, column, or diagonal with their symbol: | X | X | X | | O | _ | _ | | O | _ | _ | winner: player 'X' | O | X | X | | X | O | _ | | _ | _ | O | winner: player 'O' | X | O | O | | X | _ | _ | | X | _ | _ | winner: player 'X' | X | O | X | | X | O | X | | O | X | O | winner: no one! draw. Program Requirements -------------------- The final program must fulfill the following requirements: - must operate in two modes: player versus player and player versus computer. - in player versus player mode, players take turns making a move - in player versus computer mode, computer must play tictactoe as player 'O' - computer AI can be as simple as making random valid moves - must correctly detect when either player has won the game and exit the program - must correctly detect a draw and exit the program - must implement error checking when a new move is inputted, invalid moves are reported and the player should be asked to re-enter their move. Invalid moves are: - new move is beyond the coordinates of the board - new move places the symbol over an existing symbol (cannot make the same move twice and cannot play in a space where the other player has already played) - must use functions for at least the following operations: - drawing the current game board - checking the board for a winner - checking validity of new moves - when the program detects a win or draw, the program must report the winner or the fact that the game is a draw and exit Turnin ------------ The turnin tag for this assignment is 'project1' and must include the following files: - the code itself - a typescript showing compilation and execution of the game under the following scenarios: - player versus player, player X winning by completing a row - player versus player, player O winning by completing a column - player versus player, no winner showing a draw - player versus computer, whomever wins! - in at least one scenario, player attempting to make an invalid move by specifying coordinates beyond the edge of the board - in at least one scenario, player attempting to make an invalid move by playing in a space already taken up by a previous move - an optional README file containing any special instructions for the grader Extra Credit ------------- For 10 pts of extra credit, the program should be able to be configured to use an arbitrary sized, symmetric game board. The size of the board should be specified using #define directives and should be symmetric, so 10x10 is a valid size, but 10x11 is not. Otherwise, the rules of the game and requirements are the same. The typescript for extra credit should show the game being played on a 3x3 board, a 5x5 board, and another sized board, with all of the turnin scenarios being played out on at least the 5x5 board, and at least one of the turnin scenarios being played on the 3x3 and other sized boards. HINT: if you plan on doing the extra credit, start from scratch with arbitrary sized game boards in mind! Depending on coding decisions, it may be difficult to extend a 3x3 tictactoe program to arbitrary sized boards. Sample Output --------------- You program does not have to look exactly like the following output, but it must at least draw the board to the screen before and after every move. [nurmi@localhost sol]$ gcc tictac.c -o tictac [nurmi@localhost sol]$ ./tictac 0 - player versus player 1 - player versus computer Please enter game mode (0 or 1): 0 | _ | _ | _ | | _ | _ | _ | | _ | _ | _ | player X: enter a move in x,y coordinates (x,y): 1,1 Player X plays at (1,1) | _ | _ | _ | | _ | X | _ | | _ | _ | _ | player O: enter a move in x,y coordinates (x,y): 0,0 Player O plays at (0,0) | O | _ | _ | | _ | X | _ | | _ | _ | _ | player X: enter a move in x,y coordinates (x,y): 0,1 Player X plays at (0,1) | O | X | _ | | _ | X | _ | | _ | _ | _ | player O: enter a move in x,y coordinates (x,y): 2,2 Player O plays at (2,2) | O | X | _ | | _ | X | _ | | _ | _ | O | player X: enter a move in x,y coordinates (x,y): 2,1 Player X plays at (2,1) | O | X | _ | | _ | X | _ | | _ | X | O | X wins! [nurmi@localhost sol]$ ./tictac 0 - player versus player 1 - player versus computer Please enter game mode (0 or 1): 0 | _ | _ | _ | | _ | _ | _ | | _ | _ | _ | player X: enter a move in x,y coordinates (x,y): 0,0 Player X plays at (0,0) | X | _ | _ | | _ | _ | _ | | _ | _ | _ | player O: enter a move in x,y coordinates (x,y): 1,1 Player O plays at (1,1) | X | _ | _ | | _ | O | _ | | _ | _ | _ | player X: enter a move in x,y coordinates (x,y): 0,1 Player X plays at (0,1) | X | X | _ | | _ | O | _ | | _ | _ | _ | player O: enter a move in x,y coordinates (x,y): 0,2 Player O plays at (0,2) | X | X | O | | _ | O | _ | | _ | _ | _ | player X: enter a move in x,y coordinates (x,y): 2,2 Player X plays at (2,2) | X | X | O | | _ | O | _ | | _ | _ | X | player O: enter a move in x,y coordinates (x,y): 0,2 player O: Illegal move, try again! | X | X | O | | _ | O | _ | | _ | _ | X | player O: enter a move in x,y coordinates (x,y): 2,0 Player O plays at (2,0) | X | X | O | | _ | O | _ | | O | _ | X | O wins! [nurmi@localhost sol]$ ./tictac 0 - player versus player 1 - player versus computer Please enter game mode (0 or 1): 0 | _ | _ | _ | | _ | _ | _ | | _ | _ | _ | player X: enter a move in x,y coordinates (x,y): 0,0 Player X plays at (0,0) | X | _ | _ | | _ | _ | _ | | _ | _ | _ | player O: enter a move in x,y coordinates (x,y): 1,0 Player O plays at (1,0) | X | _ | _ | | O | _ | _ | | _ | _ | _ | player X: enter a move in x,y coordinates (x,y): 1,1 Player X plays at (1,1) | X | _ | _ | | O | X | _ | | _ | _ | _ | player O: enter a move in x,y coordinates (x,y): 2,2 Player O plays at (2,2) | X | _ | _ | | O | X | _ | | _ | _ | O | player X: enter a move in x,y coordinates (x,y): 0,2 Player X plays at (0,2) | X | _ | X | | O | X | _ | | _ | _ | O | player O: enter a move in x,y coordinates (x,y): 2,0 Player O plays at (2,0) | X | _ | X | | O | X | _ | | O | _ | O | player X: enter a move in x,y coordinates (x,y): 2,1 Player X plays at (2,1) | X | _ | X | | O | X | _ | | O | X | O | player O: enter a move in x,y coordinates (x,y): 0,1 Player O plays at (0,1) | X | O | X | | O | X | _ | | O | X | O | player X: enter a move in x,y coordinates (x,y): 1,2 Player X plays at (1,2) | X | O | X | | O | X | X | | O | X | O | Draw! [nurmi@localhost sol]$ ./tictac 0 - player versus player 1 - player versus computer Please enter game mode (0 or 1): 1 | _ | _ | _ | | _ | _ | _ | | _ | _ | _ | player X: enter a move in x,y coordinates (x,y): 0,0 Player X plays at (0,0) | X | _ | _ | | _ | _ | _ | | _ | _ | _ | Player O plays at (2,2) | X | _ | _ | | _ | _ | _ | | _ | _ | O | player X: enter a move in x,y coordinates (x,y): 1,1 Player X plays at (1,1) | X | _ | _ | | _ | X | _ | | _ | _ | O | Player O plays at (1,0) | X | _ | _ | | O | X | _ | | _ | _ | O | player X: enter a move in x,y coordinates (x,y): 2,0 Player X plays at (2,0) | X | _ | _ | | O | X | _ | | X | _ | O | Player O plays at (0,2) | X | _ | O | | O | X | _ | | X | _ | O | player X: enter a move in x,y coordinates (x,y): 1,2 Player X plays at (1,2) | X | _ | O | | O | X | X | | X | _ | O | Player O plays at (2,1) | X | _ | O | | O | X | X | | X | O | O | player X: enter a move in x,y coordinates (x,y): 0,1 Player X plays at (0,1) | X | X | O | | O | X | X | | X | O | O | Draw! [nurmi@localhost sol]$ exit