Problem Statement
PROBLEM STATEMENT The chessboard is an 8 by 8 grid of squares. For the purpose of this problem consider the rows of the chessboard to be numbered from 1 to 8 starting at the top and moving down, and the columns to be numbered from 1 to 8 starting at the left and moving right. Board positions will be identified by (row,column) ordered pairs. The knight is a chess piece capable of moving exactly two squares in one direction and then one square perpendicularly. Assuming the board is empty except for a knight, the problem is to determine the minimum number of moves required to move from point A to point B on the board. DEFINITION Class name: ChessBoard Method name: getMinMoves Parameters: String Return type: int Method signature: int getMinMoves(String pos); Be sure your method is public. Each test case contains 4 integers in the range 1 to 8, delimited by one or more spaces, representing the row and column of the starting position on the board, and the row and column of the destination position, respectively. For each test case, return the minimum number of moves required to reach the destination position from the starting position. TopCoder will ensure that: * all positions given are valid positions on a chess board. * the input will be of the form (quotation marks are included for clarity only) "int int int int", where there is one or more spaces between each int. Each int must be between 1 and 8 inclusive. NOTES * if the starting position and the destination position are the same, the number of moves is zero. * the knight cannot move diagonally. EXAMPLES 1. Given the position string "5 5 4 5", the minimum number of moves to get from position (5, 5) to position (4, 5) is 3. 2. Given the position string "3 1 3 8", the minimum number of moves to get from position (3, 1) to position (3, 8) is 5.
Definition
- Class:
- ChessBoard
- Method:
- getMinMoves
- Parameters:
- String
- Returns:
- int
- Method signature:
- int getMinMoves(String param0)
- (be sure your method is public)
Constraints
Examples
No public sample cases were explicitly marked for this problem in the original data.