Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WRITE THIS PROGRAM IN C++!! Chess Simulator: Write a program that is capable of replaying the moves in a chess match. The user will first

WRITE THIS PROGRAM IN C++!!

Chess Simulator:

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: [a][#]-[a][#] 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 PPPPPPPP ........ ........ ........ ........ pppppppp rnbqkbnr 

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 (i.e., make the destination empty). Lastly, the number of moves is guaranteed to be a nonnegative integer.

Hint: if you add 32 (0x20) to the ASCII code for an uppercase letter, you can get the ASCII code for the lowercase version of that letter.

**PLEASE POST WITH COMMENTS!** Thanks!

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_2

Step: 3

blur-text-image_3

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

=+5 Does this case provide an example of the future for IHRM?

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago