fix map generation bug

This commit is contained in:
nek0 2023-12-07 12:51:35 +01:00
parent 61e19d3378
commit d92763fe09

View file

@ -21,7 +21,7 @@ generateMap
-> Int -- ^ Map's height -> Int -- ^ Map's height
-> IO Map -- ^ resulting Map -> IO Map -- ^ resulting Map
generateMap mapWidth mapHeight = do 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 divide 0 0 mapHeight mapWidth initMap
where where
divide :: Int -> Int -> Int -> Int -> Map -> IO Map divide :: Int -> Int -> Int -> Int -> Map -> IO Map
@ -39,7 +39,7 @@ generateMap mapWidth mapHeight = do
colHole2 <- randomRIO (crossCol + 1, colSize - 1) colHole2 <- randomRIO (crossCol + 1, colSize - 1)
-- determine all possible passages -- determine all possible passages
let holes = let allHoles =
[ (rowHole1, crossCol) [ (rowHole1, crossCol)
, (rowHole2, crossCol) , (rowHole2, crossCol)
, (crossRow, colHole1) , (crossRow, colHole1)
@ -47,14 +47,14 @@ generateMap mapWidth mapHeight = do
] ]
-- drop one of the passages randomly -- drop one of the passages randomly
-- randomDropIndex <- randomRIO (0, length allHoles - 1) randomDropIndex <- randomRIO (0, length allHoles - 1)
let -- randomDrop = allHoles !! randomDropIndex let randomDrop = allHoles !! randomDropIndex
-- holes = filter (/= randomDrop) allHoles holes = filter (/= randomDrop) allHoles
crossedMap = M.mapPos crossedMap = M.mapPos
(\(r, c) tile -> (\(r, c) tile ->
if (r - rowOffset == crossRow || c - colOffset == crossCol) && if (r - rowOffset == crossRow && c - colOffset > 0 && c - colOffset <= colSize) ||
(r - rowOffset <= rowSize || c - colOffset <= colSize) (c - colOffset == crossCol && r - rowOffset > 0 && r - rowOffset <= rowSize)
then if (r - rowOffset, c - colOffset) `elem` holes then if (r - rowOffset, c - colOffset) `elem` holes
then Air then Air
else Wall else Wall