From 2a865e134f16e80f35804c62b59d27c0bd9b4eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Leclaire-Fournier?= Date: Thu, 25 Jan 2024 20:43:22 -0500 Subject: [PATCH] =?UTF-8?q?Prend=20en=20note=20la=20quantit=C3=A9=20de=20c?= =?UTF-8?q?ellules=20mortes=20avant=20une=20=C3=A9tape.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GPA675Lab1GOL/GOLTeamH.cpp | 23 +++++++++++++++++++++++ GPA675Lab1GOL/GOLTeamH.h | 5 +++-- GPA675Lab1GOL/GridTeamH.h | 3 +-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/GPA675Lab1GOL/GOLTeamH.cpp b/GPA675Lab1GOL/GOLTeamH.cpp index 39d1285..37bceef 100644 --- a/GPA675Lab1GOL/GOLTeamH.cpp +++ b/GPA675Lab1GOL/GOLTeamH.cpp @@ -101,6 +101,7 @@ void GOLTeamH::resize(size_t width, size_t height, State defaultState) { mData.resize(width, height, defaultState); drawBorder(); + countLifeStatusCells(); } //! \brief Mutateur modifiant la règle de la simulation. @@ -218,6 +219,7 @@ void GOLTeamH::setBorderManagement(BorderManagement borderManagement) mBorderManagement = borderManagement; mIteration = 0; drawBorder(); + countLifeStatusCells(); } void GOLTeamH::drawBorder() @@ -251,6 +253,7 @@ void GOLTeamH::setState(int x, int y, State state) { mData.setAt(x, y, state); mIteration = 0; + countLifeStatusCells(); } //! \brief Mutateur remplissant de façon uniforme toutes les cellules de @@ -266,6 +269,7 @@ void GOLTeamH::fill(State state) { mData.fill(state, mBorderManagement == GOL::BorderManagement::immutableAsIs); mIteration = 0; + countLifeStatusCells(); } //! \brief Mutateur remplissant de façon alternée toutes les cellules de @@ -282,6 +286,7 @@ void GOLTeamH::fillAlternately(State firstCell) { mData.fillAternately(firstCell, mBorderManagement == GOL::BorderManagement::immutableAsIs); mIteration = 0; + countLifeStatusCells(); } //! \brief Mutateur remplissant de façon aléatoire toutes les cellules de @@ -299,6 +304,7 @@ void GOLTeamH::randomize(double percentAlive) { mData.randomize(percentAlive, mBorderManagement == GOL::BorderManagement::immutableAsIs); mIteration = 0; + countLifeStatusCells(); } //! \brief Mutateur remplissant la grille par le patron passé en argument. @@ -331,6 +337,7 @@ bool GOLTeamH::setFromPattern(std::string const& pattern, int centerX, int cente fillDataFromPattern(pattern, sq.value(), centerX, centerY); mIteration = 0; + countLifeStatusCells(); return true; } @@ -358,6 +365,7 @@ bool GOLTeamH::setFromPattern(std::string const& pattern) fillDataFromPattern(pattern, sq.value(), centerX, centerY); mIteration = 0; + countLifeStatusCells(); return true; } @@ -603,3 +611,18 @@ void GOLTeamH::fillDataFromPattern(std::string const& pattern, sizeQueried& sq, } } } + +void GOLTeamH::countLifeStatusCells() +{ + size_t aliveCount{}; + auto* s_ptr{ mData.data() }, * e_ptr{ mData.data() + mData.size() }; + + while (s_ptr < e_ptr) { + if (*s_ptr == State::alive) { + aliveCount++; + } + s_ptr++; + } + + mData.setAliveCount(aliveCount); +} diff --git a/GPA675Lab1GOL/GOLTeamH.h b/GPA675Lab1GOL/GOLTeamH.h index c36e3af..fa4201f 100644 --- a/GPA675Lab1GOL/GOLTeamH.h +++ b/GPA675Lab1GOL/GOLTeamH.h @@ -3,12 +3,12 @@ #define GOLTEAMH_H +#include #include #include + #include #include "GridTeamH.h" -#include -#include // Fichier : GridTeam.h // GPA675 – Laboratoire 1 @@ -114,6 +114,7 @@ private: std::optional parsePattern(std::string const& pattern); void fillDataFromPattern(std::string const& pattern, sizeQueried& sq, int centerX, int centerY); + void countLifeStatusCells(); }; #endif GOLTEAMH_H \ No newline at end of file diff --git a/GPA675Lab1GOL/GridTeamH.h b/GPA675Lab1GOL/GridTeamH.h index 7f3e91d..e0a04f4 100644 --- a/GPA675Lab1GOL/GridTeamH.h +++ b/GPA675Lab1GOL/GridTeamH.h @@ -2,14 +2,13 @@ #ifndef GRIDTEAMH_H #define GRIDTEAMH_H -#include #include #include "GOL.h" // Fichier : GridTeam.h // GPA675 – Laboratoire 1 // Création : -// - A. Einstein +// - Timothée Leclaire-Fournier // - 2024/01/17 // - - - - - - - - - - - - - - - - - - - - - - - // Classe GridTeamH