Programming Mini-Challenge: KnightBot

Mallard
Sun, 16 Sep 2018 16:47:22 +0000

Another programming mini-challenge for you. It's been a month since the first one and that seemed to be rather successful. (I appreciate that there are other challenges on here but trying to sync with them seems tricky!)

A reminder:
I'm certain that many of you might find these pretty straight forward, but I still think there's merit in sharing different approaches to simple problems, including weird-and-wonderful ones.

KnightBot

Info

You will be writing a small part of a Chess program, specifically focusing on the Knight, on an 8 x 8 board.

Input

The top-left square of the board will have index 0, and the bottom-right square will have index 63.

The first input is the starting square of the knight.

The second input is the requested finishing square of the knight.

The third input is the number of maximum moves allowed.

Output

The expected outcome is either True or False, determined by whether or not the Knight can reach the requested finishing square within the number of allowed moves when stating on the starting square.

e.g. The expected output for the input 16, 21, 4 is True since the Knight can move 16->33->27->21, which is 3 moves.

Extensions

Some additional ideas for extending this challenge...

1. Instead of an 8x8, what if the board was nxn?

2. Instead of "within x moves", what if it was "with exactly x moves?"

3. Instead of a traditional Knight's move (2 long, 1 short), what if it was n long and m short?

4. What if the board was infinite?

5. What if the board looped back around when crossing the edges? (e.g. the square to the right of 7 is 0)

Comments URL: https://tildes.net/~comp/6g2/programming_mini_challenge_knightbot

Votes: 17

Comments: 6