Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ #include #include using namespace std; enum piece_t {EMPTY, PAWN, ROOK, KNIGHT, BISHOP, QUEEN, KING}; enum side_t {WHITE, BLACK}; int main() { //Set up

In C++

image text in transcribed

#include #include using namespace std;

enum piece_t {EMPTY, PAWN, ROOK, KNIGHT, BISHOP, QUEEN, KING}; enum side_t {WHITE, BLACK};

int main() { //Set up the board //Get # of moves //Read in and perform moves //Print out the board return 0; }

Write a program that is capable of replaying the moves in a chess match. The user will first enter the number of moves, then they will type in moves of the form: where [a] can be any letter a-h (representing a column on the board), [#] can be 1-8 (representing a row on the board), and the move takes the piece at the first position and moves it to the second For example, the common opening move c2-c4 would take the chess piece at c2 (initially a pawn) and move it to space c4. Note that every move will leave its initial space (c2) empty afterwards, and when a piece moves to a space occupied by another piece, the existing piece is taken away and the "capturing" piece occupies that space. The game of chess is played between two opposing players, white and black, where each player starts 16 pieces of 6 different types: pawn rook, knight, bishop, queen, and king. Initially, white's pieces occupy rows 1 and 2, while black's pieces occupy rows 7 and 8. All of the pieces on rows 2 and 7 are pawns, though the pieces on rows 1 and 8 differ. Columns a and h on these rows have rooks, b and g have knights, c and f have bishops, d has the two queens, and e has the two kings Using P R, N (knight), B, Q, and K to represent the chess pieces (capital for white and lowercase for black) and. to represent an empty space, we can draw this initial board as RNBQKBNR rnbgkbnr Once the user has entered all of the moves, the program should print the final state of the board, in this format. As usual, this should be the only output for the program Note that your program does NOT need to check the validity of the moves according to the rules of chess, just to replay them. Your program will not be tested on whether it can recognize improperly formatted moves (e.g., moves that don't start with a-h or don't have two spaces separated by a hyphen), but you may wish to do some input checking to help when testing your code. Also, you may treat a move that starts with an empty space as valid-let the empty space "capture" wherever it moves (ie., make the destination empty). Lastly, the number of moves is guaranteed to be a nonnegative integer Hint: if you add 32 (0x20) to the ASClIl code for an uppercase letter, you can get the ASCIl code for the lowercase version of that letter Write a program that is capable of replaying the moves in a chess match. The user will first enter the number of moves, then they will type in moves of the form: where [a] can be any letter a-h (representing a column on the board), [#] can be 1-8 (representing a row on the board), and the move takes the piece at the first position and moves it to the second For example, the common opening move c2-c4 would take the chess piece at c2 (initially a pawn) and move it to space c4. Note that every move will leave its initial space (c2) empty afterwards, and when a piece moves to a space occupied by another piece, the existing piece is taken away and the "capturing" piece occupies that space. The game of chess is played between two opposing players, white and black, where each player starts 16 pieces of 6 different types: pawn rook, knight, bishop, queen, and king. Initially, white's pieces occupy rows 1 and 2, while black's pieces occupy rows 7 and 8. All of the pieces on rows 2 and 7 are pawns, though the pieces on rows 1 and 8 differ. Columns a and h on these rows have rooks, b and g have knights, c and f have bishops, d has the two queens, and e has the two kings Using P R, N (knight), B, Q, and K to represent the chess pieces (capital for white and lowercase for black) and. to represent an empty space, we can draw this initial board as RNBQKBNR rnbgkbnr Once the user has entered all of the moves, the program should print the final state of the board, in this format. As usual, this should be the only output for the program Note that your program does NOT need to check the validity of the moves according to the rules of chess, just to replay them. Your program will not be tested on whether it can recognize improperly formatted moves (e.g., moves that don't start with a-h or don't have two spaces separated by a hyphen), but you may wish to do some input checking to help when testing your code. Also, you may treat a move that starts with an empty space as valid-let the empty space "capture" wherever it moves (ie., make the destination empty). Lastly, the number of moves is guaranteed to be a nonnegative integer Hint: if you add 32 (0x20) to the ASClIl code for an uppercase letter, you can get the ASCIl code for the lowercase version of that letter

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

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago