bn

Now that we have a visual board to display, and we’ve called for the engine to check for all available moves, we need to actually add moves for each piece. Today we are going to start with the knight. I started with the knight because I thought it would be the most difficult.

A fun fact about knights: knights have the advantage of being able to control squares of either color, unlike a lone bishop, however, a lone bishop can trap (although it cannot then capture) a knight on the edge of the board, or rim, especially in the endgame.

I ended up doing the knights move in two stages. I first made the knight’s moves, and later realized a way to make it better.

If the knight is on whichever side of the board, it can make the appropriate L or T shaped move in the opposite side of the board. Since our board is made of number squares, it really was just a mathematical problem. In every case, it is the following four algebraic equations:

  • Move to (m) = Knight (n) +/- number.
  • m = n +/- 17
  • m = n +/- 15
  • m = n +/- 10
  • m = n +/- 6

Pretty cool, huh? Be sure to check out the commits here and here.

Linux – keep it simple.

Leave a Reply

Your email address will not be published.