Question: 5 Chessboard game tTo (pl, p2, board.dim, max.moves) Description Current position (row, column) of the knight. Desired position (row, column) of the knight. Size of
5 Chessboard game tTo (pl, p2, board.dim, max.moves) Description Current position (row, column) of the knight. Desired position (row, column) of the knight. Size of chessboard (rows, columns). Maximum number of moves to check into the future Description Minimum number of moves the knight has to take to get function moves #myKnigh Type 1x2 double 1x2 double 1x2 double 1x1 double Type 1x1 double Input pl p2 board dim max moves Output moves from its current pdsition pl to position p2 Details On a chessboard of size board.dim, a player wants to move their knight from position pl to position p2. A chess knight can take one move every step, where cach move is two squares in a cardinal direction, then one square in an orthogonal direction, as illustrated below. The knight continues moving until it reaches its target position. What is the minimum number of moves that the knight has to take? Tips . The top-left square of the board is (1, 1). This way we can treat each tile of the board as a matrix component, Note that the first index refers to the vertical direction going downwards and the second index refers to the horizontal direction going to the right. Recursion could be helpful here. . If you cannot find a sequence of moves that gets the knight to the target position within max.moves, your function should return Inf. . M lake use of max.moves to limit the number of possible moves you have to check and make the problem tractable. Your code should be able to run the given test case within a few seconds. Code that takes extremely long to run will be flagged and lose points in the autograder. . Be carcful of testing the problem with max.moves higher than 5. The computing time of the problem increases dramatically
Step by Step Solution
There are 3 Steps involved in it
To solve this problem well use a breadthfirst search BFS algorithm This approach will efficiently fi... View full answer
Get step-by-step solutions from verified subject matter experts
