about summary refs log tree commit diff
path: root/src/Xanthous/Generators/CaveAutomata.hs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-09-15T21·00-0400
committerGriffin Smith <root@gws.fyi>2019-09-15T21·30-0400
commit15895c69fe8f1415f45fe33f7b3d564f4239496e (patch)
tree61f3f5cf633e86f1cbdb51bce0b7c51d3b9dc6f5 /src/Xanthous/Generators/CaveAutomata.hs
parent2604341c2f3c7805f88422707e8ed08e45ecfa0b (diff)
Remove all but the largest region in caves
When generating cave levels, remove all but the largest contiguous
region from the resulting level.
Diffstat (limited to 'src/Xanthous/Generators/CaveAutomata.hs')
-rw-r--r--src/Xanthous/Generators/CaveAutomata.hs3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/Xanthous/Generators/CaveAutomata.hs b/src/Xanthous/Generators/CaveAutomata.hs
index fd4c68ddbe90..f1123abbd8f4 100644
--- a/src/Xanthous/Generators/CaveAutomata.hs
+++ b/src/Xanthous/Generators/CaveAutomata.hs
@@ -99,6 +99,9 @@ generate' params dims = do
   when (steps' > 0)
    $ for_ [0 .. pred steps'] . const $ stepAutomata cells dims params
   lift $ fillOuterEdgesM cells
+  -- Remove all but the largest contiguous region of unfilled space
+  (_: smallerRegions) <- lift $ regions @UArray . amap not <$> freeze cells
+  lift $ fillAllM (fold smallerRegions) cells
   pure cells
 
 stepAutomata :: forall s g. MCells s -> Dimensions -> Params -> CellM g s ()