You are on page 1of 3

CS&141 Lab #7

Programming Projects Page 499 5.


Use a two-dimensional array to write a game of Tic-Tac-Toe that represents the board.
Your program should prompt the user to choose who goes first and the user can play the game
multiple times. The implemented strategy will complete a 2-in-a-row if possible and will otherwise
block a user 2-in-a-row. The program recognizes a win by either player and a cat's game situation
when it is the computer's turn.

Log of execution (user input underlined)


Let's play tic tac toe
Do you want to go first? y
Your move? 2 <enter>
2
------------|
|
|
|
------------|
| X |
|
------------|
|
|
|
------------I move to 1, 3
------------|
|
| O |
------------|
| X |
|
------------|
|
|
|
-------------

Your move? 3
1
------------|
|
| O |
------------|
| X |
|
------------| X |
|
|
------------I move to 1, 2
------------|
| O | O |
------------|
| X |
|
------------| X |
|
|
------------Your move? 1
1
------------| X | O | O |
------------|
| X |
|
------------| X |
|
|
------------I move to 2, 1
------------| X | O | O |
------------| O | X |
|
------------| X |
|
|
-------------

Your move? 3
3
------------| X | O | O |
------------| O | X |
|
------------| X |
| X |
------------You win
------------| X | O | O |
------------| O | X |
|
------------| X |
| X |
------------Want to play again? y
...Steps Skipped...
I move to 2, 3
I win
------------| X |
| O |
------------|
| X | O |
------------| X |
| O |
------------Want to play again?

You might also like