Write a program to play the game of Cuatro, an invented close cousin of Tic-Tac-Toe and Quarto. This is a two-player game unlike Tic-Tac-Toe in that you don't have "your" pieces and "their" pieces, but rather the winner is the one who on their move is first to complete a configuration of 4 pieces of the same type, drawing upon all the pieces remaining to play. Once placed on the board pieces cannot be moved. Running the game with this user input:

C 6 O1 D2 z 17 z 1 z 8 O 16 O 5 c 11

looks like the following:

Welcome to the game of Cuatro, where you try to complete a set
of four pieces that are alike. Players take turns making moves.
On each move your OPPONENT chooses the piece, then YOU get to
place it on the board. If you create a set of four alike when
you place your piece, then you win!

A set of four alike can be completed by using four all upper (or all
lower) case characters, four all vowels (or all consonants), or four
all curved (or all straight-lined). Curved letters are 'O' and 'C'
(upper or lower), and straight-line letters are 'I' and 'Z' (upper or
lower). Groups of four can be created in a row, column, diagonal, or
corner quadrant.

When prompted for input you may also enter 'x' or 'X' to exit.

--------- Square #
| . . . . | 1 2 3 4
| . . . . | 5 6 7 8
| . . . . | 9 10 11 12
| . . . . | 13 14 15 16
---------
Pieces: Curved Straight
Upper: OO/CC II/ZZ
Lower: oo/cc ii/zz
Vowel/Consonant
1. Player 1 enter piece, and Player 2 enter destination: C 6

--------- Square #
| . . . . | 1 2 3 4
| . C . . | 5 6 7 8
| . . . . | 9 10 11 12
| . . . . | 13 14 15 16
---------
Pieces: Curved Straight
Upper: OO/ C II/ZZ
Lower: oo/cc ii/zz
Vowel/Consonant
2. Player 2 enter piece, and Player 1 enter destination: O1

--------- Square #
| O . . . | 1 2 3 4
| . C . . | 5 6 7 8
| . . . . | 9 10 11 12
| . . . . | 13 14 15 16
---------
Pieces: Curved Straight
Upper: O/ C II/ZZ
Lower: oo/cc ii/zz
Vowel/Consonant
3. Player 1 enter piece, and Player 2 enter destination: D2
*** Sorry, that is an invalid piece. Please retry.

--------- Square #
| O . . . | 1 2 3 4
| . C . . | 5 6 7 8
| . . . . | 9 10 11 12
| . . . . | 13 14 15 16
---------
Pieces: Curved Straight
Upper: O/ C II/ZZ
Lower: oo/cc ii/zz
Vowel/Consonant
3. Player 1 enter piece, and Player 2 enter destination: z 17
*** Sorry, that destination is invalid. Please retry.

--------- Square #
| O . . . | 1 2 3 4
| . C . . | 5 6 7 8
| . . . . | 9 10 11 12
| . . . . | 13 14 15 16
---------
Pieces: Curved Straight
Upper: O/ C II/ZZ
Lower: oo/cc ii/zz
Vowel/Consonant
3. Player 1 enter piece, and Player 2 enter destination: z 1
*** Sorry, that destination is occupied. Please retry.

--------- Square #
| O . . . | 1 2 3 4
| . C . . | 5 6 7 8
| . . . . | 9 10 11 12
| . . . . | 13 14 15 16
---------
Pieces: Curved Straight
Upper: O/ C II/ZZ
Lower: oo/cc ii/zz
Vowel/Consonant
3. Player 1 enter piece, and Player 2 enter destination: z 8

--------- Square #
| O . . . | 1 2 3 4
| . C . z | 5 6 7 8
| . . . . | 9 10 11 12
| . . . . | 13 14 15 16
---------
Pieces: Curved Straight
Upper: O/ C II/ZZ
Lower: oo/cc ii/ z
Vowel/Consonant
4. Player 2 enter piece, and Player 1 enter destination: O 16

--------- Square #
| O . . . | 1 2 3 4
| . C . z | 5 6 7 8
| . . . . | 9 10 11 12
| . . . O | 13 14 15 16
---------
Pieces: Curved Straight
Upper: / C II/ZZ
Lower: oo/cc ii/ z
Vowel/Consonant
5. Player 1 enter piece, and Player 2 enter destination: O 5
*** Sorry, that is an invalid piece. Please retry.

--------- Square #
| O . . . | 1 2 3 4
| . C . z | 5 6 7 8
| . . . . | 9 10 11 12
| . . . O | 13 14 15 16
---------
Pieces: Curved Straight
Upper: / C II/ZZ
Lower: oo/cc ii/ z
Vowel/Consonant
5. Player 1 enter piece, and Player 2 enter destination: c 11

