From e044a983594e198c6d3c263e3fe20037be41fdbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Leclaire-Fournier?= Date: Thu, 25 Jan 2024 21:16:04 -0500 Subject: [PATCH] =?UTF-8?q?=C3=89bauche=20de=20tendance.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GPA675Lab1GOL/GOLTeamH.cpp | 9 ++++---- GPA675Lab1GOL/GridTeamH.cpp | 41 ++++++++++++++++++++++++++++++++----- GPA675Lab1GOL/GridTeamH.h | 14 ++++++++++--- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/GPA675Lab1GOL/GOLTeamH.cpp b/GPA675Lab1GOL/GOLTeamH.cpp index 37bceef..d82afc1 100644 --- a/GPA675Lab1GOL/GOLTeamH.cpp +++ b/GPA675Lab1GOL/GOLTeamH.cpp @@ -44,9 +44,9 @@ GOL::Statistics GOLTeamH::statistics() const .totalDeadAbs = mData.totalDead(), .totalAliveAbs = mData.totalAlive(), .totalDeadRel = mData.totalDeadRel(), - .totalAliveRel = mData.totalAliveRel() - // .tendencyAbs = ..., - // .tendencyRel = ... + .totalAliveRel = mData.totalAliveRel(), + .tendencyAbs = mData.tendencyAbs(), + .tendencyRel = mData.tendencyRel() }); } @@ -284,7 +284,7 @@ void GOLTeamH::fill(State state) //! \param firstCell L'état de la première cellule. void GOLTeamH::fillAlternately(State firstCell) { - mData.fillAternately(firstCell, mBorderManagement == GOL::BorderManagement::immutableAsIs); + mData.fillAlternately(firstCell, mBorderManagement == GOL::BorderManagement::immutableAsIs); mIteration = 0; countLifeStatusCells(); } @@ -623,6 +623,5 @@ void GOLTeamH::countLifeStatusCells() } s_ptr++; } - mData.setAliveCount(aliveCount); } diff --git a/GPA675Lab1GOL/GridTeamH.cpp b/GPA675Lab1GOL/GridTeamH.cpp index ae52277..1809385 100644 --- a/GPA675Lab1GOL/GridTeamH.cpp +++ b/GPA675Lab1GOL/GridTeamH.cpp @@ -13,7 +13,8 @@ GridTeamH::GridTeamH() } GridTeamH::GridTeamH(size_t width, size_t height, CellType initValue) - :mWidth{ width }, mHeight{ height }, mEngine(mRandomDevice()), mDistribution(0.0, 1.0), mAliveCount{} + :mWidth{ width }, mHeight{ height }, mEngine(mRandomDevice()), mDistribution(0.0, 1.0) + , mAliveCount{}, mLastGenAliveCount{} , mData{}, mIntermediateData{} { resize(width, height, initValue); @@ -134,10 +135,10 @@ void GridTeamH::setAt(int column, int row, CellType value) void GridTeamH::setAliveCount(size_t aliveCount) { + mLastGenAliveCount = mAliveCount; mAliveCount = aliveCount; } - // Accesseur en lecture seule sur le "buffer" de la grille. GridTeamH::DataType const& GridTeamH::data() const { @@ -162,7 +163,7 @@ GridTeamH::DataType& GridTeamH::intData() size_t GridTeamH::totalDead() const { - return mAliveCount; + return (mWidth * mHeight) - mAliveCount; } float GridTeamH::totalDeadRel() const @@ -172,7 +173,7 @@ float GridTeamH::totalDeadRel() const size_t GridTeamH::totalAlive() const { - return (mWidth * mHeight) - mAliveCount; + return mAliveCount; } float GridTeamH::totalAliveRel() const @@ -180,6 +181,36 @@ float GridTeamH::totalAliveRel() const return static_cast(totalAlive()) / static_cast(size()); } +size_t GridTeamH::lastGenDead() const +{ + return (mWidth * mHeight) - mLastGenAliveCount; +} + +float GridTeamH::lastGenDeadRel() const +{ + return static_cast(lastGenDead()) / static_cast(size()); +} + +size_t GridTeamH::lastGenAlive() const +{ + return mLastGenAliveCount; +} + +float GridTeamH::lastGenAliveRel() const +{ + return static_cast(lastGenAlive()) / static_cast(size()); +} + +int GridTeamH::tendencyAbs() const +{ + return lastGenAlive() - totalAlive(); +} + +float GridTeamH::tendencyRel() const +{ + return static_cast(tendencyAbs()) / static_cast(size()); +} + void GridTeamH::fill(CellType value, bool fillBorder) { for (size_t i{ static_cast(1) - fillBorder }; i < mWidth - (static_cast(1) - fillBorder); i++) @@ -187,7 +218,7 @@ void GridTeamH::fill(CellType value, bool fillBorder) mData[i + (j * mWidth)] = value; } -void GridTeamH::fillAternately(CellType initValue, bool fillBorder) +void GridTeamH::fillAlternately(CellType initValue, bool fillBorder) { auto otherValue = (initValue == CellType::alive) ? CellType::dead : CellType::alive; diff --git a/GPA675Lab1GOL/GridTeamH.h b/GPA675Lab1GOL/GridTeamH.h index 9c2f119..53eef4e 100644 --- a/GPA675Lab1GOL/GridTeamH.h +++ b/GPA675Lab1GOL/GridTeamH.h @@ -42,7 +42,6 @@ public: size_t width() const { return mWidth; } size_t height() const { return mHeight; } size_t size() const { return mHeight * mWidth; } - size_t aliveCount() const { return mAliveCount; } void resize(size_t width, size_t height, CellType initValue = CellType{}); @@ -68,8 +67,17 @@ public: size_t totalAlive() const; float totalAliveRel() const; + size_t lastGenDead() const; + float lastGenDeadRel() const; + + size_t lastGenAlive() const; + float lastGenAliveRel() const; + + int tendencyAbs() const; + float tendencyRel() const; + void fill(CellType value, bool fillBorder); - void fillAternately(CellType initValue, bool fillBorder); + void fillAlternately(CellType initValue, bool fillBorder); void randomize(double percentAlive, bool fillBorder); void fillBorder(CellType value); @@ -80,7 +88,7 @@ public: private: DataType mData, mIntermediateData; - size_t mWidth, mHeight, mAliveCount; + size_t mWidth, mHeight, mAliveCount, mLastGenAliveCount; // Pour la génération de nombres aléatoires std::random_device mRandomDevice;