77 lines
1.6 KiB
Haskell
77 lines
1.6 KiB
Haskell
module Types where
|
|
|
|
type Entrypoint = Char
|
|
|
|
data Direction = East | South | West | North
|
|
deriving (Eq, Ord)
|
|
|
|
instance Enum Direction where
|
|
toEnum 0 = East
|
|
toEnum 1 = South
|
|
toEnum 2 = West
|
|
toEnum 3 = North
|
|
toEnum x = toEnum $ mod x 4
|
|
|
|
fromEnum East = 0
|
|
fromEnum South = 1
|
|
fromEnum West = 2
|
|
fromEnum North = 3
|
|
|
|
succ East = South
|
|
succ South = West
|
|
succ West = North
|
|
succ North = East
|
|
|
|
pred East = North
|
|
pred North = West
|
|
pred West = South
|
|
pred South = East
|
|
|
|
data ModifierKind = Increment | Decrement
|
|
deriving (Eq)
|
|
|
|
data SpecialKind = Duplicate | Conditional
|
|
deriving (Eq)
|
|
|
|
data Tile = Entrypoint
|
|
| Exitpoint
|
|
| Track Direction
|
|
| Modifier ModifierKind
|
|
| Special SpecialKind
|
|
| Machine Char -- user defined machines
|
|
| Ignored
|
|
deriving (Eq)
|
|
|
|
instance Show Tile where
|
|
show t = [tileToChar t]
|
|
|
|
type Factory = [[Tile]]
|
|
|
|
charToTile :: Char -> Tile
|
|
charToTile c = case c of
|
|
'E' -> Entrypoint
|
|
'X' -> Exitpoint
|
|
'>' -> Track East
|
|
'<' -> Track West
|
|
'v' -> Track South
|
|
'^' -> Track North
|
|
'+' -> Modifier Increment
|
|
'-' -> Modifier Decrement
|
|
'D' -> Special Duplicate
|
|
'?' -> Special Conditional
|
|
_ -> Ignored
|
|
|
|
tileToChar :: Tile -> Char
|
|
tileToChar t = case t of
|
|
Entrypoint -> 'E'
|
|
Exitpoint -> 'X'
|
|
Track East -> '>'
|
|
Track West -> '<'
|
|
Track South -> 'v'
|
|
Track North -> '^'
|
|
Modifier Increment -> '+'
|
|
Modifier Decrement -> '-'
|
|
Special Duplicate -> 'D'
|
|
Special Conditional -> '?'
|
|
_ -> ' '
|