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
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
PYTHON
Chess Moves Mapper using Shortest path
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
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
- Board height and width range from 7 to 10 and are independent of each other.
- All piece inputs will be valid piece inputs from the list given
- Starting and end positions will always be within the specified board size
- No special moves allowed like pawn moving 2 steps ahead from second row, en passant, and castling.
- 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
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 |
Step by step
Solved in 2 steps