Skip to content

Instantly share code, notes, and snippets.

@mk0x9
Created October 23, 2011 13:37
Show Gist options
  • Save mk0x9/1307367 to your computer and use it in GitHub Desktop.
Save mk0x9/1307367 to your computer and use it in GitHub Desktop.
Direction
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)
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