From 772bc2446aee7f8bbbde53acfb923cd483519b43 Mon Sep 17 00:00:00 2001 From: Arity-T Date: Sat, 7 Dec 2024 11:23:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=B4=D1=81=D1=87=D1=91=D1=82=D0=B0=20=D0=B6?= =?UTF-8?q?=D0=B8=D0=B2=D1=8B=D1=85=20=D0=BA=D0=BB=D0=B5=D1=82=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab1/CellularAutomaton.cpp | 16 ++++++++++++++++ lab1/CellularAutomaton.h | 2 ++ lab1/lab1.cpp | 2 ++ 3 files changed, 20 insertions(+) diff --git a/lab1/CellularAutomaton.cpp b/lab1/CellularAutomaton.cpp index 0a44b2b..6c6b53a 100644 --- a/lab1/CellularAutomaton.cpp +++ b/lab1/CellularAutomaton.cpp @@ -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; } \ No newline at end of file diff --git a/lab1/CellularAutomaton.h b/lab1/CellularAutomaton.h index b1bbf30..85063da 100644 --- a/lab1/CellularAutomaton.h +++ b/lab1/CellularAutomaton.h @@ -29,5 +29,7 @@ public: void update(); void displayField() const; + + int countLiveCells() const; }; diff --git a/lab1/lab1.cpp b/lab1/lab1.cpp index c00208f..5475b34 100644 --- a/lab1/lab1.cpp +++ b/lab1/lab1.cpp @@ -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, чтобы продолжить...";