Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Prog 2: Cuatro (USING C++) Under Construction Write a program to play the game of Cuatro, an invented close cousin of Tic-Tac-Toe and Quarto. This

Prog 2: Cuatro (USING C++)

Under Construction

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 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 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 2 enter piece, and Player 1 enter destination: D2 *** Sorry, that is an invalid piece. Please retry. 3. Player 2 enter piece, and Player 1 enter destination: z1 *** Sorry, that destination is occupied. Please retry. 3. Player 2 enter piece, and Player 1 enter destination: z 17 *** Sorry, that destination is invalid. Please retry. 3. Player 2 enter piece, and Player 1 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: ... 

Notes:

Here are 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)

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.

Stages

  1. (5 points) 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 that each 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 likewise be stored in another set of 16 char variables.
  2. (15 points) Prompt for user input of the piece to be played and the destination and make the move. Note that the player selects the piece, and then the opponent chooses where it should go. You should list move numbers that 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. (5 points) When prompting for a piece also allow entering 'x' or 'X' to exit the program.
  4. (10 points) Add error checking and appropriate error messages if a player chooses an invalid piece or an invalid destination as illustrated above. After detecting and displaying the appropriate error message your program must then redisplay the board and re-prompt for the move. Note that the move number only increases after each valid move. If there are multiple error conditions resulting from user input, only the first is shown. Check for errors in this order:
    1. Verify the selected piece is available to be used
    2. Verify the destination is not already occupied
    3. Verify the destination number is valid (between 1..16)
  5. (20 points) 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 give the message "*** You Won!" and exit.

image text in transcribed

image text in transcribed

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions