Ébauche de tendance.

This commit is contained in:
Timothée Leclaire-Fournier 2024-01-25 21:16:04 -05:00
parent 12c9c17874
commit e044a98359
3 changed files with 51 additions and 13 deletions

View File

@ -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);
}

View File

@ -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<float>(totalAlive()) / static_cast<float>(size());
}
size_t GridTeamH::lastGenDead() const
{
return (mWidth * mHeight) - mLastGenAliveCount;
}
float GridTeamH::lastGenDeadRel() const
{
return static_cast<float>(lastGenDead()) / static_cast<float>(size());
}
size_t GridTeamH::lastGenAlive() const
{
return mLastGenAliveCount;
}
float GridTeamH::lastGenAliveRel() const
{
return static_cast<float>(lastGenAlive()) / static_cast<float>(size());
}
int GridTeamH::tendencyAbs() const
{
return lastGenAlive() - totalAlive();
}
float GridTeamH::tendencyRel() const
{
return static_cast<float>(tendencyAbs()) / static_cast<float>(size());
}
void GridTeamH::fill(CellType value, bool fillBorder)
{
for (size_t i{ static_cast<size_t>(1) - fillBorder }; i < mWidth - (static_cast<size_t>(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;

View File

@ -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;