Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: - become familiar with a C++ coding environment (Linux, Visual Studio, X-Code, ...) - utilize 2-D arrays in C++ - appropriately testing code Problem

image text in transcribed
image text in transcribed
image text in transcribed
Objectives: - become familiar with a C++ coding environment (Linux, Visual Studio, X-Code, ...) - utilize 2-D arrays in C++ - appropriately testing code Problem Description In the game of chess, a game board has a specified number of rows and columns (usually 8 rows and 8 columns.) A "rook" is a chess game piece that can move across any number of columns in a horizontal direction or any number of rows in a vertical direction (but a rook cannot move diagonally in any way.) This is indicated for one rook in the image below, where the green squares represent possible moves for a rook found at row ' 3 ' and column ' e ' Note that, as in the above figure, most chess players number the rows from 1-8, while the columns are labelled with letters by most chess players. As coders, we tend to think about these as rows 0 through 7 and columns 0 through 7 instead. In chess, two game pieces (of any type, but we are only concerned about rooks in this assignment) are said to be attacking each other if a single valid move can land one piece in the same square as another game piece. You will be writing a complete C++ program that checks to see if there exists a pair (or more) of two rooks on a given chess board (that only has rook game pieces on it) that are attacking each other. There is one additional component to this problem - several of the squares on the board have "biocks" in them, and a rook cannot move or see past a block. Your program should: 1. prompt for and read in the name of an input file containing the size of a chess board, the locations of rooks, and the locations of blocks as follows: - the first item in the input file will be a (positive) integer representing the number of rows in the chess board. This value will be no larger than 100. - the second item in the input file will be a (positive) integer representing the number of columns in the chess board. This value will be no larger than 100. - What follows will be a sequence of rows, each containing one character for each column. There are three possible values for each character: * '. ", which means this is am empty chess board square (that does not contain a block or a rook) - '\#', which means this chess board square is a biock - 1R, which means this chess board square contains rook 2. Print out the board, as read from the input file, one row at a time. 3. Print out one of two messages, based on the placement of rooks and blocks on the chess board: - "No two rooks can attack each other" should be printed if no two rooks can attack each other. - "At least two rooks can attack each other" should be printed if two or more rooks can attack each other. For example, suppose the file named input1. data contains the following: 57 . 7 chess board has 5 rows and 7 columns. , R, . a, a R R,RDR ARHRARE R.. H...R If you ran your program and specified the above input file (with program output in regular text and input in italics ) then the execution would look like: Please enter the name of an input file: input1.data ..R. \# R. +R++N+N RA##R \# R No two rooks can attack each other Note that some other example input files will be posted to Canvas

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions