55void seed(Grid &g, std::uint32_t seed_value,
double p_alive)
57 std::mt19937
rng(seed_value);
58 std::uniform_real_distribution<double> u(0.0, 1.0);
61 g.set({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)},
62 u(
rng) < p_alive ? 1 : 0);
65void render(
const Grid &g, std::ostream &os)
70 os << (g.at({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)})
77bool grids_equal(
const Grid &a,
const Grid &b)
81 if (a.at({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)})
82 != b.at({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)}))
87std::size_t alive(
const Grid &g)
92 if (g.at({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)}) != 0)
99int main(
int argc,
char **argv)
101 std::size_t
steps = 1000;
103 std::uint32_t seed_value = 0xC0DEFEEDu;
107 steps =
static_cast<std::size_t
>(std::stoul(argv[1]));
109 side =
static_cast<ca_size_t>(std::stoul(argv[2]));
114 const unsigned long long s = std::stoull(argv[3],
nullptr, 0);
115 if (s > std::numeric_limits<std::uint32_t>::max())
116 throw std::out_of_range(
"seed");
117 seed_value =
static_cast<std::uint32_t
>(s);
120 catch (
const std::invalid_argument &)
122 std::cerr <<
"Invalid argument: expected non-negative integers for "
123 "[steps] [side] [seed]\n";
126 catch (
const std::out_of_range &)
128 std::cerr <<
"Argument out of range for [steps] [side] [seed]\n";
136 if (side < 2 or side % 2 != 0)
138 std::cerr <<
"Invalid side: " << side
139 <<
" (must be a positive even integer ≥ 2 for Margolus reversibility)\n";
143 Grid initial({side, side}, 0);
144 seed(initial, seed_value, 0.45);
145 Grid baseline = initial;
147 std::cout <<
"Critters reversible CA — " << side <<
"×" << side
148 <<
", " <<
steps <<
" steps, seed 0x" << std::hex << seed_value
149 << std::dec <<
"\n\n";
150 std::cout <<
"Initial frame (" << alive(initial) <<
" alive):\n";
151 render(initial, std::cout);
158 std::cout <<
"\nAfter forward(" <<
steps <<
") steps ("
159 << alive(
engine.frame()) <<
" alive):\n";
160 render(
engine.frame(), std::cout);
164 std::cout <<
"\nAfter backward(" <<
steps <<
") steps ("
165 << alive(
engine.frame()) <<
" alive):\n";
166 render(
engine.frame(), std::cout);
168 const bool ok = grids_equal(
engine.frame(), baseline);
169 std::cout <<
"\nReversibility check: "
170 << (ok ?
"PASS — bit-exact identity recovered"
171 :
"FAIL — recovered frame differs from initial")
Common typedefs and tag types for the Cellular Automata module.
Update-scheme aware engine.
Critters reversible CA block rule.
Lattice that adds boundary-aware access on top of a storage.
Placeholder neighbourhood for engines that drive block rules.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Main namespace for Aleph-w library functions.
Margolus 2×2 partition update for reversible CAs.
The lattice wraps around on every axis.
Phase 13 update-scheme aware engine.
Block-based local rules for Aleph::CA (Phase 13).
Cellular automata lattice with pluggable boundary policies.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).
Phase 13 update-scheme strategies for Aleph::CA.