From d92763fe09fc9cc4d6f707476b4c420a09bc818a Mon Sep 17 00:00:00 2001 From: nek0 Date: Thu, 7 Dec 2023 12:51:35 +0100 Subject: [PATCH] fix map generation bug --- src-server/Server/Map.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src-server/Server/Map.hs b/src-server/Server/Map.hs index 152c3ca..9fbe8a5 100644 --- a/src-server/Server/Map.hs +++ b/src-server/Server/Map.hs @@ -21,7 +21,7 @@ generateMap -> Int -- ^ Map's height -> IO Map -- ^ resulting Map generateMap mapWidth mapHeight = do - let initMap = M.matrix mapWidth mapHeight (const Air) + let initMap = M.matrix mapHeight mapWidth (const Air) divide 0 0 mapHeight mapWidth initMap where divide :: Int -> Int -> Int -> Int -> Map -> IO Map @@ -39,7 +39,7 @@ generateMap mapWidth mapHeight = do colHole2 <- randomRIO (crossCol + 1, colSize - 1) -- determine all possible passages - let holes = + let allHoles = [ (rowHole1, crossCol) , (rowHole2, crossCol) , (crossRow, colHole1) @@ -47,14 +47,14 @@ generateMap mapWidth mapHeight = do ] -- drop one of the passages randomly - -- randomDropIndex <- randomRIO (0, length allHoles - 1) - let -- randomDrop = allHoles !! randomDropIndex - -- holes = filter (/= randomDrop) allHoles + randomDropIndex <- randomRIO (0, length allHoles - 1) + let randomDrop = allHoles !! randomDropIndex + holes = filter (/= randomDrop) allHoles crossedMap = M.mapPos (\(r, c) tile -> - if (r - rowOffset == crossRow || c - colOffset == crossCol) && - (r - rowOffset <= rowSize || c - colOffset <= colSize) + if (r - rowOffset == crossRow && c - colOffset > 0 && c - colOffset <= colSize) || + (c - colOffset == crossCol && r - rowOffset > 0 && r - rowOffset <= rowSize) then if (r - rowOffset, c - colOffset) `elem` holes then Air else Wall