Created
April 3, 2015 13:15
-
-
Save akhileshs/2594fdaa879f1aeee23a to your computer and use it in GitHub Desktop.
simulating a knight's move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> case class KnightPos(c: Int, r: Int) | |
defined class KnightPos | |
scala> :pa | |
// Entering paste mode (ctrl-D to finish) | |
case class KnightPos(c: Int, r: Int) { | |
def move: List[KnightPos] = | |
for { | |
KnightPos(c2, r2) <- List(KnightPos(c + 2, r - 1), KnightPos(c + 2, r + 1), | |
KnightPos(c - 2, r - 1), KnightPos(c - 2, r + 1) | |
, | |
KnightPos(c + 1, r - 2), KnightPos(c + 1, r + 2), | |
KnightPos(c - 1, r - 2), KnightPos(c - 1, r + 2)) if ( | |
((1 |-> 8) contains c2) && ((1 |-> 8) contains r2)) | |
} yield KnightPos(c2, r2) | |
} | |
// Exiting paste mode, now interpreting. | |
defined class KnightPos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment