ING Chess Moves Mapper using Shortest path algorithm As the title indicates, you will need to determine the number of moves it will take for the different chess pieces from their current position to any other tile in the board. While a standard chess board will have an 8 x 8 grid chess board, your code should be able to handle boards of different dimensions.  For this program the board will be blank. The only piece will be the one inputted. Input Format s1, s2, x1, y1, piece All inputs end with a '\n' s1, s2 - horizontal size and vertical size of the board respectively. x1, y1 - starting position of the piece. Refer to Figure 3. for coordinate convention piece - name of the piece. Use the following names. [p

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter6: System Integration And Performance
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

PYTHON PROGRAMMING

Chess Moves Mapper using Shortest path algorithm

As the title indicates, you will need to determine the number of moves it will take for the different chess pieces from their current position to any other tile in the board. While a standard chess board will have an 8 x 8 grid chess board, your code should be able to handle boards of different dimensions. 

For this program the board will be blank. The only piece will be the one inputted.

Input Format

s1, s2, x1, y1, piece

All inputs end with a '\n'

s1, s2 - horizontal size and vertical size of the board respectively.

x1, y1 - starting position of the piece. Refer to Figure 3. for coordinate convention

piece - name of the piece. Use the following names. [pawn, rook, knight, bishop, queen, king]

 

Given the initial starting position of a given piece, you will be asked to determine the minimum number of moves needed to reach any position in the tile. A sample setup is shown below as well as a visualization of the solution. See Figure 1.

The number in the output grid is the minimum number of moves it will take for the chess piece, in this case the bishop, to reach that specific position. The starting position of the piece is marked as 0 and unreachable tiles are marked as -1. See Figure 1 and 2 for examples. Note that this program will only consider the one piece that is inputted, and will not have extra pieces in the way.

Constraints

  1. Board height and width range from 7 to 10 and are independent of each other.
  2. All piece inputs will be valid piece inputs from the list given
  3. Starting and end positions will always be within the specified board size
  4. No special moves allowed like pawn moving 2 steps ahead from second row, en passant, and castling.
  5. x,y - Coordinates of squares for starting position, ending position, and/or blocking pieces. The board is numbered according to Figure 3. (x is the horizontal coordinate and y is the vertical coordinate)

Output Format

z1
z2
z3
...
<there is a blank line at the end>

All outputs end with a '\n'

z1, z2, … - The values of the grid indicating the minimum number of moves the indicated piece needs to reach each square from the starting position. Print the grid numbers in the following order ((0,0)->(0,n)->(1,0)->(m,n)). In other words print the values from left to right going up. 

Example:

3 6 -1
2 5 -1
1 4 -1
 
Will be outputted as:
1
4
-1
2
5
-1
3
6
-1
(space because of \n)
 
SAMPLE INPUT
7, 8, 0, 0, pawn
 
SAMPLE OUTPUT
0
-1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
-1
3
-1
-1
-1
-1
-1
-1
4
-1
-1
-1
-1
-1
-1
5
-1
-1
-1
-1
-1
-1
6
-1
-1
-1
-1
-1
-1
7
-1
-1
-1
-1
-1
-1
 
|-1
|1
|-1
2
|-1
|2
|-1
|1
|2
|-1
|1
|-1
|2
|-1
|1
|-1
8
++
|-1
|2
|-1 |2
|1
|-1
|-1
|e
|1
|-1
|-1
|2
|2
|-1
Do
Figure 1
|2
|-1
|-1 |2
|2
|-1
|-1
|1
|1
|-1
|-1
|2
|-1
|-1
|-1
|3
|2
|-1
CO
|-1
| 1
|1
|-1
|-1
|2
|-1 |-1
|-1
3
|2
|-1
|-1 |2
13
|-1
2
Figure 3
| (0,7) | (1,7) | (2,7) | (3,7) | (4,7) | (5,7) | (6,7)| (7,7) |
| (0,6) | (1,6) | (2,6) | (3,6) | (4,6) | (5,6)| (6,6) | (7,6) |
| (0,5) | (1,5) | (2,5) | (3,5) | (4,5)| (5,5)| (6,5) | (7,5) |
| (0,4) | (1,4) | (2,4) | (3,4) | (4,4) | (5,4) | (6,4) | (7,4) |
| (0,3) | (1,3)| (2,3) | (3,3) | (4,3)| (5,3)| (6,3) | (7,3) |
| (0,2)| (1,2) | (2,2) | (3,2) | (4,2)| (5,2)| (6,2)| (7,2) |
| (0,1) | (1,1) | (2,1) | (3,1) | (4,1) | (5,1) | (6,1) | (7,1) |
| (0,0) | (1,0) | (2,0) | (3,0) | (4,0) | (5,0) | (6,0)| (7,0) |
Transcribed Image Text:|-1 |1 |-1 2 |-1 |2 |-1 |1 |2 |-1 |1 |-1 |2 |-1 |1 |-1 8 ++ |-1 |2 |-1 |2 |1 |-1 |-1 |e |1 |-1 |-1 |2 |2 |-1 Do Figure 1 |2 |-1 |-1 |2 |2 |-1 |-1 |1 |1 |-1 |-1 |2 |-1 |-1 |-1 |3 |2 |-1 CO |-1 | 1 |1 |-1 |-1 |2 |-1 |-1 |-1 3 |2 |-1 |-1 |2 13 |-1 2 Figure 3 | (0,7) | (1,7) | (2,7) | (3,7) | (4,7) | (5,7) | (6,7)| (7,7) | | (0,6) | (1,6) | (2,6) | (3,6) | (4,6) | (5,6)| (6,6) | (7,6) | | (0,5) | (1,5) | (2,5) | (3,5) | (4,5)| (5,5)| (6,5) | (7,5) | | (0,4) | (1,4) | (2,4) | (3,4) | (4,4) | (5,4) | (6,4) | (7,4) | | (0,3) | (1,3)| (2,3) | (3,3) | (4,3)| (5,3)| (6,3) | (7,3) | | (0,2)| (1,2) | (2,2) | (3,2) | (4,2)| (5,2)| (6,2)| (7,2) | | (0,1) | (1,1) | (2,1) | (3,1) | (4,1) | (5,1) | (6,1) | (7,1) | | (0,0) | (1,0) | (2,0) | (3,0) | (4,0) | (5,0) | (6,0)| (7,0) |
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
Figure 2
6
5
3
2
1
-1
-1 -1
-1 1
-1
-1
-1 -1 -1
2
2
-1 -1
-1 -1
-1
-1
-1
-1
-1 -1
-1 -1 -1
-1 -1
-1 -1
2
2
2
2
2 1
1
N
2
2
2
2
2
2
N
1
2
1
1
Y
2
2
f
2
2
1
1
2
2
2
2 2 2
2
2
2
2
1
2
1
2
b
2
2
9
2
1
2
1
2
1
2
2
2
d
2
1
2
2
N
1
2
2
8
5
m
1
1
1
2
IOC
~~
2
2 2
2
2 2
1
1
2
2
1 2 2
f
1
1
2
2
2
7
5
3
Transcribed Image Text:-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 Figure 2 6 5 3 2 1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 2 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 2 2 2 2 2 1 1 N 2 2 2 2 2 2 N 1 2 1 1 Y 2 2 f 2 2 1 1 2 2 2 2 2 2 2 2 2 2 1 2 1 2 b 2 2 9 2 1 2 1 2 1 2 2 2 d 2 1 2 2 N 1 2 2 8 5 m 1 1 1 2 IOC ~~ 2 2 2 2 2 2 1 1 2 2 1 2 2 f 1 1 2 2 2 7 5 3
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning