58struct Bays_B2_S34_Functor
60 template <
typename State>
61 [[nodiscard]]
constexpr State operator()(
const State ¤t,
62 const std::size_t alive)
const noexcept
64 const bool alive_now =
current != State{};
65 const bool next_alive = (alive_now
and (alive == 3 or alive == 4))
66 or (not alive_now
and alive == 2);
67 return next_alive ?
static_cast<State
>(1) : static_cast<State>(0);
73void print_offset_view(
const L &lat, std::size_t step)
75 std::size_t alive = 0;
77 for (
ca_size_t q = 0; q < lat.cols(); ++q)
78 if (lat.at_axial(
Hex_Axial{static_cast<ca_index_t>(q), static_cast<ca_index_t>(r)})
82 std::printf(
"\nStep %2zu alive=%zu\n", step, alive);
89 for (
ca_size_t q = 0; q < lat.cols(); ++q)
91 const auto v = lat.at_axial(
93 std::printf(
"%c ", v != 0 ?
'#' :
'.');
111 const Hex_Axial p{centre.
q + dq, centre.r + dr};
113 seed.set_axial(p, 1);
116 std::printf(
"Aleph::CA Phase-6 example: Bays' B2/S34 hex life on a 16x16 toroidal lattice\n");
117 print_offset_view(
seed, 0);
123 for (std::size_t s = 1; s <= 6; ++s)
126 print_offset_view(eng.frame(), s);
129 std::printf(
"\n--- TikZ render of step 6 ---\n");
132 return v != 0 ?
"black" :
"white";
Common typedefs and tag types for the Cellular Automata module.
Hexagonal lattice with axial accessors over a 2D storage.
Six-neighbour hex pattern in axial coordinates over a 2D lattice.
Rule whose next state depends on (current, alive_count).
Synchronous double-buffered engine.
void step()
Apply the rule to every cell once and swap buffers.
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
void render_hex_lattice_tikz(std::ostream &os, const Lattice &lat, Palette &&palette, double radius=0.5, bool pointy_top=true)
Render a hex frame as a stand-alone TikZ picture.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
constexpr ca_size_t hex_distance(Hex_Axial a, Hex_Axial b) noexcept
Hex distance between two axial coordinates.
decltype(auto) current(It &it) noexcept(current_is_noexcept< It >)
Current item of an iterator that is positioned on one.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Axial integer coordinates (q, r) of a hex cell.
The lattice wraps around on every axis.
Synchronous double-buffered engine for cellular automata.
Hexagonal lattice with axial / offset / cube coordinate conversions and a TikZ-compatible pixel mappi...
Neighborhoods catalogue for Aleph::CA.
Rule mechanisms for Aleph::CA.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).