#game-of-life #cellular-automata #parser

ca-rules

Parsing rule strings of life-like cellular automata

5 unstable releases

✓ Uses Rust 2018 edition

0.3.2 May 19, 2020
0.3.1 Dec 19, 2019
0.3.0 Sep 12, 2019
0.2.0 Sep 8, 2019
0.1.0 Aug 6, 2019

#46 in Parser tooling

36 downloads per month
Used in 2 crates (via rlifesrc-lib)

MIT license

65KB
1.5K SLoC

CA rules parsers

Travis (.org) Crates.io Docs.rs 中文

Parsing rule strings of life-like and other cellular automata.

Currently the following rules are supported:

For non-Generations rules, four different notations are supported:

For Generations rules, four different notations are supported:

  • B/S notation (B357/S3457/C5)
  • The notation used by Golly (3457/357/5)
  • The notation used by Catagolue (g5b357s3457)
  • MAP strings for non-isotropic rules (MAPARYBFxZpF38WaRd/aZZ//hZpF39pln/+aZZ//pZp/ukWaRd/aZZ//mmWf/6Waf7paZZ//pZp/umWaf7paZbplg/5)

Please refer to Life Wiki for detailed definitions and notations of these rule strings.

Usage

use ca_rules::ParseLife;

// Define a struct for your rule:
#[derive(Debug, Eq, PartialEq)]
struct Rule {
    b: Vec<u8>,
    s: Vec<u8>,
}

// Implement a parser trait for your rule:
// The choice of the trait depends on the type of rules you want to parse.
impl ParseLife for Rule {
    // Implement a function to construct the rule from b and s data:
    fn from_bs(b: Vec<u8>, s: Vec<u8>) -> Self {
        Rule { b, s }
    }
}

// Then you can parse a rule string:
let life = Rule::parse_rule("B3/S23").unwrap();
assert_eq!(
    life,
    Rule {
        b: vec![3],
        s: vec![2, 3],
    }
)

For details, please refer to the doc.

Dependencies

~0.6–1MB
~21K SLoC