| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Text.RLE
Description
The RLE (run length encoded) format is a common way of representing patterns in life-like cellular automata. RLE files consist of three sections:
- Zero or more comment lines beginning with
# - A header of the form
x = [width], y = [height], rule = [rule].[width]and[height]are natural numbers, and[rule]is the rule the pattern is meant to be run in, such asB36/S23. The "rule" field is optional. - The content of the pattern.
brepresents a dead cell,orepresents a live cell, and$denotes the end of a row. A run of identical characters can be abbreviated with a number, e.g.4ois short foroooo(hence the name "run length encoded"). This section must be terminated by a!character.
A glider in the Game of Life could be represented like so:
#N glider x = 3, y = 3, rule = B3/S23 3o$2bo$bo!
See this LifeWiki article for more information.
Documentation
A string representing a cellular automaton, such as "B36/S23" or
"B3/S2-i34q".
parse :: Stream s Identity Char => s -> Maybe (Maybe Rule, Pattern) Source #
Parse an RLE file, returning a Rule (if it exists) and a Pattern.
The argument can be String, Text, or any other type with a Stream
instance.
Whitespace is allowed everywhere except
in the middle of a number or rulestring, and there need not be a
newline after the header. Also, text after the final ! character is
ignored.
printAll :: Maybe Rule -> [Pattern] -> IO () Source #
Convert a list of patterns into RLEs and print them. Example:
import qualified Text.RLE as RLE import Data.CA.List (withDimensions) main = RLE.printAll (Just "B3/S23") (withDimensions 4 4)
The program above will print the RLE of every possible pattern contained in a 4 by 4 square. This data can then be piped into another program such as apgsearch.