import Control.Monad.State.Strict
import Control.Monad.ST
import qualified Data.Array.IArray as A
+import Data.Array.IArray ((!))
import qualified Data.Array.MArray as M
import Data.Array.ST
import Data.Maybe
simulateN (n - 1)
simulateOnce =
+ do updateGrove
+ growGrove
+ updateDirections
+ updateCount
+
+updateGrove :: GroveState ()
+updateGrove =
do grove <- gets currentGrove
proposalsInf <- gets proposalDirections
let proposals = take 4 proposalsInf
moveElves mPopulation
return mPopulation
modify' (\g -> g { currentGrove = newGrove})
- growGrove
- updateDirections
- updateCount
growGrove =
do grove <- gets currentGrove
where shiftBounds (b0, b1) (d0, d1) = (b0 ^+^ d0, b1 ^+^ d1)
emptyStrip :: Population -> (Position, Position) -> Bool
-emptyStrip grove strip = all isNothing $ fmap (grove A.!) $ range strip
+emptyStrip grove strip = all isNothing $ fmap (grove !) $ range strip
topStrip, bottomStrip, leftStrip, rightStrip :: (Position, Position) -> (Position, Position)
topStrip (V2 minX _minY, V2 maxX maxY) = (V2 minX maxY, V2 maxX maxY)
rightShrink = (V2 0 0, V2 -1 0)
countEmpty :: Population -> (Position, Position) -> Int
-countEmpty grove bounds = length $ filter isNothing $ fmap (grove A.!) cells
+countEmpty grove bounds = length $ filter isNothing $ fmap (grove !) cells
where cells = range bounds
-- Parse the input file