You will be working on the Tic-Tac-Toe game just like last week. You have been given part of the code and you must complete the remaining portions to implement the game of Tic-Tac-Toe.
The code that is entirely in main
Please do not change the code given to you.
We have split the program into functions, the program does not use global variables anymore.
(Using Global variables in your program is usually not encouraged).
The game starts by the first move made by player 'X', the user enters a position for the move. The player alternates at every move, until someone wins or the game is a draw.
Running the Program with the input 1 3 4 7 5 6 9 should look like:
Welcome to the TicTacToe game!
Take turns entering the move destination (1..9)
or '0' (zero) to exit.
-------
| | | | 1 2 3
-------
| | | | 4 5 6
-------
| | | | 7 8 9
-------
1. Enter the move (1..9) for X:
-------
|X| | | 1 2 3
-------
| | | | 4 5 6
-------
| | | | 7 8 9
-------
2. Enter the move (1..9) for O:
-------
|X| |O| 1 2 3
-------
| | | | 4 5 6
-------
| | | | 7 8 9
-------
3. Enter the move (1..9) for X:
-------
|X| |O| 1 2 3
-------
|X| | | 4 5 6
-------
| | | | 7 8 9
-------
4. Enter the move (1..9) for O:
-------
|X| |O| 1 2 3
-------
|X| | | 4 5 6
-------
|O| | | 7 8 9
-------
5. Enter the move (1..9) for X:
-------
|X| |O| 1 2 3
-------
|X|X| | 4 5 6
-------
|O| | | 7 8 9
-------
6. Enter the move (1..9) for O:
-------
|X| |O| 1 2 3
-------
|X|X|O| 4 5 6
-------
|O| | | 7 8 9
-------
7. Enter the move (1..9) for X:
-------
|X| |O| 1 2 3
-------
|X|X|O| 4 5 6
-------
|O| |X| 7 8 9
-------
Congratulations player X. You WON!
Exiting program...
Do not change the code we have already given you, but do complete the changes needed to the parameters used when calling a function and in the function declarations themselves. Make the appropriate changes to make the game work.
Step 1: (1 Point)
a) declare the required variables in main.
b) call the function displayBoard( ) in main. Also, add appropriate return value and parameters in place of "???" in
??? displayBoard??? which must take the board variables and display the board. Note this must be updated in two locations in main.
Step 2: (1 Point)
a) Call the function makeMove() in main and also add appropriate return value and parameters in place of ??? in
??? makeMove( ??? ).
b) Call the function thereIsAWin() in main and also add appropriate return value and parameters in place of ? in
??? thereIsAWin( ??? ).
Step 3: (1 extra credit point)
Implement the parameters and return type for the moveIsValid() function that checks if the entered position is valid or not after the user enters the move. You will also need to write the code in that function to do the checks. A valid move is one that is moving into an empty square and uses a position number in the range 1..9.