pattern fixé test avec grille 25x25 et pattern 17x29. Le bug de mémoire peut apparaître pas trouvé l'occurence
This commit is contained in:
parent
da3d080a8f
commit
3208f27c07
@ -324,8 +324,7 @@ bool GOLTeamH::setFromPattern(std::string const& pattern, int centerX, int cente
|
|||||||
if (!sq.has_value())
|
if (!sq.has_value())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
fillDataFromPattern(pattern, sq.value(), centerX, centerY);
|
fillDataFromPattern(pattern, sq.value(), centerX+1, centerY+1);
|
||||||
mData.fill(State::dead, true);
|
|
||||||
|
|
||||||
mIteration = 0;
|
mIteration = 0;
|
||||||
countLifeStatusCells();
|
countLifeStatusCells();
|
||||||
@ -350,11 +349,12 @@ bool GOLTeamH::setFromPattern(std::string const& pattern)
|
|||||||
if (!sq.has_value())
|
if (!sq.has_value())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
size_t centerX = mData.width() / 2 - (sq.value().width / 2);
|
// Offset pour ajuster le centrage du pattern
|
||||||
size_t centerY = mData.height() / 2 - (sq.value().height / 2);
|
int centerX = (mData.width() - sq.value().width)/2;
|
||||||
|
int centerY = (mData.height() - sq.value().height)/2;
|
||||||
|
|
||||||
|
fillDataFromPattern(pattern, sq.value(),centerX+1, centerY+1);
|
||||||
|
|
||||||
fillDataFromPattern(pattern, sq.value(), centerX + 1, centerY + 1);
|
|
||||||
mData.fill(State::dead, true);
|
|
||||||
|
|
||||||
mIteration = 0;
|
mIteration = 0;
|
||||||
countLifeStatusCells();
|
countLifeStatusCells();
|
||||||
@ -557,19 +557,20 @@ std::optional<GOLTeamH::sizeQueried> GOLTeamH::parsePattern(std::string const& p
|
|||||||
void GOLTeamH::fillDataFromPattern(std::string const& pattern, sizeQueried& sq,
|
void GOLTeamH::fillDataFromPattern(std::string const& pattern, sizeQueried& sq,
|
||||||
int centerX, int centerY)
|
int centerX, int centerY)
|
||||||
{
|
{
|
||||||
|
mData.fill(State::dead, true);
|
||||||
// Remplissage de la grille aux positions spécifiées par le patron
|
// Remplissage de la grille aux positions spécifiées par le patron
|
||||||
for (size_t y = 0; y < sq.height; ++y) {
|
for (size_t y = 0; y < sq.height; ++y) {
|
||||||
for (size_t x = 0; x < sq.width; ++x) {
|
for (size_t x = 0; x < sq.width; ++x) {
|
||||||
// TODO: Check si in bounds et vérifie que ça répare le problème de quand on ferme, erreur.
|
// Coordonnées dans la grille de destination
|
||||||
if (centerX - sq.width / 2 + x <0
|
int destX = centerX + x;
|
||||||
|| centerX - sq.width / 2 + x > mData.width()
|
int destY = centerY + y;
|
||||||
|| centerY - sq.height / 2 + x <0
|
|
||||||
|| centerY - sq.height / 2 + x > mData.height()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
State cellState = (sq.pos[(y * sq.width) + x] == '0') ? State::dead : State::alive;
|
// Vérifier si les coordonnées sont dans la grille
|
||||||
mData.setAt(centerX + x, centerY + y, cellState);
|
if (destX >= 0 || destX < mData.width()-1 || destY >= 0 || destY < mData.height()-1) {
|
||||||
|
// On remplit la grille avec les valeurs du pattern
|
||||||
|
State cellState = (sq.pos[(y * sq.width) + x] == '0') ? State::dead : State::alive;
|
||||||
|
mData.setAt(destX, destY, cellState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include < algorithm >
|
||||||
|
|
||||||
#include <GOL.h>
|
#include <GOL.h>
|
||||||
#include "GridTeamH.h"
|
#include "GridTeamH.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user