diff --git a/Hw6/LifeSimulator.cpp b/Hw6/LifeSimulator.cpp index 5491368..a9fe101 100644 --- a/Hw6/LifeSimulator.cpp +++ b/Hw6/LifeSimulator.cpp @@ -6,8 +6,8 @@ LifeSimulator::LifeSimulator(std::uint8_t sizeX, std::uint8_t sizeY) : // Initializing vectors with padding for easy searches for (std::uint8_t i = 0; i < sizeY + 2; i++) { - currentScreen.push_back(std::vector()); - nextScreen.push_back(std::vector()); + currentScreen.emplace_back(); + nextScreen.emplace_back(); for (std::uint8_t j = 0; j < sizeX + 2; j++) { currentScreen[i].push_back(false); @@ -18,15 +18,15 @@ LifeSimulator::LifeSimulator(std::uint8_t sizeX, std::uint8_t sizeY) : void LifeSimulator::insertPattern(const Pattern& pattern, std::uint8_t startX, std::uint8_t startY) { - // Adding offset for padded borders startX += 1; startY += 1; - - if ((pattern.getSizeY() + startY) <= (currentScreen.size() - 1) && (pattern.getSizeX() + startX) <= (currentScreen[0].size() - 1)) + std::cout << pattern.getCell(0, 0) << std::endl; + if (((currentScreen.size() - 1) >= pattern.getSizeY() + startY) && + (pattern.getSizeX() + startX) <= (currentScreen[0].size() - 1)) { - for (int y = 0; y < pattern.getSizeY(); y++) + for (std::uint8_t y = 0; y < pattern.getSizeY(); y++) { - for (int x = 0; x < pattern.getSizeX(); x++) + for (std::uint8_t x = 0; x < pattern.getSizeX(); x++) { if (pattern.getCell(x, y)) { @@ -51,32 +51,23 @@ void LifeSimulator::update() nextScreen[i][j] = false; } } - // For loop to update nextScreen vector + for (int i = 1; i < currentScreen.size() - 1; i++) { for (int j = 1; j < currentScreen[0].size() - 1; j++) { - // Checking each pixel - int count = 0; + int liveCount = 0; for (int y = -1; y < 2; y++) { for (int x = -1; x < 2; x++) { - if (y == 0 && x == 0) - ; - else - { + if (!(y == 0 && x == 0)) if (currentScreen[i + y][j + x]) - count++; - } + liveCount++; } } - /* - * Any live cell with two or three live neighbours lives on to the next generation. - * Any live cell with more than three live neighbours dies, as if by overpopulation. - * Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. - */ - if (count > 1 && count < 4) + + if (liveCount > 1 && liveCount < 4) { if (currentScreen[i][j]) { @@ -84,7 +75,7 @@ void LifeSimulator::update() } else { - if (count == 3) + if (liveCount == 3) { nextScreen[i][j] = true; } diff --git a/Hw6/LifeSimulator.hpp b/Hw6/LifeSimulator.hpp index ae8e112..c3d5347 100644 --- a/Hw6/LifeSimulator.hpp +++ b/Hw6/LifeSimulator.hpp @@ -21,9 +21,9 @@ class LifeSimulator void insertPattern(const Pattern& pattern, std::uint8_t startX, std::uint8_t startY); void update(); - std::uint8_t getSizeX() const { return sizeX; }; - std::uint8_t getSizeY() const { return sizeY; }; - bool getCell(std::uint8_t x, std::uint8_t y) const { return currentScreen[y + 1][x + 1]; }; + [[nodiscard]] std::uint8_t getSizeX() const { return sizeX; }; + [[nodiscard]] std::uint8_t getSizeY() const { return sizeY; }; + [[nodiscard]] bool getCell(std::uint8_t x, std::uint8_t y) const { return currentScreen[y + 1][x + 1]; }; ; }; diff --git a/Hw6/Pattern.hpp b/Hw6/Pattern.hpp index 4320751..fff8419 100644 --- a/Hw6/Pattern.hpp +++ b/Hw6/Pattern.hpp @@ -15,9 +15,9 @@ class Pattern { public: - virtual std::uint8_t getSizeX() const = 0; - virtual std::uint8_t getSizeY() const = 0; - virtual bool getCell(std::uint8_t x, std::uint8_t y) const = 0; + [[nodiscard]] virtual std::uint8_t getSizeX() const = 0; + [[nodiscard]] virtual std::uint8_t getSizeY() const = 0; + [[nodiscard]] virtual bool getCell(std::uint8_t x, std::uint8_t y) const = 0; }; #endif //CS3460_CPP_PATTERN_HPP diff --git a/Hw6/PatternAcorn.hpp b/Hw6/PatternAcorn.hpp index 59c1058..13f0269 100644 --- a/Hw6/PatternAcorn.hpp +++ b/Hw6/PatternAcorn.hpp @@ -12,19 +12,19 @@ class PatternAcorn : public Pattern private: std::uint8_t X; std::uint8_t Y; - std::array, 4> cells; + std::array, 4> cells{}; public: PatternAcorn(); - std::uint8_t getSizeX() const + [[nodiscard]] std::uint8_t getSizeX() const override { return X; }; - std::uint8_t getSizeY() const + [[nodiscard]] std::uint8_t getSizeY() const override { return Y; }; - bool getCell(std::uint8_t x, std::uint8_t y) const + [[nodiscard]] bool getCell(std::uint8_t x, std::uint8_t y) const override { return cells[x][y]; }; diff --git a/Hw6/PatternBlinker.hpp b/Hw6/PatternBlinker.hpp index 68a7b31..ead61ec 100644 --- a/Hw6/PatternBlinker.hpp +++ b/Hw6/PatternBlinker.hpp @@ -10,18 +10,24 @@ class PatternBlinker : public Pattern { private: - uint8_t X; - uint8_t Y; - std::array, 5> cells; + std::uint8_t X; + std::uint8_t Y; + std::array, 5> cells{}; public: PatternBlinker(); - - std::uint8_t getSizeX() const { return X; }; - - std::uint8_t getSizeY() const { return Y; }; - - bool getCell(std::uint8_t x, std::uint8_t y) const { return cells[y][x]; }; + [[nodiscard]] std::uint8_t getSizeX() const override + { + return X; + }; + [[nodiscard]] std::uint8_t getSizeY() const override + { + return Y; + }; + [[nodiscard]] bool getCell(std::uint8_t x, std::uint8_t y) const override + { + return cells[x][y]; + }; }; #endif //CS3460_CPP_PATTERNBLINKER_HPP diff --git a/Hw6/PatternBlock.hpp b/Hw6/PatternBlock.hpp index 68ea41f..70c4e3a 100644 --- a/Hw6/PatternBlock.hpp +++ b/Hw6/PatternBlock.hpp @@ -11,19 +11,19 @@ class PatternBlock : public Pattern private: std::uint8_t X; std::uint8_t Y; - std::array, 4> cells; + std::array, 4> cells{}; public: PatternBlock(); - std::uint8_t getSizeX() const + [[nodiscard]] std::uint8_t getSizeX() const override { return X; }; - std::uint8_t getSizeY() const + [[nodiscard]] std::uint8_t getSizeY() const override { return Y; }; - bool getCell(std::uint8_t x, std::uint8_t y) const + [[nodiscard]] bool getCell(std::uint8_t x, std::uint8_t y) const override { return cells[x][y]; }; diff --git a/Hw6/PatternGlider.cpp b/Hw6/PatternGlider.cpp index 5423781..c674653 100644 --- a/Hw6/PatternGlider.cpp +++ b/Hw6/PatternGlider.cpp @@ -14,10 +14,9 @@ PatternGlider::PatternGlider() : cells[i][j] = false; } } - - cells[3][1]; - cells[3][2]; - cells[3][3]; - cells[2][3]; - cells[1][2]; + cells[1][2] = true; + cells[2][3] = true; + cells[3][1] = true; + cells[3][2] = true; + cells[3][3] = true; } \ No newline at end of file diff --git a/Hw6/PatternGlider.hpp b/Hw6/PatternGlider.hpp index eafc179..f707924 100644 --- a/Hw6/PatternGlider.hpp +++ b/Hw6/PatternGlider.hpp @@ -7,26 +7,24 @@ #include "Pattern.hpp" -#include - class PatternGlider : public Pattern { private: std::uint8_t X; std::uint8_t Y; - std::array, 5> cells; + std::array, 5> cells{}; public: PatternGlider(); - std::uint8_t getSizeX() const + [[nodiscard]] std::uint8_t getSizeX() const override { return X; }; - std::uint8_t getSizeY() const + [[nodiscard]] std::uint8_t getSizeY() const override { return Y; }; - bool getCell(std::uint8_t x, std::uint8_t y) const + [[nodiscard]] bool getCell(std::uint8_t x, std::uint8_t y) const override { return cells[x][y]; }; diff --git a/Hw6/PatternGosperGliderGun.hpp b/Hw6/PatternGosperGliderGun.hpp index 8a6885b..71900c4 100644 --- a/Hw6/PatternGosperGliderGun.hpp +++ b/Hw6/PatternGosperGliderGun.hpp @@ -12,19 +12,19 @@ class PatternGosperGliderGun : public Pattern private: std::uint8_t X; std::uint8_t Y; - std::array, 11> cells; + std::array, 4> cells{}; public: PatternGosperGliderGun(); - std::uint8_t getSizeX() const + [[nodiscard]] std::uint8_t getSizeX() const override { return X; }; - std::uint8_t getSizeY() const + [[nodiscard]] std::uint8_t getSizeY() const override { return Y; }; - bool getCell(std::uint8_t x, std::uint8_t y) const + [[nodiscard]] bool getCell(std::uint8_t x, std::uint8_t y) const override { return cells[x][y]; }; diff --git a/Hw6/RendererConsole.cpp b/Hw6/RendererConsole.cpp index 429c3ca..6058e3b 100644 --- a/Hw6/RendererConsole.cpp +++ b/Hw6/RendererConsole.cpp @@ -22,5 +22,5 @@ void RendererConsole::render(const LifeSimulator& simulation) } } } - rlutil::showcursor(); + //rlutil::showcursor(); } \ No newline at end of file diff --git a/Hw6/build/CMakeFiles/ConwaysLife.dir/CXX.includecache b/Hw6/build/CMakeFiles/ConwaysLife.dir/CXX.includecache index 2686d45..6d988e2 100644 --- a/Hw6/build/CMakeFiles/ConwaysLife.dir/CXX.includecache +++ b/Hw6/build/CMakeFiles/ConwaysLife.dir/CXX.includecache @@ -57,8 +57,6 @@ PatternGlider.hpp /Users/bradybodily/Repositories/CS3460/Hw6/PatternGlider.hpp Pattern.hpp /Users/bradybodily/Repositories/CS3460/Hw6/Pattern.hpp -array -- /Users/bradybodily/Repositories/CS3460/Hw6/PatternGosperGliderGun.cpp PatternGosperGliderGun.hpp diff --git a/Hw6/build/CMakeFiles/ConwaysLife.dir/LifeSimulator.cpp.o b/Hw6/build/CMakeFiles/ConwaysLife.dir/LifeSimulator.cpp.o index f0f848a..2d6c032 100644 Binary files a/Hw6/build/CMakeFiles/ConwaysLife.dir/LifeSimulator.cpp.o and b/Hw6/build/CMakeFiles/ConwaysLife.dir/LifeSimulator.cpp.o differ diff --git a/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternAcorn.cpp.o b/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternAcorn.cpp.o index 6519bde..8d917b1 100644 Binary files a/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternAcorn.cpp.o and b/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternAcorn.cpp.o differ diff --git a/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternBlinker.cpp.o b/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternBlinker.cpp.o index 28a7c6a..8092074 100644 Binary files a/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternBlinker.cpp.o and b/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternBlinker.cpp.o differ diff --git a/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternBlock.cpp.o b/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternBlock.cpp.o index b9b944c..1c7d1c3 100644 Binary files a/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternBlock.cpp.o and b/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternBlock.cpp.o differ diff --git a/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternGlider.cpp.o b/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternGlider.cpp.o index cdcb61e..8ff969f 100644 Binary files a/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternGlider.cpp.o and b/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternGlider.cpp.o differ diff --git a/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternGosperGliderGun.cpp.o b/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternGosperGliderGun.cpp.o index 7ad976e..489ff15 100644 Binary files a/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternGosperGliderGun.cpp.o and b/Hw6/build/CMakeFiles/ConwaysLife.dir/PatternGosperGliderGun.cpp.o differ diff --git a/Hw6/build/CMakeFiles/ConwaysLife.dir/RendererConsole.cpp.o b/Hw6/build/CMakeFiles/ConwaysLife.dir/RendererConsole.cpp.o index c24bb7f..3fb1d6d 100644 Binary files a/Hw6/build/CMakeFiles/ConwaysLife.dir/RendererConsole.cpp.o and b/Hw6/build/CMakeFiles/ConwaysLife.dir/RendererConsole.cpp.o differ diff --git a/Hw6/build/CMakeFiles/ConwaysLife.dir/main.cpp.o b/Hw6/build/CMakeFiles/ConwaysLife.dir/main.cpp.o index 9baab76..d173c94 100644 Binary files a/Hw6/build/CMakeFiles/ConwaysLife.dir/main.cpp.o and b/Hw6/build/CMakeFiles/ConwaysLife.dir/main.cpp.o differ diff --git a/Hw6/build/ConwaysLife b/Hw6/build/ConwaysLife index a7b73ba..507f8b4 100755 Binary files a/Hw6/build/ConwaysLife and b/Hw6/build/ConwaysLife differ diff --git a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/CXX.includecache b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/CXX.includecache index 2686d45..6d988e2 100644 --- a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/CXX.includecache +++ b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/CXX.includecache @@ -57,8 +57,6 @@ PatternGlider.hpp /Users/bradybodily/Repositories/CS3460/Hw6/PatternGlider.hpp Pattern.hpp /Users/bradybodily/Repositories/CS3460/Hw6/Pattern.hpp -array -- /Users/bradybodily/Repositories/CS3460/Hw6/PatternGosperGliderGun.cpp PatternGosperGliderGun.hpp diff --git a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/LifeSimulator.cpp.o b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/LifeSimulator.cpp.o index f653f85..c941df0 100644 Binary files a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/LifeSimulator.cpp.o and b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/LifeSimulator.cpp.o differ diff --git a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternAcorn.cpp.o b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternAcorn.cpp.o index f421087..4076e68 100644 Binary files a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternAcorn.cpp.o and b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternAcorn.cpp.o differ diff --git a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternBlinker.cpp.o b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternBlinker.cpp.o index 163c89b..ffa4f75 100644 Binary files a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternBlinker.cpp.o and b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternBlinker.cpp.o differ diff --git a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternBlock.cpp.o b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternBlock.cpp.o index c2f19ba..45ca8db 100644 Binary files a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternBlock.cpp.o and b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternBlock.cpp.o differ diff --git a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternGlider.cpp.o b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternGlider.cpp.o index 74cc668..6d02fcb 100644 Binary files a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternGlider.cpp.o and b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternGlider.cpp.o differ diff --git a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternGosperGliderGun.cpp.o b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternGosperGliderGun.cpp.o index 42d3427..c9f7123 100644 Binary files a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternGosperGliderGun.cpp.o and b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/PatternGosperGliderGun.cpp.o differ diff --git a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/RendererConsole.cpp.o b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/RendererConsole.cpp.o index 2d36b8f..afbbaa0 100644 Binary files a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/RendererConsole.cpp.o and b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/RendererConsole.cpp.o differ diff --git a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/main.cpp.o b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/main.cpp.o index 308d73f..347c3a0 100644 Binary files a/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/main.cpp.o and b/Hw6/cmake-build-debug/CMakeFiles/ConwaysLife.dir/main.cpp.o differ diff --git a/Hw6/cmake-build-debug/ConwaysLife b/Hw6/cmake-build-debug/ConwaysLife index 2bae8c8..9f88cc4 100755 Binary files a/Hw6/cmake-build-debug/ConwaysLife and b/Hw6/cmake-build-debug/ConwaysLife differ diff --git a/Hw6/main.cpp b/Hw6/main.cpp index f163d47..8426a4c 100644 --- a/Hw6/main.cpp +++ b/Hw6/main.cpp @@ -14,26 +14,26 @@ int main() { - // Renderer and Simulator RendererConsole rendererConsole = RendererConsole(); - LifeSimulator lifeSimulator = LifeSimulator(100, 40); - // Objects - PatternGosperGliderGun patternGosperGliderGun = PatternGosperGliderGun(); - PatternBlock patternBlock = PatternBlock(); - PatternGlider patternGlider = PatternGlider(); - PatternBlinker patternBlinker = PatternBlinker(); - PatternAcorn patternAcorn = PatternAcorn(); + LifeSimulator lifeSimulator = LifeSimulator(100, 100); - // Adding objects to simulator - lifeSimulator.insertPattern(patternGosperGliderGun, 20, 20); - lifeSimulator.insertPattern(patternBlock, 0, 10); - lifeSimulator.insertPattern(patternGlider, 5, 10); + PatternBlinker patternBlinker = PatternBlinker(); lifeSimulator.insertPattern(patternBlinker, 50, 10); + + PatternGlider patternGlider = PatternGlider(); + lifeSimulator.insertPattern(patternGlider, 5, 10); + + PatternGosperGliderGun patternGosperGliderGun = PatternGosperGliderGun(); + lifeSimulator.insertPattern(patternGosperGliderGun, 20, 20); + + PatternBlock patternBlock = PatternBlock(); + lifeSimulator.insertPattern(patternBlock, 0, 10); + + PatternAcorn patternAcorn = PatternAcorn(); lifeSimulator.insertPattern(patternAcorn, 0, 23); - // Animation Demonstration int x = 0; - while (x < 200) + while (x < 400) { rendererConsole.render(lifeSimulator); lifeSimulator.update();