A game of Tic-Tac-Toe.
Noughts and crosses, also known as Tic-Tac-Toe is a game for two players. It is played on a 3x3 grid of squares. Player one plays with counters marked "X". Player two plays with counters marked "O". The aim of the game is to win by having placed three of your own counters adjacent to each other either horizontally, vertically or diagonally. On a players turn they place just one of their counters onto an empty square.
Write the program to play the game.
Use this boilerplate code as a starting point:
Remember to add a comment before a subprogram or selection statement to explain its purpose.
-1 indicates an empty square, 0 indicates an "O" and 10 indicates an "X".
Numbers will make it easier to calculate if there is a winner.
0 1 2
0 | |
---------
1 | |
---------
2 | |
Enter xy position: 11
0 1 2
0 | |
---------
1 |X|
---------
2 | |
Enter xy position: 21
0 1 2
0 | |
---------
1 |X|O
---------
2 | |
Enter xy position: 20
0 1 2
0 | |X
---------
1 |X|O
---------
2 | |
Enter xy position: 02
0 1 2
0 | |X
---------
1 |X|O
---------
2 O| |
Enter xy position: 00
0 1 2
0 X| |X
---------
1 |X|O
---------
2 O| |
Enter xy position: 10
0 1 2
0 X|O|X
---------
1 |X|O
---------
2 O| |
Enter xy position: 22
0 1 2
0 X|O|X
---------
1 |X|O
---------
2 O| |X
X wins.
Use these resources as a reference to help you meet the success criteria.
Create the unit tests below to check that your program has met the success criteria.
Check that you have: