Lab 3: Tic-Tac-Toe

Announcements:

  • You must work with a new partner this week, someone with whom you have not been a partner in the past.

  • After taking the quiz select the one computer you will use between the two of you as you take turns being the driver (typing) and navigator (watching / suggesting).

  • IMPORTANT: After you have finished your quiz, if you have not already done so use this google form to enter your information and acknowledge that you have read the Academic Honesty policy on the course web site, and that you agree to abide by it.

Quiz:

The quiz will be available during the first 5 minutes of lab:

    • Your lab TA will tell you the password you will need to get into the quiz for your section.

    • You may use either one of the lab machines or your own laptop.

      • For the lab computers your account name and password are the same as your UIC NetID and password.

    • Please Click on Your Lab Time: 9am, 10am, 11am, 12pm, 1pm, 2pm, 3pm, 4pm, 5pm


Lab Exercise:

  • Starting point for this lab exercise can be found in section 4.31 of Zybooks.

  • You have been given some starter code and will need to add code in several functions to implement the game of Tic-Tac-Toe. Shown below are the functions you need to complete the code for and their points.

    1. Complete the function displayBoard(). It should use the board variables to display the board. (1 Point)

    2. Complete the function makeMove() which allows the user to make a move. It should prompt for user input, read in the user input number, and change to appropriate board variable. (1 Point)

    3. Complete the checkBoard() function that checks for a win after every turn. A win can be three of the same kind on any row, column, or diagonal. (1 Extra Credit Point)

  • Please do not edit the code in main(). The code in main() calls the various previously mentioned functions. You must complete the code in these functions to ensure that the game works properly.

  • Side Note: Since we have not yet discussed parameter passing in C++ when using functions, just for this program we will use global variables, even though using global variables in your programs is strongly discouraged and usually will lead to point deductions.


Game Introduction:

  • Game starts by player 'X' selecting a move position.

    • This position is chosen by entering a number 1-9 .

  • Players alternate on every move, until someone wins (with three in a row) or the board is filled and the game is a draw.

  • Running the program should look like the following, where user input is shown below bolded and underlined:



Welcome to the TicTacToe game!

Take turns entering the position (1..9)

into which your piece will be placed.

Enter '0' (zero) to exit.


-------

| | | | 1 2 3

-------

| | | | 4 5 6

-------

| | | | 7 8 9

-------

1. Enter the move (1..9) for X: 1

-------

|X| | | 1 2 3

-------

| | | | 4 5 6

-------

| | | | 7 8 9

-------

2. Enter the move (1..9) for O: 3

-------

|X| |O| 1 2 3

-------

| | | | 4 5 6

-------

| | | | 7 8 9

-------

3. Enter the move (1..9) for X: 4

-------

|X| |O| 1 2 3

-------

|X| | | 4 5 6

-------

| | | | 7 8 9

-------

4. Enter the move (1..9) for O: 7

-------

|X| |O| 1 2 3

-------

|X| | | 4 5 6

-------

|O| | | 7 8 9

-------

5. Enter the move (1..9) for X: 5

-------

|X| |O| 1 2 3

-------

|X|X| | 4 5 6

-------

|O| | | 7 8 9

-------

6. Enter the move (1..9) for O: 6

-------

|X| |O| 1 2 3

-------

|X|X|O| 4 5 6

-------

|O| | | 7 8 9

-------

7. Enter the move (1..9) for X: 9

-------

|X| |O| 1 2 3

-------

|X|X|O| 4 5 6

-------

|O| |X| 7 8 9

-------


Congratulations player X. You WON!

Exiting program...