Forest fire: Difference between revisions
m
→{{header|Haskell}}: Dropped one (now redundant) import.
m (→{{header|Haskell}}: Dropped one (now redundant) import.) |
|||
Line 4,616:
=={{header|Haskell}}==
<lang haskell>import
import Data.List (tails, transpose)
import
data Cell
Line 4,625:
| Fire
deriving (Eq)
instance Show Cell where
show Empty = " "
show Tree = "T"
show Fire = "$"
randomCell :: IO Cell
randomCell = fmap ([Empty, Tree] !!) (randomRIO (0, 1) :: IO Int)
randomChance :: IO Double
randomChance = randomRIO (0, 1.0) :: IO Double
rim :: a -> [[a]] -> [[a]]
rim b = fmap (fb b) . (fb =<< rb)
where
fb =
rb = fst . unzip . zip (repeat b) . head
take3x3 :: [[a]] -> [[[a]]]
take3x3 = concatMap (transpose . fmap take3) . take3
where
take3 = init . init . takeWhile (not . null) . fmap (take 3) . tails
list2Mat :: Int -> [a] -> [[a]]
list2Mat n = takeWhile (not . null) . fmap (take n) . iterate (drop n)
evolveForest :: Int -> Int -> Int -> IO ()
evolveForest m n k = do
Line 4,672:
nfs >>= evolve (i + 1)
evolve 1 fs
main :: IO ()
main = evolveForest 6 50 3</lang>
|