about summary refs log tree commit diff
path: root/src/Xanthous/Generators/Util.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/Util.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/Util.hs')
-rw-r--r--src/Xanthous/Generators/Util.hs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/Xanthous/Generators/Util.hs b/src/Xanthous/Generators/Util.hs
index e399ca5d4936..8fd04c0b9326 100644
--- a/src/Xanthous/Generators/Util.hs
+++ b/src/Xanthous/Generators/Util.hs
@@ -11,15 +11,17 @@ module Xanthous.Generators.Util
   , cloneMArray
   , floodFill
   , regions
+  , fillAll
+  , fillAllM
   ) where
 --------------------------------------------------------------------------------
-import Xanthous.Prelude hiding (Foldable, toList)
+import Xanthous.Prelude hiding (Foldable, toList, for_)
 import Data.Array.ST
 import Data.Array.Unboxed
 import Control.Monad.ST
 import Control.Monad.Random
 import Data.Monoid
-import Data.Foldable (Foldable, toList)
+import Data.Foldable (Foldable, toList, for_)
 --------------------------------------------------------------------------------
 import Xanthous.Util (foldlMapM')
 import Xanthous.Data (Dimensions, width, height)
@@ -177,5 +179,8 @@ regions arr
     findFirstPoint :: a (i, j) Bool -> Maybe (i, j)
     findFirstPoint = fmap fst . headMay . filter snd . assocs
 
-    fillAll :: Foldable f => f (i, j) -> a (i, j) Bool -> a (i, j) Bool
-    fillAll ixes a = accum (const fst) a $ (, (False, ())) <$> toList ixes
+fillAll :: (IArray a Bool, Ix i, Foldable f) => f i -> a i Bool -> a i Bool
+fillAll ixes a = accum (const fst) a $ (, (False, ())) <$> toList ixes
+
+fillAllM :: (MArray a Bool m, Ix i, Foldable f) => f i -> a i Bool -> m ()
+fillAllM ixes a = for_ ixes $ \i -> writeArray a i False