Created
December 5, 2013 07:03
-
-
Save jacknoble/7801291 to your computer and use it in GitHub Desktop.
Ugly checkers move rule method
This file contains hidden or 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
| def assert_legal_direction(dir) | |
| unless dir.all?{|coord| coord.abs == 1} | |
| raise InvalidMoveError.new "tried to move too many squares" | |
| end | |
| unless (dir[0] + dir[1]).even? | |
| raise InvalidMoveError.new "did not move diagonally" | |
| end | |
| unless king | |
| if wrong_way?(dir[0]) | |
| raise InvalidMoveError.new "pawns can't move in that direction" | |
| end | |
| end | |
| nil | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment