4/2 Changed the phrase "5 in a row" to be "5 in a line" throughout.
5/5 Descriptions below were updated (and shown in blue) to match the expected output of a couple of test cases, as follows:
In test case 1, after user input of 'x' or 'X', a message gets displayed.
When program is finished due to the board being full (test 3) or when a user wins (test 6), respective messages are shown, the main loop is exited, the final board is shown, and a final message is given.
Create the interface to allow two human players to play Pentago (available as Zylab 9.23). This is played on a 6 x 6 board, and the objective is to get 5 of your pieces ('X' or 'O') in a line. Instructions and sample play are shown below.
Welcome to Pentago, where you try to get 5 of your pieces in a line. At any point enter 'x' to exit or 'i' for instructions. 1 2 3 4 5 6 1-----------------------2 A | . . . | . . . | A | | | B | . . . | . . . | B | | | C | . . . | . . . | C |-----------+-----------| D | . . . | . . . | D | | | E | . . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 1. Enter row, column, quadrant, direction for X: i Play the two-player game of Pentago. Be the first to get 5 in a line. Pentago is played on a 6 by 6 board, divided into four 3 by 3 quadrants. There are two players, X and O, who alternate turns. The goal of each player is to get five of their pieces in a line, either horizontally, vertically, or diagonally. Players take turns placing one of their pieces into an empty space anywhere on the board, then choosing one of the four board quadrants to rotate 90 degrees left or right. If both players get five in a line at the same time, or the last move is played with no five in a line, the game is a tie. If a player makes five a line by placing a piece, there is no need to rotate a quadrant and the player wins immediately. Play online at: https://perfect-pentago.net Purchase at: www.mindtwisterusa.com For each move provide four inputs: row (A-F), column (1-6), quadrant (1-4), rotation direction (L or R) For instance input of B32R places the next piece at B3 and then would rotate quadrant 2 (upper-right) to the right (clockwise). At any point enter 'x' to exit the program or 'i' to display instructions. 1 2 3 4 5 6 1-----------------------2 A | . . . | . . . | A | | | B | . . . | . . . | B | | | C | . . . | . . . | C |-----------+-----------| D | . . . | . . . | D | | | E | . . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 1. Enter row, column, quadrant, direction for X: c31r 1 2 3 4 5 6 1-----------------------2 A | . . . | . . . | A | | | B | . . . | . . . | B | | | C | X . . | . . . | C |-----------+-----------| D | . . . | . . . | D | | | E | . . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 2. Enter row, column, quadrant, direction for O: A5 3R 1 2 3 4 5 6 1-----------------------2 A | . . . | . O . | A | | | B | . . . | . . . | B | | | C | X . . | . . . | C |-----------+-----------| D | . . . | . . . | D | | | E | . . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 3. Enter row, column, quadrant, direction for X: G05h *** Invalid move row. Please retry. 1 2 3 4 5 6 1-----------------------2 A | . . . | . O . | A | | | B | . . . | . . . | B | | | C | X . . | . . . | C |-----------+-----------| D | . . . | . . . | D | | | E | . . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 3. Enter row, column, quadrant, direction for X: c25h *** Selected quadrant is invalid. Please retry. 1 2 3 4 5 6 1-----------------------2 A | . . . | . O . | A | | | B | . . . | . . . | B | | | C | X . . | . . . | C |-----------+-----------| D | . . . | . . . | D | | | E | . . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 3. Enter row, column, quadrant, direction for X: c21h *** Quadrant rotation direction is invalid. Please retry. 1 2 3 4 5 6 1-----------------------2 A | . . . | . O . | A | | | B | . . . | . . . | B | | | C | X . . | . . . | C |-----------+-----------| D | . . . | . . . | D | | | E | . . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 3. Enter row, column, quadrant, direction for X: c1 1r
*** That board location is already taken. Please retry.
1 2 3 4 5 6 1-----------------------2 A | . . . | . O . | A | | | B | . . . | . . . | B | | | C | X . . | . . . | C |-----------+-----------| D | . . . | . . . | D | | | E | . . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 3. Enter row, column, quadrant, direction for X: c2 1r
1 2 3 4 5 6 1-----------------------2 A | X . . | . O . | A | | | B | X . . | . . . | B | | | C | . . . | . . . | C |-----------+-----------| D | . . . | . . . | D | | | E | . . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 4. Enter row, column, quadrant, direction for O: b 6 4 l 1 2 3 4 5 6 1-----------------------2 A | X . . | . O . | A | | | B | X . . | . . O | B | | | C | . . . | . . . | C |-----------+-----------| D | . . . | . . . | D | | | E | . . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 5. Enter row, column, quadrant, direction for X: c53l 1 2 3 4 5 6 1-----------------------2 A | X . . | . O . | A | | | B | X . . | . . O | B | | | C | . . . | . X . | C |-----------+-----------| D | . . . | . . . | D | | | E | . . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 6. Enter row, column, quadrant, direction for O: d6 3r 1 2 3 4 5 6 1-----------------------2 A | X . . | . O . | A | | | B | X . . | . . O | B | | | C | . . . | . X . | C |-----------+-----------| D | . . . | . . O | D | | | E | . . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 7. Enter row, column, quadrant, direction for X: c41r 1 2 3 4 5 6 1-----------------------2 A | . X X | . O . | A | | | B | . . . | . . O | B | | | C | . . . | X X . | C |-----------+-----------| D | . . . | . . O | D | | | E | . . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 8. Enter row, column, quadrant, direction for O: e14l 1 2 3 4 5 6 1-----------------------2 A | . X X | . O . | A | | | B | . . . | . . O | B | | | C | . . . | X X . | C |-----------+-----------| D | . . . | O . . | D | | | E | O . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 9. Enter row, column, quadrant, direction for X: c6 2r 1 2 3 4 5 6 1-----------------------2 A | . X X | X . . | A | | | B | . . . | X . O | B | | | C | . . . | X O . | C |-----------+-----------| D | . . . | O . . | D | | | E | O . . | . . . | E | | | F | . . . | . . . | F 3-----------------------4 1 2 3 4 5 6 10. Enter row, column, quadrant, direction for O: f2 3l *** O has won the game! 1 2 3 4 5 6 1-----------------------2 A | . X X | X . . | A | | | B | . . . | X . O | B | | | C | . . . | X O . | C |-----------+-----------| D | . . . | O . . | D | | | E | . . O | . . . | E | | | F | . O . | . . . | F 3-----------------------4 1 2 3 4 5 6 Thanks for playing. Exiting...
The following input was used for the above-given run of the program, testing input validation and resulting in a win for 'O':
i c31r A5 3R G05h c05h c25h c21h c2 1r b 6 4 l c53l d6 3r c41r e14l c6 2r f2 3l
Your program must represent the board using a class, that should itself have a default constructor and also member functions to allow making moves, rotating a quadrant, and checking for a win. In the default constructor initialize board array values to all be the '.' character. Failure to implement this program using a class as described will result in a 20 point deduction.
The 55 points for program execution are assigned as follows:
(5 points) Display the board. Print out the instructions exactly as shown in the sample run above. Handle user input in either upper or lower case. Display the move number, that should update each time a valid move is made. After user input of 'x' or 'X', the program should display the message "Exiting program..." and then exit.
Test input: i X
(5 points) Read in user input to allow making alternating moves by placing an 'X' anywhere on the board into an empty space on the odd-numbered turns, then placing an 'O' anywhere on the board into an empty space on the even-numbered turns. You should not need to do anything special to handle user input, but rather should be able to simply use cin into char variables.
Test input: a24r B34R c 4 4 r x
(5 points) If/when the board fills up, game should display the message " *** No one has won. Game is a tie." and should exit the main loop, and just before the program ends should redisplay the board and then display the message " Thanks for playing. Exiting... "
Test input (all on one line):
a14r a24l a34r a44r a54l a64r b24l b14r b44l b34r b64r b54l c14l c24r c34l c44r c54l c64r d14l d24r d34l e14r e24l e34r f14r f24l f34r d44l e44r d64l d54r e54l f54r f44l e64r f64l
(10 points) After each move, implement making a rotation of the chosen quadrant in the chosen direction. Quadrant 1 is the upper-left, quadrant 2 is the upper-right, quadrant 3 is the lower-left, and quadrant 4 is the lower-right. Rotations are relative to the middle of the quadrant, where input of 'r' or 'R' rotates the selected quadrant right (clockwise), and input of 'l' or 'L' rotates the selected quadrant left (counter-clockwise).
Test input: a11r b4 2l e33r f64l x
(10 points) Implement error handling for the conditions described below, in the order given below. Handling the same errors in a different order could lead to your output not matching when multiple input errors are present at the same time. Input should work regardless of spacing, so that input all concatenated together must work, as well as input all separated by spaces.
Row out of range should give the error message: " *** Invalid move row. Please retry."
Column out of range should give the error message: " *** Invalid move column. Please retry."
Selected board row, column destination square is not blank should give the error message:
" *** That board location is already taken. Please retry."
Quadrant out of range should give the error message: " *** Selected quadrant is invalid. Please retry. "
Rotation direction out of range should give the error message: " *** Quadrant rotation direction is invalid. Please retry. "
Test input: c31r A5 3R G05h c05h c25h c21h c11r c2 1r x
(5 points) Detect when a sequence of 5 in a line is created on the board, either when placing a piece or after rotating a quadrant. If a winning configuration is created when placing a piece, then the rotation part of the move should not be done. A sequence of 5 in a line should be detected in any row, column or diagonal where it is found and if player 'O' wins should display the message:
" *** O has won the game!"
or if player 'X' wins:
" *** X has won the game!"
After a player wins the program should exit the main loop, and just before the program ends should redisplay the board and then display the message " Thanks for playing. Exiting... "
Test input: c31r A53R c21r b 6 4 l c 53l d63 r c41r e14l c62r f23l
(5 points) If both players get a winning configuration at the same time, the program must indicate it is a tie by displaying the message:
" *** Both X and O have won. Game is a tie."
Test input: b23r a53l b13l b63l b33l d63l e24l e12r e31r f23l
(10 points) Hidden input test