A knight’s quest

Here’s a problem that really lends itself to being solved with non-determinism. Say you have a chess board and only one knight piece on it. We want to find out if the knight can reach a certain position in three moves. We’ll just use a pair of numbers to represent the knight’s position on the chess board. The first number will determine the column he’s in and the second number will determine the row.

Haskell:

type KnightPos = (Int,Int)

Then the function moveKnight defines all possible moves for this position:

OK! Let’s do the same in Scala. We can determine a case class Position and the companion object for this class. I’m used to use characters from ‘a’ to ‘h’ for chess rows, but not numbers. The method set will help me to define a knight position taking pairs ('a', 1) or ('c', 4).