Добавил функцию для подсчёта живых клеток

This commit is contained in:
2024-12-07 11:23:39 +03:00
parent a7043f4843
commit 772bc2446a
3 changed files with 20 additions and 0 deletions

View File

@@ -101,4 +101,20 @@ void CellularAutomaton::displayField() const
}
std::cout << '\n';
}
}
int CellularAutomaton::countLiveCells() const
{
int liveCount = 0;
for (const auto& row : m_field)
{
for (const auto& cell : row)
{
if (cell == 1)
{
++liveCount;
}
}
}
return liveCount;
}