about summary refs log tree commit diff
path: root/src/Xanthous/Generators
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xanthous/Generators')
-rw-r--r--src/Xanthous/Generators/CaveAutomata.hs1
-rw-r--r--src/Xanthous/Generators/Util.hs13
2 files changed, 13 insertions, 1 deletions
diff --git a/src/Xanthous/Generators/CaveAutomata.hs b/src/Xanthous/Generators/CaveAutomata.hs
index a2f0a165e3c1..fd4c68ddbe90 100644
--- a/src/Xanthous/Generators/CaveAutomata.hs
+++ b/src/Xanthous/Generators/CaveAutomata.hs
@@ -98,6 +98,7 @@ generate' params dims = do
   let steps' = params ^. steps
   when (steps' > 0)
    $ for_ [0 .. pred steps'] . const $ stepAutomata cells dims params
+  lift $ fillOuterEdgesM cells
   pure cells
 
 stepAutomata :: forall s g. MCells s -> Dimensions -> Params -> CellM g s ()
diff --git a/src/Xanthous/Generators/Util.hs b/src/Xanthous/Generators/Util.hs
index 47ee81b2931e..6a2d27839cf6 100644
--- a/src/Xanthous/Generators/Util.hs
+++ b/src/Xanthous/Generators/Util.hs
@@ -7,6 +7,7 @@ module Xanthous.Generators.Util
   , randInitialize
   , numAliveNeighborsM
   , numAliveNeighbors
+  , fillOuterEdgesM
   , cloneMArray
   , floodFill
   , regions
@@ -20,7 +21,7 @@ import Control.Monad.Random
 import Data.Monoid
 import Data.Foldable (Foldable, toList)
 --------------------------------------------------------------------------------
-import Xanthous.Util (foldlMapM', between)
+import Xanthous.Util (foldlMapM')
 import Xanthous.Data (Dimensions, width, height)
 --------------------------------------------------------------------------------
 
@@ -93,6 +94,16 @@ numAliveNeighbors cells (x, y) =
     neighborPositions :: [(Int, Int)]
     neighborPositions = [(i, j) | i <- [-1..1], j <- [-1..1], (i, j) /= (0, 0)]
 
+fillOuterEdgesM :: (MArray a Bool m, Ix i, Ix j) => a (i, j) Bool -> m ()
+fillOuterEdgesM arr = do
+  ((minX, minY), (maxX, maxY)) <- getBounds arr
+  for_ (range (minX, maxX)) $ \x -> do
+    writeArray arr (x, minY) True
+    writeArray arr (x, maxY) True
+  for_ (range (minY, maxY)) $ \y -> do
+    writeArray arr (minX, y) True
+    writeArray arr (maxX, y) True
+
 safeGet :: (IArray a e, Ix i) => a i e -> i -> Maybe e
 safeGet arr idx =
   let (minIdx, maxIdx) = bounds arr