about summary refs log tree commit diff
path: root/src/Xanthous/Generators/Util.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xanthous/Generators/Util.hs')
-rw-r--r--src/Xanthous/Generators/Util.hs13
1 files changed, 12 insertions, 1 deletions
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