diff --git a/Internal/World.hs b/Internal/World.hs index 5e37973..08bb6d1 100644 --- a/Internal/World.hs +++ b/Internal/World.hs @@ -1,7 +1,7 @@ {-# LANGUAGE LambdaCase #-} module Internal.World - ( World, + ( World(..), worldWithDimensions, getBeepersAt, setBeepersAt, @@ -70,29 +70,29 @@ addWallAt :: Vector -> Direction -> World -> World addWallAt pos dir w | not $ positionWithinWorld w newPosition = error "Invalid position" | isOnEdge (worldDimensions w) newPosition newDirection = w - | otherwise = w {worldWalls = M.insert pos newWalls (worldWalls w)} + | otherwise = w {worldWalls = M.insert newPosition newWalls (worldWalls w)} where (newPosition, newDirection) = switchDirectionToInternal pos dir - oldWalls = M.findWithDefault S.empty pos (worldWalls w) - newWalls = S.union oldWalls $ S.singleton dir + oldWalls = M.findWithDefault S.empty newPosition (worldWalls w) + newWalls = S.union oldWalls $ S.singleton newDirection removeWallAt :: Vector -> Direction -> World -> World removeWallAt pos dir w | not $ positionWithinWorld w newPosition = error "Invalid position" | isOnEdge (worldDimensions w) newPosition newDirection = w - | S.null newWalls = w {worldWalls = M.delete pos (worldWalls w)} - | otherwise = w {worldWalls = M.insert pos newWalls (worldWalls w)} + | S.null newWalls = w {worldWalls = M.delete newPosition (worldWalls w)} + | otherwise = w {worldWalls = M.insert newPosition newWalls (worldWalls w)} where (newPosition, newDirection) = switchDirectionToInternal pos dir - oldWalls = M.findWithDefault S.empty pos (worldWalls w) - newWalls = oldWalls S.\\ S.singleton dir + oldWalls = M.findWithDefault S.empty newPosition (worldWalls w) + newWalls = oldWalls S.\\ S.singleton newDirection hasWallAt :: Vector -> Direction -> World -> Bool hasWallAt pos dir w | not $ positionWithinWorld w newPosition = False | isOnEdge (worldDimensions w) newPosition newDirection = True - | otherwise = case worldWalls w M.!? pos of - Just wallsInPlace -> S.member dir wallsInPlace + | otherwise = case worldWalls w M.!? newPosition of + Just wallsInPlace -> S.member newDirection wallsInPlace Nothing -> False where (newPosition, newDirection) = switchDirectionToInternal pos dir