| Crates.io | ca-rules |
| lib.rs | ca-rules |
| version | 0.3.5 |
| created_at | 2019-08-06 14:47:54.534804+00 |
| updated_at | 2023-03-18 04:13:56.193341+00 |
| description | Parsing rule strings of life-like cellular automata. |
| homepage | https://github.com/AlephAlpha/ca-rules |
| repository | https://github.com/AlephAlpha/ca-rules |
| max_upload_size | |
| id | 154547 |
| size | 73,439 |
Parsing rule strings of life-like and other cellular automata.
Currently the following rules are supported:
B3/S23.B2ci3ai4c8/S02ae3eijkq4iz5ar6i7e.MAPARYXfhZofugWaH7oaIDogBZofuhogOiAaIDogIAAgAAWaH7oaIDogGiA6ICAAIAAaIDogIAAgACAAIAAAAAAAA.B2/S34H.B2o3-o4m/S12m3o4m5H.MAPFgFoF2gXgH5oF4B+gH4A6AH.B2/S013V.MAPHmlphg.3457/357/5.For non-Generations rules, four different notations are supported:
B3/S23)23/3)MAPARYXfhZofugWaH7oaIDogBZofuhogOiAaIDogIAAgAAWaH7oaIDogGiA6ICAAIAAaIDogIAAgACAAIAAAAAAAA)For Generations rules, four different notations are supported:
B357/S3457/C5)3457/357/5)g5b357s3457)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.
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.