Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students also viewed these Databases questions