From d31939c6ed9249b47c4df4442fa2b8d9205e68e9 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sun, 15 Nov 2020 13:07:08 +0100 Subject: [PATCH] Fix export and use correct direction and position Signed-off-by: Matej Focko --- Internal/World.hs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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