--------- Square #
| O . . . | 1 2 3 4
| . C . z | 5 6 7 8
| . . c . | 9 10 11 12
| . . . O | 13 14 15 16
---------
Pieces: Curved Straight
Upper: / C II/ZZ
Lower: oo/ c ii/ z
Vowel/Consonant
*** Player 2 you won!

Notes:

1. Here are a few examples of winning sets of four, which could be found in any row, column, diagonal, or corner quadrant of four adjacent squares:

1. OICZ (all upper case)
2. ZiiI (all straight-line)
3. ZzCc (all consonants)

2. After selecting a piece and placing it on the board, the program should no longer display that piece as an option to be selected to be played. On each move the program should do error-checking to ensure that only available pieces can be selected to be played, and that the destination square is not already occupied. After each move the program should also check to see if there was a win for the player that just placed a piece.

3. Do's and Don'ts:

  • You should break up your program into pieces using functions.
  • The board must be displayed and manipulated by using 16 separate variables representing the 16 locations on the board. Failure to do so will result in a 20 point deduction. You may (but don't have to) make these 16 board location variables global variables, even though normally (and later this semester) this will not be allowed.
  • The board must be displayed and manipulated by using 16 separate variables representing the 16 locations on the board. Failure to do so will result in a 20 point deduction. You may (but don't have to) make these 16 board location variables global variables, even though normally (and later this semester) this will not be allowed.
  • You may not use arrays or vectors or C++ string variables anywhere in your program besides what has been specifically described above.

Stages

The starting template code is in Zybooks at section 5.40 Prog2: Cuatro

1. Display the blank board, square numbers and pieces to play, which should look the sample program run shown above.

Board: Your board should be declared as 16 char variables where each one has '.' in it to start. Displaying the board simply displays whatever values are stored in each of the board square variables. Later as play progresses the '.' characters will be replaced by other letters, one at a time, and displaying the board array will then end up displaying those characters instead.

Pieces: Your pieces available to be played should be stored in one or more C++ strings

2. Prompt for user input of the piece to be played (a char) and the destination (an int) and make the move. Note that the current player selects the piece, and then the opponent chooses where it should go. The displayed move numbers must increment as valid moves are made. Your program should handle user input with or without a space between the piece and destination, as shown in the example above.

3. When prompting for a piece also allow entering 'x' or 'X' to exit the program. To do this you should check if the piece to be played is 'X' or 'x' after the piece to be played is entered, but before the destination is entered. In other words, you need to handle user input in two separate cin statements. When user input is 'X' or 'x', your program must display the message: "Exiting program..." and then exit immediately.

4. When prompting for a piece also allow entering 'x' or 'X' to exit the program. To do this you should check if the piece to be played is 'X' or 'x' after the piece to be played is entered, but before the destination is entered. In other words, you need to handle user input in two separate cin statements. When user input is 'X' or 'x', your program must display the message: "Exiting program..." and then exit immediately.

  • Verify the selected piece is available to be used.
  • Verify the destination number is valid (between 1..16).
  • Verify the destination is not already occupied.

5. Check for a win in any of the valid configurations, checking all rows, columns, diagonals, and corner quadrants. Once there is a win your program should display the final board, and indicate which player won with a message, and then exit the program. For example if player 1 just placed a piece on the board which results in a win, then your program would give the message "*** Player 1 you won!". If play reaches the end of the game with no winner the program should display the final completely-filled board and terminate with no message.

Test Input

You should be able to copy/paste the user input shown below in response to the initial prompt and the program should play all the way as if you had entered the input one move at a time. You don't need to do any extra programming for this, as user input is automatically buffered, with subsequent input statements automatically reading what is next from the input buffer.

  • Display board and exit. Input: x
  • Make multiple moves with and without spaces between user inputs. Input: C6 O 1 z12 i 15 X
  • Error checking: Verify selected piece, destination number, and destination available. Input: B1 I0 Z9 Z10 Z13 O9 X
  • Check for winning condition of a row, with vowels. Input: O9 I10 o11 i12
  • Check for winning condition of a column, with consonants. Input: C2 Z6 c10 O9 z14
  • Check for winning condition of a diagonal, with curved. Input: O13 C10 o7 c4
  • Check for winning condition of a corner quadrant, with straight. Input: I11 I6Z12 i15 z16
  • Check for winning condition of a quadrant, with upper case. Input: O9 O10 Z13 Z14
  • Check for winning condition of a diagonal, with lower case. Input: o1 c6 i11 z16
  • Check for end of game detection when no one wins. Input: O1 z2 I3 C4 z5 i6 C7 o8 Z9 o10 c11 i12 Z13 I14 O15 c16
  • There are 5 additional tests with hidden input, worth 3 points each.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.