Question: C++ You will create a problem that takes in a board with chess pieces from file. For this exercise, the board will only contain pawns

C++

You will create a problem that takes in a board with chess pieces from file. For this exercise, the board will only contain pawns and rooks. The dimensions of the board will be some MxN dimensions where both M and N are greater than 1.

Given a board, you will mark all pawns that can be attacked by a rook. Recall, a rook can move horizontally or vertically through empty spaces until it reaches an end of the board or another piece.

You job is to read in the file, find all the pawns that can be attacked, and print an updated board to the screen.

Piece and Board Representations

Rooks: 'R'

Pawns: 'P'

Empty spaces: '*'

When you find a pawn that can be attacked, change it from a 'P' to a '!'

There will be 3 components

void read //reading the file

void write //writing the file

int main() //does everything else

Sample file

The files will contain the dimensions on the first line of the file then contain a board with a mix of empty spaces, pawns, and rooks.

Command-line argument:

$>./lab08 sample.txt

Contents of sample.txt input file:

4 5 *P**R *R*** ****P P***P 

Output to terminal:

*!**R *R*** ****! P***P 

Notes:

The pawn at position (3,0) cannot be attacked because there is no rook in its row or column

The pawn at position (3,4) cannot be attacked because there is a piece between it and the rook in its column

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!