From be18110c1dfc3815f7f3c6e0fd5bc5a74a51472e Mon Sep 17 00:00:00 2001 From: Martin Euzenat Date: Thu, 25 Jan 2024 00:34:59 -0500 Subject: [PATCH] =?UTF-8?q?set=20Pattern=20ne=20fonctionn=20que=20pour=20d?= =?UTF-8?q?es=20[XXxXX]=20et=20pas=20=20pour=20des=20[XxX]=20=C3=A0=20corr?= =?UTF-8?q?iger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GPA675Lab1GOL/GOLTeamH.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/GPA675Lab1GOL/GOLTeamH.cpp b/GPA675Lab1GOL/GOLTeamH.cpp index 68b6894..427b316 100644 --- a/GPA675Lab1GOL/GOLTeamH.cpp +++ b/GPA675Lab1GOL/GOLTeamH.cpp @@ -411,25 +411,21 @@ bool GOLTeamH::setFromPattern(std::string const& pattern) std::cerr << "Erreur de format : 'x' manquant." << std::endl; return false; } - pos++; // Lecture de la hauteur size_t height = std::stoi(pattern.substr(pos), &pos); + pos = pos + 4; if (height <= 0) { std::cerr << "Erreur de format : Hauteur invalide." << std::endl; return false; } - pos++; + // Vérification du ']' if (static_cast(pattern[pos++]) != ']') { std::cerr << "Erreur de format : ']' manquant." << std::endl; return false; } pos++; - // Vérification de la taille du reste du pattern - if (pattern.length() - pos != width * height) { - std::cerr << "Erreur de format : Taille du patron incorrecte." << std::endl; - return false; - } + size_t centerX = mData.width() / 2; size_t centerY = mData.height() / 2; @@ -437,6 +433,7 @@ bool GOLTeamH::setFromPattern(std::string const& pattern) for (size_t y = 0; y < height; ++y) { for (size_t x = 0; x < width; ++x) { char cellChar = pattern[pos++]; + mData.setAt(centerX + x, centerY + y, State::dead); State cellState = (cellChar == '0') ? State::dead : State::alive; mData.setAt(centerX + x, centerY + y, cellState); }