Created
October 23, 2011 13:37
-
-
Save mk0x9/1307367 to your computer and use it in GitHub Desktop.
Direction
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
entity2order :: Ant -> Point -> [Order] | |
entity2order a food = let xant = snd.point $ a | |
yant = fst.point $ a | |
xfood = snd food | |
yfood = fst food | |
in case compare xant xfood of | |
GT -> map (Order a) (directionClockWise West) | |
LT -> map (Order a) (directionClockWise East) | |
EQ -> case compare yant yfood of | |
GT -> map (Order a) (directionClockWise North) | |
otherwise -> map (Order a) (directionClockWise South) |
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
int2dir x | x `mod` 4 == 0 = North | |
| x `mod` 4 == 1 = East | |
| x `mod` 4 == 2 = South | |
| x `mod` 4 == 3 = West | |
dir2int x | x == North = 0 | |
| x == East = 1 | |
| x == South = 2 | |
| x == West = 3 | |
rotateDirection op x = [ x | |
, int2dir $ (dir2int x) `op` 1 | |
, int2dir $ (dir2int x) `op` 2 | |
, int2dir $ (dir2int x) `op` 3 ] | |
directionClockWise = rotateDirection (+) | |
directionCounterClockWise = rotateDirection (-) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment