Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

you should write a C program named infinite_chess.c. This program will accept two inputs from standard in. The first will be one character (used to

you should write a C program named infinite_chess.c. This program will accept two inputs from standard in. The first will be one character (used to identify which type of chess piece we are dealing with) and the second will be an integer number, representing the number of moves to simulate. You should get both of these input values using the scanf function. For this program, the only two standard library imports you are allowed to use are and . You may *not* use math.h. As you may already know, a chess board is typically an 8x8 2D grid. However, for this assignment, you should assume we are working with an infinitely large 2D grid / board. The goal of the program is to determine how many possible board locations a particular piece could be at if it started from some location on the board and was able to make at most N moves. You can expect that the first input will be one of three characters: k (for king) b (for brigadier) and p (for pawn). In real chess, pawn movement is a bit more complex, but for our purposes a Pawn can only move 1 location, and can only move in 1 direction (forward). Thus, this is the easiest one to simulate. If the pawn had zero moves, there is only 1 location it could be at. If it had 1 move, it could be in 2 possible places. If it had 2 moves, it could be in 3 possible spots, and so on. When a King moves in chess, it can move to any of the neighboring pieces on the board, including diagonals. For this problem, if the king had zero moves, there is only 1 piece it could be at. However, if it had 1 move, it could be in 9 possible places. If it had 2 moves, it could be in any of 25 possible positions, and so on. The Brigadier is a new chess piece that I made up for this PA. A brigadier can only move to any of its 4 neighboring diagonal locations. It cannot move directly forward / backward / left / right. Thus, if the brigadier had zero moves, there is only 1 piece it could be at. However, if it had 1 move, it could be in 5 possible places. If it had 2 moves, it could be in any of 13 possible positions, and so on. Here are a few examples, with standard input highlighted in red:

image text in transcribed

$ ./a.out Enter piece type (k, b, p): k Enter number of moves: 5 possible locations: 121 $ ./a.out Enter piece type (k, b, p): p Enter number of moves: 20 possible locations: 21

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

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

What is Ramayana, who is its creator, why was Ramayana written?

Answered: 1 week ago

Question

To solve by the graphical methods 2x +3y = 9 9x - 8y = 10

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago