-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot.hs
52 lines (37 loc) · 1.16 KB
/
robot.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module Robot where
import Data.Array
import Data.List
import Control.Monad
import Control.Applicative
import System.IO
type Position = (Int,Int)
type Grid = Array Position [Direction]
data Direction = North | Ease | South | West
deriving (Eq,Show,Enum)
data Color = Black | Blue | Green | Cyan
| Red | Magenta | Yellow | White
deriving (Eq, Ord, Bounded, Enum, Ix, Show, Read)
type Energy = Maybe Double
data RobotState
= RobotState
{ position :: Position
, facing :: Direction
, pen :: Bool
, color :: Color
, treasure :: [Position]
, pocket :: Int
, energy :: Energy
}
deriving Show
newtype Robot a
= Robot (RobotState)
right :: Direction -> Direction
right d = toEnum $ succ (fromEnum d) `mod` 4
left :: Direction -> Direction
left d = toEnum $ pred (fromEnum d) `mod` 4
-- updateState :: (RobotState -> RobotState) -> Robot
-- updateState u = Robot (\s -> return (u s, ()))
-- turnLeft :: Robot
-- turnLeft = updateState (\s -> s {facing=left (facing s)})
-- turnRight :: Robot
-- turnRight = updateState (\s -> s {facing=right (facing s)})