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!)
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.
You will be writing a small part of a Chess program, specifically focusing on the Knight, on an 8 x 8 board.
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.
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.
Some additional ideas for extending this challenge...
- Instead of an 8x8, what if the board was nxn?
- Instead of "within x moves", what if it was "with exactly x moves?"
- Instead of a traditional Knight's move (2 long, 1 short), what if it was n long and m short?
- What if the board was infinite?
- What if the board looped back around when crossing the edges? (e.g. the square to the right of 7 is 0)