Skip to main content

sac/life/
patterns.rs

1/// A predefined seed pattern for the Game of Life.
2#[derive(Clone, Copy, Debug)]
3pub struct SeedPattern {
4    /// Width of the pattern in cells.
5    pub width: usize,
6    /// Height of the pattern in cells.
7    pub height: usize,
8    /// Coordinates of live cells within the pattern bounds.
9    pub cells: &'static [(usize, usize)],
10}
11
12/// Placement configuration for injecting a pattern into the life field.
13#[derive(Clone, Copy, Debug)]
14pub struct PatternPlacement {
15    /// The pattern to place.
16    pub pattern: SeedPattern,
17    /// Horizontal offset from center (scaled by LIFE_LAYOUT_WIDTH_SCALE).
18    pub dx: isize,
19    /// Vertical offset from center.
20    pub dy: isize,
21    /// Rotation in 90-degree increments (0-3).
22    pub rotation: u8,
23    /// Whether to flip horizontally after rotation.
24    pub flip: bool,
25}
26
27/// The glider pattern - a small spaceship that moves diagonally.
28pub const GLIDER_PATTERN: SeedPattern = SeedPattern {
29    width: 3,
30    height: 3,
31    cells: &[(1, 0), (2, 1), (0, 2), (1, 2), (2, 2)],
32};
33
34/// The R-pentomino pattern - a small methuselah that evolves for many generations.
35pub const R_PENTOMINO_PATTERN: SeedPattern = SeedPattern {
36    width: 3,
37    height: 3,
38    cells: &[(1, 0), (2, 0), (0, 1), (1, 1), (1, 2)],
39};
40
41/// The acorn pattern - a methuselah that evolves for 5206 generations.
42pub const ACORN_PATTERN: SeedPattern = SeedPattern {
43    width: 7,
44    height: 3,
45    cells: &[(1, 0), (3, 1), (0, 2), (1, 2), (4, 2), (5, 2), (6, 2)],
46};
47
48/// The lightweight spaceship (LWSS) pattern - moves orthogonally.
49pub const LWSS_PATTERN: SeedPattern = SeedPattern {
50    width: 5,
51    height: 4,
52    cells: &[
53        (1, 0),
54        (2, 0),
55        (3, 0),
56        (4, 0),
57        (0, 1),
58        (4, 1),
59        (4, 2),
60        (0, 3),
61        (3, 3),
62    ],
63};
64
65/// Small random blob pattern (4x4) for variety
66pub const RANDOM_BLOB_4X4: SeedPattern = SeedPattern {
67    width: 4,
68    height: 4,
69    cells: &[
70        (1, 0),
71        (2, 0),
72        (0, 1),
73        (3, 1),
74        (1, 2),
75        (2, 2),
76        (0, 3),
77        (3, 3),
78    ],
79};
80
81/// Medium random blob pattern (5x5) for variety
82pub const RANDOM_BLOB_5X5: SeedPattern = SeedPattern {
83    width: 5,
84    height: 5,
85    cells: &[
86        (1, 0),
87        (3, 0),
88        (0, 1),
89        (2, 1),
90        (4, 1),
91        (1, 2),
92        (3, 2),
93        (0, 3),
94        (2, 3),
95        (4, 3),
96        (1, 4),
97        (3, 4),
98    ],
99};
100
101/// Large random blob pattern (6x6) for variety
102pub const RANDOM_BLOB_6X6: SeedPattern = SeedPattern {
103    width: 6,
104    height: 6,
105    cells: &[
106        (1, 0),
107        (4, 0),
108        (0, 1),
109        (2, 1),
110        (3, 1),
111        (5, 1),
112        (1, 2),
113        (4, 2),
114        (1, 3),
115        (4, 3),
116        (0, 4),
117        (2, 4),
118        (3, 4),
119        (5, 4),
120        (1, 5),
121        (4, 5),
122    ],
123};