Problem Statement
You will be given a
Definition
- Class:
- CaptureThemAll
- Method:
- fastKnight
- Parameters:
- String, String, String
- Returns:
- int
- Method signature:
- int fastKnight(String knight, String rook, String queen)
- (be sure your method is public)
Notes
- A knight's jump moves him 2 cells along one of the axes, and 1 cell along the other one. In other words, if knight is in the (0,0) now, it can be in (-2, -1), (-2, 1), (2, -1), (2, 1), (-1, -2), (1, -2), (-1, 2) or (1, 2) after his move.
- The knight will capture one of Joe's pieces if it ends its move in the cell that the piece occupies.
- The knight cannot jump out of the board.
- A chessboard has 8 rows and 8 columns.
Constraints
- knight, rook and queen will all be distinct.
- knight, rook and queen will be formatted as "cr", where c is a lowercase character between 'a' and 'h', inclusive, and r is a digit between '1' and '8', inclusive.
Examples
"a1"
"b3"
"c5"
Returns: 2
From "a1", the knight can move directly to "b3" and capture the rook. From there, the knight can move directly to "c5" and capture the queen.
"b1"
"c3"
"a3"
Returns: 3
The rook and the queen are both 1 move away from the knight. Once the knight captures one of them (it doesn't matter which one), it can return to its starting location, and capture the other piece in one more move.
"a1"
"a2"
"b2"
Returns: 6
The rook and the queen are close, but it takes 6 moves to capture them.
"a1"
"h8"
"b2"
Returns: 8
"a1"
"h8"
"b1"
Returns: 8
"a1"
"a8"
"h8"
Returns: 10
"a5"
"b7"
"e4"
Returns: 3
"c8"
"g6"
"b7"
Returns: 6
"f5"
"c1"
"a3"
Returns: 7
"b2"
"h4"
"a1"
Returns: 8
"b6"
"d3"
"a5"
Returns: 5
"g7"
"e3"
"h6"
Returns: 4
"h8"
"e2"
"d2"
Returns: 6
"g2"
"g7"
"h8"
Returns: 7
"e4"
"c3"
"g1"
Returns: 3
"d1"
"f1"
"a8"
Returns: 6
"c3"
"e6"
"g6"
Returns: 5
"d2"
"f4"
"d8"
Returns: 6
"f1"
"e4"
"f5"
Returns: 4
"e3"
"b2"
"d7"
Returns: 5
"e8"
"g3"
"b6"
Returns: 7
"d1"
"f5"
"b8"
Returns: 5
"b8"
"f3"
"d1"
Returns: 7
"h6"
"b8"
"g5"
Returns: 6
"b2"
"g4"
"b5"
Returns: 7
"f4"
"c5"
"f7"
Returns: 5
"f4"
"a3"
"g1"
Returns: 6
"e6"
"d1"
"h8"
Returns: 8
"e3"
"d3"
"g3"
Returns: 5
"d3"
"h3"
"f5"
Returns: 6
"b7"
"g4"
"e8"
Returns: 4
"a8"
"e1"
"e2"
Returns: 7
"g6"
"f2"
"g1"
Returns: 5
"a6"
"c8"
"c3"
Returns: 6
"b6"
"g6"
"e6"
Returns: 5
"c2"
"a1"
"g7"
Returns: 5
"b1"
"e1"
"a4"
Returns: 5
"g6"
"e1"
"d2"
Returns: 5
"f3"
"d2"
"e5"
Returns: 3
"f2"
"e8"
"f8"
Returns: 6
"b3"
"b8"
"d8"
Returns: 5
"a6"
"a4"
"h1"
Returns: 6
"h3"
"b7"
"d2"
Returns: 6
"f5"
"d4"
"e6"
Returns: 2
"g7"
"e6"
"e4"
Returns: 3
"b6"
"e8"
"b2"
Returns: 5
"e6"
"e3"
"d1"
Returns: 4
"f5"
"e6"
"g2"
Returns: 4
"h8"
"e2"
"d2"
Returns: 6
"a1"
"h1"
"a8"
Returns: 11