Prend en note la quantité de cellules mortes avant une étape.
This commit is contained in:
parent
baf6addabd
commit
2a865e134f
@ -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);
|
||||
}
|
||||
|
@ -3,12 +3,12 @@
|
||||
#define GOLTEAMH_H
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
|
||||
#include <GOL.h>
|
||||
#include "GridTeamH.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
// Fichier : GridTeam.h
|
||||
// GPA675 – Laboratoire 1
|
||||
@ -114,6 +114,7 @@ private:
|
||||
std::optional<sizeQueried> parsePattern(std::string const& pattern);
|
||||
void fillDataFromPattern(std::string const& pattern, sizeQueried& sq,
|
||||
int centerX, int centerY);
|
||||
void countLifeStatusCells();
|
||||
};
|
||||
|
||||
#endif GOLTEAMH_H
|
@ -2,14 +2,13 @@
|
||||
#ifndef GRIDTEAMH_H
|
||||
#define GRIDTEAMH_H
|
||||
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include "GOL.h"
|
||||
|
||||
// Fichier : GridTeam.h
|
||||
// GPA675 – Laboratoire 1
|
||||
// Création :
|
||||
// - A. Einstein
|
||||
// - Timothée Leclaire-Fournier
|
||||
// - 2024/01/17
|
||||
// - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Classe GridTeamH
|
||||
|
Loading…
Reference in New Issue
Block a user