Kubicschach (Cubic Chess Path Finding)
Statement
Goal
In 1851, Lionel Kieseritzky invented one of the first variations of a 3D Chess game, "Kubikschach", or Cubic Chess in German.In this puzzle, you must calculate the least number of moves for a specific piece to move from one position to another on an empty 8x8x8 chess board based on the movements defined below.
Each position is indexed by a capital letter, a number, and a lowercase letter, for the its row, column, and slice (YXZ => RCS => A1a). The game's "board" is made by creating 8 "slices" which are
The two players, Black and White, each have a "Home Row" located opposite one another, that being row A within the h-slice for Black and row H within the a-slice for White. The color of the given piece will only affect the movement of the pawn.
A1h A2h A3h A4h A5h A6h A7h A8h <-- Black Home Row
A1g . . . . . . A8g
A1f . . . . . . A8f
A1e . . . . . . A8e
A1d . . . . . . A8d
A1c . . . . . . A8c
A1b . . . . . . A8b
A1a A2a A3a A4a A5a A6a A7a A8a <-- "Slice" a
B1a . . . . . . B8a /
C1a . . . . . . C8a <--
D1a . . . . . . D8a /
E1a . . . . . . E8a <--
F1a . . . . . . F8a
G1a . . . . . . G8a
H1a H2a H3a H4a H5a H6a H7a H8a <-- White Home Row
Here are the rules governing the movement of each piece:
King may move
(Ex: A1a -> A1b, or A2b, or B2b, etc.)
Pawn may move
(Ex-White Pawn: H1a -> G1a, H1a -> H1b, NOT H1a -> G1b, NOT A1a -> B1a)
Rook may move
(Ex: F3d -> F8d, A1a -> H1a, D6c -> D6b)
Bishop may move
(Ex: A1a -> H8h, D4f -> A7b, NOT A1a -> H8a)
Queen may move
(Ex: A1a -> B2b, A1a -> B1a, A1a -> A2a, NOT A1a -> B2a)
Knight must move
(Ex: A1a -> B3a, A1a -> B1c, A1a -> C1b, F4d -> G2d)
No piece may ever leave the chess board. For this level the pawn will always move 1 space and will not need to be promoted to reach the final space.
Input
Line 1: A name of a chess piece, piece, followed by the first initial, color, of the color of the piece, separated by a space
Line 2: A 3-character String, startingPosition
Line 3: A 3-character String, finalPosition
Line 2: A 3-character String, startingPosition
Line 3: A 3-character String, finalPosition
Output
The least number of moves, N, that a chess piece, piece, can move from startingPosition to finalPosition, or -1 if it cannot move to the desired position.
Constraints
A1a <= startingPosition, finalPosition <= H8h
piece is always the White Player's Piece
piece is always the White Player's Piece
Example
Input
King W A1a B3d
Output
3
Tags
Pathfinding
Difficulty
Medium
Test cases
King 1 Test
Input
King W
A1a
B3d
Output
3
Validator King 1 Validator
Input
King W
F6d
D2d
Output
4
King 2 Test
Input
King W
A1a
A1a
Output
0
Validator King 2 Validator
Input
King W
B7d
B7d
Output
0
Pawn 1 (Black Pawn) Test
Input
Pawn B
C6a
A6g
Output
-1
Validator Pawn 1 (Black Pawn) Validator
Input
Pawn B
F3b
B3e
Output
-1
Pawn 2 (White Pawn) Test
Input
Pawn W
C6a
A6g
Output
8
Validator Pawn 2 (White Pawn) Validator
Input
Pawn W
F3b
B3e
Output
7
Rook 1 Test
Input
Rook W
G6f
C2e
Output
3
Validator Rook 1 Validator
Input
Rook W
H3g
A7b
Output
3
Rook 2 Test
Input
Rook W
D8c
D8g
Output
1
Validator Rook 2 Validator
Input
Rook W
F5d
F3f
Output
2
Bishop 1 Test
Input
Bishop W
C5g
A3e
Output
1
Validator Bishop 1 Validator
Input
Bishop W
D4h
G1e
Output
1
Bishop 2 Test
Input
Bishop B
H3a
A6h
Output
2
Validator Bishop 2 Validator
Input
Bishop B
C4f
E4f
Output
2
Bishop 3 Test
Input
Bishop W
E7b
F4g
Output
3
Validator Bishop 3 Validator
Input
Bishop W
H4d
F8d
Output
3
Bishop 4 Test
Input
Bishop W
D6e
F5f
Output
-1
Validator Bishop 4 Validator
Input
Bishop W
G3d
D1g
Output
-1
Queen 1 Test
Input
Queen W
E7b
F4g
Output
3
Validator Queen 1 Validator
Input
Queen W
H4g
F8a
Output
3
Queen 2 Test
Input
Queen W
D6e
F5f
Output
2
Validator Queen 2 Validator
Input
Queen W
G3d
D1g
Output
2
Knight 1 Test
Input
Knight W
A1a
A7a
Output
4
Validator Knight 1 Validator
Input
Knight W
H4e
H4f
Output
3
Knight 2 Test
Input
Knight W
A1a
H7h
Output
8
Validator Knight 2 Validator
Input
Knight W
B2g
F5a
Output
5
Pawn 3 (Black Pawn) Test
Input
Pawn B
A6g
C6a
Output
8
Validator 3 (Black Pawn) Validator
Input
Pawn B
B3e
F3b
Output
7
Solution language
Solution
Stub generator input