37# include <initializer_list>
43# include <gtest/gtest.h>
60 using Cell = std::pair<ca_index_t, ca_index_t>;
62 std::set<Cell>
to_set(std::initializer_list<Cell> cells)
64 return std::set<Cell>(cells.begin(), cells.end());
68 std::initializer_list<Cell> alive)
71 for (
const auto & c : alive)
72 g.set({ c.first, c.second }, 1);
77 const std::vector<Cell> & alive)
80 for (
const auto & c : alive)
81 g.set({ c.first, c.second }, 1);
92 if (g.at({ i, j }) != 0)
99 Grid
nxt(
cur.extents(), 0);
102 std::array<int, Moore<2, 1>::size_v> buf { };
110 std::span<int>(buf.data(), buf.size()));
112 rule(
cur.at({ i, j }),
128 for (std::size_t t = 0; t < 20; ++t)
131 << name <<
" before step " << t;
136 << name <<
" after 20 steps";
142 Grid g({ 17, 17 }, 0);
144 const std::array<int, 4>
sparse_rows = {{ 0, 5, 7, 12 }};
145 const std::array<int, 6>
dense_cols = {{ 2, 3, 4, 8, 9, 10 }};
150 const std::array<int, 6>
dense_rows = {{ 2, 3, 4, 8, 9, 10 }};
151 const std::array<int, 4>
sparse_cols = {{ 0, 5, 7, 12 }};
160 return { { 1, 2 }, { 2, 3 }, { 3, 1 }, { 3, 2 }, { 3, 3 } };
163 std::set<Cell>
shifted(
const std::vector<Cell> & cells,
167 for (
const auto & c : cells)
168 out.
insert({ c.first + dr, c.second + dc });
176 make_grid(5, 5, { { 2, 1 }, { 2, 2 }, { 2, 3 } }),
179 make_grid(6, 6, { { 2, 2 }, { 2, 3 }, { 2, 4 },
180 { 3, 1 }, { 3, 2 }, { 3, 3 } }),
183 make_grid(6, 6, { { 1, 1 }, { 1, 2 }, { 2, 1 }, { 2, 2 },
184 { 3, 3 }, { 3, 4 }, { 4, 3 }, { 4, 4 } }),
195 make_grid(5, 5, { { 2, 1 }, { 2, 2 }, { 2, 3 } }));
197 make_grid(6, 6, { { 2, 2 }, { 2, 3 }, { 2, 4 },
198 { 3, 1 }, { 3, 2 }, { 3, 3 } }));
200 make_grid(6, 6, { { 1, 1 }, { 1, 2 }, { 2, 1 }, { 2, 2 },
201 { 3, 3 }, { 3, 4 }, { 4, 3 }, { 4, 4 } }));
205 const auto toad0 =
to_set({ { 2, 2 }, { 2, 3 }, { 2, 4 },
206 { 3, 1 }, { 3, 2 }, { 3, 3 } });
207 const auto toad1 =
to_set({ { 1, 3 }, { 2, 1 }, { 2, 4 },
208 { 3, 1 }, { 3, 4 }, { 4, 2 } });
209 const auto beacon0 =
to_set({ { 1, 1 }, { 1, 2 }, { 2, 1 }, { 2, 2 },
210 { 3, 3 }, { 3, 4 }, { 4, 3 }, { 4, 4 } });
212 { 3, 4 }, { 4, 3 }, { 4, 4 } });
214 for (std::size_t t = 0; t <= 20; ++t)
217 <<
"blinker t=" << t;
236 for (std::size_t t = 0; t <= 20; ++t)
240 const auto d =
static_cast<ca_index_t>(t / 4);
254 for (std::size_t t = 1; t <= 20; ++t)
266 make_grid(5, 5, { { 2, 1 }, { 2, 2 }, { 2, 3 } }));
272 engine.on_pre_step([&](std::size_t step,
const Grid & frame)
277 engine.on_post_step([&](std::size_t step,
const Grid & frame)
305 for (std::size_t t = 0; t <= 20; ++t)
size_t size_t int32_t * out
Convenience builders for the Phase 3 synchronous engine.
Common typedefs and tag types for the Cellular Automata module.
Lattice that adds boundary-aware access on top of a storage.
Moore (Chebyshev) neighborhood of radius R in N dimensions.
Synchronous double-buffered engine.
Minimal std::expected-style result type for C++20.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
const long double offset[]
Offset values indexed by symbol string length (bounded by MAX_OFFSET_INDEX)
Wolfram_1D_Engine make_wolfram_engine(std::uint8_t rule_no, ca_size_t width)
Build a 1D elementary Wolfram engine of the given width.
constexpr Game_Of_Life_Rule make_game_of_life_rule() noexcept
Build the canonical Game of Life rule.
std::span< const T > Neighbor_View
Read-only view over a contiguous range of neighbour values.
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
std::array< ca_index_t, N > Coord_Vec
Default coordinate vector.
void gather_neighbors(const Nbh &nh, const L &lat, const typename L::coord_type ¢er, std::span< T > out)
Populate out[0..nh.size()) with neighbour values of center.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
std::set< typename C::Item_Type > to_set(const C &c)
Convert a container to a std::set.
Iterate the lattice in column-major (Fortran) order.
Out-of-range neighbours behave as if the lattice ended.
Iterate a 2D lattice in W x H tiles.
Synchronous double-buffered engine for cellular automata.
Cellular automata lattice with pluggable boundary policies.
Neighborhoods catalogue for Aleph::CA.
Rule mechanisms for Aleph::CA.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).