Добавил функцию для подсчёта живых клеток
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -29,5 +29,7 @@ public:
|
||||
|
||||
void update();
|
||||
void displayField() const;
|
||||
|
||||
int countLiveCells() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -51,12 +51,14 @@ int main()
|
||||
|
||||
cout << "\nИтерация 0:\n";
|
||||
ca.displayField();
|
||||
//cout << ca.countLiveCells() << "\n";
|
||||
|
||||
for (int i = 0; i < iterationsCount; ++i)
|
||||
{
|
||||
cout << "\nИтерация " << i + 1 << ":\n";
|
||||
ca.update();
|
||||
ca.displayField();
|
||||
//cout << ca.countLiveCells() << "\n";
|
||||
}
|
||||
|
||||
cout << "\nНажмите на enter, чтобы продолжить...";
|
||||
|
||||
Reference in New Issue
Block a user