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);
|
mData.resize(width, height, defaultState);
|
||||||
drawBorder();
|
drawBorder();
|
||||||
|
countLifeStatusCells();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Mutateur modifiant la règle de la simulation.
|
//! \brief Mutateur modifiant la règle de la simulation.
|
||||||
@ -218,6 +219,7 @@ void GOLTeamH::setBorderManagement(BorderManagement borderManagement)
|
|||||||
mBorderManagement = borderManagement;
|
mBorderManagement = borderManagement;
|
||||||
mIteration = 0;
|
mIteration = 0;
|
||||||
drawBorder();
|
drawBorder();
|
||||||
|
countLifeStatusCells();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GOLTeamH::drawBorder()
|
void GOLTeamH::drawBorder()
|
||||||
@ -251,6 +253,7 @@ void GOLTeamH::setState(int x, int y, State state)
|
|||||||
{
|
{
|
||||||
mData.setAt(x, y, state);
|
mData.setAt(x, y, state);
|
||||||
mIteration = 0;
|
mIteration = 0;
|
||||||
|
countLifeStatusCells();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Mutateur remplissant de façon uniforme toutes les cellules de
|
//! \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);
|
mData.fill(state, mBorderManagement == GOL::BorderManagement::immutableAsIs);
|
||||||
mIteration = 0;
|
mIteration = 0;
|
||||||
|
countLifeStatusCells();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Mutateur remplissant de façon alternée toutes les cellules de
|
//! \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);
|
mData.fillAternately(firstCell, mBorderManagement == GOL::BorderManagement::immutableAsIs);
|
||||||
mIteration = 0;
|
mIteration = 0;
|
||||||
|
countLifeStatusCells();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Mutateur remplissant de façon aléatoire toutes les cellules de
|
//! \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);
|
mData.randomize(percentAlive, mBorderManagement == GOL::BorderManagement::immutableAsIs);
|
||||||
mIteration = 0;
|
mIteration = 0;
|
||||||
|
countLifeStatusCells();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Mutateur remplissant la grille par le patron passé en argument.
|
//! \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);
|
fillDataFromPattern(pattern, sq.value(), centerX, centerY);
|
||||||
|
|
||||||
mIteration = 0;
|
mIteration = 0;
|
||||||
|
countLifeStatusCells();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,6 +365,7 @@ bool GOLTeamH::setFromPattern(std::string const& pattern)
|
|||||||
fillDataFromPattern(pattern, sq.value(), centerX, centerY);
|
fillDataFromPattern(pattern, sq.value(), centerX, centerY);
|
||||||
|
|
||||||
mIteration = 0;
|
mIteration = 0;
|
||||||
|
countLifeStatusCells();
|
||||||
return true;
|
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
|
#define GOLTEAMH_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include <GOL.h>
|
#include <GOL.h>
|
||||||
#include "GridTeamH.h"
|
#include "GridTeamH.h"
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
// Fichier : GridTeam.h
|
// Fichier : GridTeam.h
|
||||||
// GPA675 – Laboratoire 1
|
// GPA675 – Laboratoire 1
|
||||||
@ -114,6 +114,7 @@ private:
|
|||||||
std::optional<sizeQueried> parsePattern(std::string const& pattern);
|
std::optional<sizeQueried> parsePattern(std::string const& pattern);
|
||||||
void fillDataFromPattern(std::string const& pattern, sizeQueried& sq,
|
void fillDataFromPattern(std::string const& pattern, sizeQueried& sq,
|
||||||
int centerX, int centerY);
|
int centerX, int centerY);
|
||||||
|
void countLifeStatusCells();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif GOLTEAMH_H
|
#endif GOLTEAMH_H
|
@ -2,14 +2,13 @@
|
|||||||
#ifndef GRIDTEAMH_H
|
#ifndef GRIDTEAMH_H
|
||||||
#define GRIDTEAMH_H
|
#define GRIDTEAMH_H
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <random>
|
#include <random>
|
||||||
#include "GOL.h"
|
#include "GOL.h"
|
||||||
|
|
||||||
// Fichier : GridTeam.h
|
// Fichier : GridTeam.h
|
||||||
// GPA675 – Laboratoire 1
|
// GPA675 – Laboratoire 1
|
||||||
// Création :
|
// Création :
|
||||||
// - A. Einstein
|
// - Timothée Leclaire-Fournier
|
||||||
// - 2024/01/17
|
// - 2024/01/17
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
// Classe GridTeamH
|
// Classe GridTeamH
|
||||||
|
Loading…
Reference in New Issue
Block a user