diff --git a/src/simulation.cpp b/src/simulation.cpp index b077d0f..832af83 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -43,6 +43,10 @@ CellIterator::CellIterator(Cell begin, Cell end) CellIterator::CellIterator(Cell begin, Cell end, Cell state) : state{ state } , begin{ begin }, end{ end } {} +static inline bool CellIsAlive(Cell const &cell) { + return living.contains(cell); +} + CellIterator &CellIterator::operator++() { ++(this->state.x); if (this->state.x == this->end.x) { @@ -71,7 +75,7 @@ bool CellIterator::at_end() const { static size_t CountNeighbors(Cell const &cell) { size_t count{ 0 }; for (Cell const &c : CellRange{ {cell.x - 1, cell.y - 1}, { cell.x + 2, cell.y + 2} }) { - if (c != cell && living.contains(c)) { + if (c != cell && CellIsAlive(c)) { ++count; } } @@ -147,7 +151,7 @@ static void FindBorn(std::shared_ptr wl) { CellRange range{{ center.x - 1, center.y - 1 }, {center.x + 2, center.y + 2 }}; std::copy_if(range.begin(), range.end(), std::back_inserter(wl->changes), [&](Cell const &c) -> bool { - return !living.contains(c) && CountNeighbors(c) == 3; + return !CellIsAlive(c) && CountNeighbors(c) == 3; }); }); TaskComplete();