première ébauche de wrapping, BordermangementType created in Grid + setAt + value+ at + setAt modified to match with bordermanagement rules; switch logic can maybe be used
This commit is contained in:
parent
57b7560a46
commit
85148b59e5
@ -232,10 +232,10 @@ void GOLTeamH::drawBorder()
|
||||
mData.fillBorder(GridTeamH::CellType::alive);
|
||||
break;
|
||||
case GOL::BorderManagement::warping:
|
||||
mData.fillBorderWarped();
|
||||
mData.setBorderManagement(GridTeamH::BorderManagement::Warpping);
|
||||
break;
|
||||
case GOL::BorderManagement::mirror:
|
||||
mData.fillBorderMirror();
|
||||
mData.setBorderManagement(GridTeamH::BorderManagement::Mirror);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -478,7 +478,7 @@ void GOLTeamH::processOneStep()
|
||||
ptrGrid = nullptr;
|
||||
ptrGridInt = nullptr;
|
||||
|
||||
mData.switchToIntermediate();
|
||||
mData.switchToIntermediate(); //mise à jour de la grille
|
||||
mIteration.value()++;
|
||||
mData.setAliveCount(aliveCount);
|
||||
}
|
||||
|
@ -17,6 +17,9 @@
|
||||
// - 2024/01/17
|
||||
// - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Classe GOLTeamH
|
||||
//
|
||||
// Cette classe nosu permet de créer et de manipuler un jeu de la vie.
|
||||
// Elle se base sur l'utilisation de la classe GridTeamH afin de gérer les mouvement dans la grid
|
||||
// - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
constexpr unsigned char MAX_ALPHA = 255;
|
||||
|
@ -8,14 +8,14 @@
|
||||
|
||||
// Constructeur Grid par défaut
|
||||
GridTeamH::GridTeamH()
|
||||
: GridTeamH(100, 100, CellType::dead)
|
||||
: GridTeamH(100, 100, CellType::dead,Classic)
|
||||
{
|
||||
}
|
||||
|
||||
GridTeamH::GridTeamH(size_t width, size_t height, CellType initValue)
|
||||
GridTeamH::GridTeamH(size_t width, size_t height, CellType initValue, BorderManagement borderType)
|
||||
:mWidth{ width }, mHeight{ height }, mEngine(mRandomDevice()), mDistribution(0.0, 1.0)
|
||||
, mAliveCount{}, mLastGenAliveCount{}
|
||||
, mData{}, mIntermediateData{}
|
||||
, mData{}, mIntermediateData{}, mBorderType{ Classic }
|
||||
{
|
||||
resize(width, height, initValue);
|
||||
}
|
||||
@ -95,6 +95,7 @@ void GridTeamH::resize(size_t width, size_t height, CellType initValue)
|
||||
fill(initValue, true);
|
||||
}
|
||||
|
||||
|
||||
void GridTeamH::dealloc()
|
||||
{
|
||||
if (mData && mIntermediateData) {
|
||||
@ -108,32 +109,75 @@ void GridTeamH::dealloc()
|
||||
// Accesseur retournant la valeur d'une cellule à une certaine coordonnée.
|
||||
GridTeamH::CellType GridTeamH::value(int column, int row) const
|
||||
{
|
||||
if (mBorderType == Warpping) {
|
||||
return mData[(static_cast<unsigned long long>(row) + mHeight) % mHeight * mWidth + (static_cast<unsigned long long>(column) + mWidth) % mWidth];
|
||||
|
||||
}
|
||||
else if (mBorderType == Mirror) {
|
||||
|
||||
}
|
||||
else if (mBorderType == Classic) {
|
||||
return mData[(static_cast<unsigned long long>(row) - 1) * mWidth + (static_cast<unsigned long long>(column) - 1)];
|
||||
}
|
||||
}
|
||||
|
||||
// Mutateur modifiant la valeur d'une cellule à une certaine coordonnée.
|
||||
void GridTeamH::setValue(int column, int row, CellType value)
|
||||
{
|
||||
if(mBorderType== Warpping){
|
||||
mData[(static_cast<unsigned long long>(row) + mHeight) % mHeight * mWidth + (static_cast<unsigned long long>(column) + mWidth) % mWidth]= value;
|
||||
|
||||
}
|
||||
else if(mBorderType== Mirror){
|
||||
|
||||
}
|
||||
else if(mBorderType== Classic){
|
||||
|
||||
mData[(static_cast<unsigned long long>(row) - 1) * mWidth + (static_cast<unsigned long long>(column) - 1)] = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Accesseur retournant la valeur d'une cellule à une certaine coordonnée.
|
||||
std::optional<GridTeamH::CellType> GridTeamH::at(int column, int row) const
|
||||
{
|
||||
if (mBorderType == Warpping) {
|
||||
// Logique de gestion des bords toroïdaux
|
||||
column = (column + mWidth) % mWidth;
|
||||
row = (row + mHeight) % mHeight;
|
||||
}
|
||||
else if (mBorderType == Mirror) {
|
||||
|
||||
}
|
||||
else if (mBorderType == Classic) {
|
||||
if (column >= mWidth || row >= mHeight)
|
||||
return std::nullopt;
|
||||
|
||||
return mData[(row - 1) * mWidth + (column - 1)];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Mutateur modifiant la valeur d'une cellule à une certaine coordonnée.
|
||||
void GridTeamH::setAt(int column, int row, CellType value)
|
||||
{
|
||||
if (mBorderType == Warpping) {
|
||||
// Logique de gestion des bords toroïdaux
|
||||
column = (column + mWidth) % mWidth;
|
||||
row = (row + mHeight) % mHeight;
|
||||
mData[(static_cast<unsigned long long>(row) + mHeight) % mHeight * mWidth + (static_cast<unsigned long long>(column) + mWidth) % mWidth] = value;
|
||||
}
|
||||
else if (mBorderType == Mirror) {
|
||||
|
||||
}
|
||||
else if (mBorderType == Classic) {
|
||||
if (column > mWidth || row > mHeight)
|
||||
return;
|
||||
|
||||
mData[(static_cast<unsigned long long>(row) - 1) * mWidth + (static_cast<unsigned long long>(column) - 1)] = value;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void GridTeamH::setAliveCount(size_t aliveCount)
|
||||
@ -276,6 +320,7 @@ void GridTeamH::fillBorderManipulations(DataType ptr, CellType value) const
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
void GridTeamH::fillBorderWarped()
|
||||
{
|
||||
|
||||
@ -293,6 +338,7 @@ void GridTeamH::switchToIntermediate()
|
||||
auto* temp{ mData };
|
||||
mData = mIntermediateData;
|
||||
mIntermediateData = temp;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
// La classe point représente une grille dans l’espace 2d des réels.
|
||||
// Deux tableaux sont utilisés, un réel et un intermédiaire.
|
||||
//Elle comporte des méthodes pour manipuler les cellules de la grille et en sortir des statstiques.
|
||||
|
||||
class GridTeamH
|
||||
{
|
||||
@ -27,9 +28,15 @@ public:
|
||||
using CellType = GOL::State;
|
||||
using DataType = CellType*;
|
||||
|
||||
enum BorderManagement {
|
||||
Warpping,
|
||||
Classic,
|
||||
Mirror,
|
||||
};
|
||||
|
||||
// Définition des constructeurs / destructeur
|
||||
GridTeamH();
|
||||
GridTeamH(size_t width, size_t height, CellType initValue = CellType{});
|
||||
GridTeamH(size_t width, size_t height, CellType initValue = CellType{}, BorderManagement borderType = Classic);
|
||||
|
||||
GridTeamH(GridTeamH const&);
|
||||
GridTeamH(GridTeamH&&) noexcept;
|
||||
@ -53,7 +60,7 @@ public:
|
||||
void setAt(int column, int row, CellType value);
|
||||
|
||||
void setAliveCount(size_t aliveCount);
|
||||
|
||||
void setBorderManagement(BorderManagement borderType) { mBorderType = borderType; }
|
||||
// Accesseurs du "buffer" de la grille
|
||||
DataType const& data() const;
|
||||
DataType& data();
|
||||
@ -61,6 +68,7 @@ public:
|
||||
DataType const& intData() const;
|
||||
DataType& intData();
|
||||
|
||||
//méthode pour les statistiques
|
||||
size_t totalDead() const;
|
||||
float totalDeadRel() const;
|
||||
|
||||
@ -76,25 +84,31 @@ public:
|
||||
int tendencyAbs() const;
|
||||
float tendencyRel() const;
|
||||
|
||||
//Méthode de remplissage
|
||||
void fill(CellType value, bool fillBorder);
|
||||
void fillAlternately(CellType initValue, bool fillBorder);
|
||||
void randomize(double percentAlive, bool fillBorder);
|
||||
|
||||
//Méthode de gestion de bordure
|
||||
void fillBorder(CellType value);
|
||||
void fillBorderWarped();
|
||||
void fillBorderMirror();
|
||||
|
||||
//Alternance entre les deux grilles
|
||||
void switchToIntermediate();
|
||||
|
||||
private:
|
||||
DataType mData, mIntermediateData;
|
||||
size_t mWidth, mHeight, mAliveCount, mLastGenAliveCount;
|
||||
|
||||
BorderManagement mBorderType;
|
||||
|
||||
// Pour la génération de nombres aléatoires
|
||||
std::random_device mRandomDevice;
|
||||
std::mt19937 mEngine;
|
||||
std::uniform_real_distribution<> mDistribution;
|
||||
|
||||
// Méthodes utilisées en interne
|
||||
void fillBorderManipulations(DataType ptr, CellType value) const;
|
||||
void dealloc();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user