Step back from the code for a moment and spend some time thinking about how to actually approach the problem. There are a few separate steps involved in a problem like this:
1) What data structure will you use to represent the chessboard?
If you asked ten people this question you'd probably get ten different answers. Think of a few different possibilities, and select the one you like the most. One simple example might be an 8x8 array, but what advantages and disadvantages does that have? Might there be anything better?
2) How can I represent a move?
Again, many possible choices. You could have a Move
class, a (fromSquare, toSquare)
tuple, etc. The answer to this question will depend to some extent on your choice of data structure in part one.
3) How can I generate the set of legal knight moves?
Probably the trickiest aspect. You'll need to devise an algorithm that computes every legal (from, to)
pair, using whatever move representation you selected. You will have to pay attention to what happens near the edge of the board to ensure that the knight cannot fall off, or wrap around to the opposite side of the board.
Once you have an answer to all of these, sit back down and work your way through the code slowly. Get one thing working at a time; perhaps the first milestone could be a little printout of the current board position?
Good luck with your assignment.