deriving (Show, Eq)
makeLenses ''Person
-data Field = Field { getMap :: FieldMap, whatsAheadFunc :: Person -> FieldContext Person, whatsAtFunc :: Position -> FieldContext Cell}
+data Field = Field { getMap :: FieldMap
+ , whatsAheadFunc :: Person -> FieldContext Person
+ -- , whatsAtFunc :: Position -> FieldContext Cell
+ }
type FieldContext = Reader Field
data Face = A | B | C | D | E | F
mkFlatField fieldMap =
Field { getMap = fieldMap
, whatsAheadFunc = whatsAheadFlat
- , whatsAtFunc = whatsAt}
+ -- , whatsAtFunc = whatsAt
+ }
mkCubeField :: FieldMap -> Field
mkCubeField fieldMap =
Field { getMap = fieldMap
, whatsAheadFunc = whatsAheadCube
- , whatsAtFunc = whatsAt}
+ -- , whatsAtFunc = whatsAt
+ }
whatsAt :: Position -> FieldContext Cell
whatsAt posiiton =
walk :: Person -> [PathElement] -> FieldContext Person
-walk person [] = return person
-walk person (step:steps) =
- do person' <- walkOne person step
- walk person' steps
+walk person path = foldM walkOne person path
walkOne :: Person -> PathElement -> FieldContext Person
walkOne person (Forward n)
| otherwise =
do whatsAhead <- asks whatsAheadFunc
person' <- whatsAhead person
- whatsAt <- asks whatsAtFunc
+ -- whatsAt <- asks whatsAtFunc
nextCell <- whatsAt (person' ^. position)
if nextCell == Wall
then return person