I have previously posted a challenge, smallest number of steps for a knight in chess.
Now I would like to go a step further by adding the possibility to choose your piece.
If you place a piece on any square of a chessboard, what is the smallest number of steps to reach every possible position?
Rules
- It is an 8 by 8 board.
- The given input is a coordinate (x, y) and the chosen piece. Explain in the answer how to input the piece of choice.
- The piece starts at an arbitrary position, taken as input.
- The pawn can not start at the bottom row, and can not move 2 steps (like when in the start-position) and travels only to the top of the board not downwards.
- If a piece cannot reach a certain position, use a character of choice to indicate this.
Example
With input (1, 0) for a knight, we start by putting a 0 in that position:
. 0
From here on we continue to fill the entire 8x8 board.
For a knight the output will look as follows:
3 0 3 2 3 2 3 4
2 3 2 1 2 3 4 3
1 2 1 4 3 2 3 4
2 3 2 3 2 3 4 3
3 2 3 2 3 4 3 4
4 3 4 3 4 3 4 5
3 4 3 4 3 4 5 4
4 5 4 5 4 5 4 5
For a pawn with input (1, 7) the output will look like this:
. 6 . . . . . .
. 5 . . . . . .
. 4 . . . . . .
. 3 . . . . . .
. 2 . . . . . .
. 1 . . . . . .
. 0 . . . . . .
. . . . . . . .
In the examples, I start counting from zero but it does not matter if you start from zero or one.
Challenge
The pattern printed for a piece, as short as possible, in any reasonable format.
1,1
the output will be a board with0
and 1,1 and1
at 0,1, instead of traveling down. \$\endgroup\$