summaryrefslogtreecommitdiff
path: root/Homework/cs3460/gameoflife/PatternSet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Homework/cs3460/gameoflife/PatternSet.cpp')
-rw-r--r--Homework/cs3460/gameoflife/PatternSet.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/Homework/cs3460/gameoflife/PatternSet.cpp b/Homework/cs3460/gameoflife/PatternSet.cpp
new file mode 100644
index 0000000..8bb3cdf
--- /dev/null
+++ b/Homework/cs3460/gameoflife/PatternSet.cpp
@@ -0,0 +1,42 @@
+#include "PatternSet.hpp"
+
+PatternSet::PatternSet(std::uint8_t width, std::uint8_t height) :
+ m_width(width), m_height(height)
+{
+}
+
+PatternSet::PatternSet(const std::set<std::pair<std::uint8_t, std::uint8_t>> aliveCells) :
+ m_aliveCells(aliveCells)
+{
+ m_width = std::max_element(
+ aliveCells.begin(), aliveCells.end(),
+ [](const auto coord1, const auto coord2)
+ {
+ return coord1.first < coord2.first;
+ })
+ ->first +
+ 1;
+ m_height = std::max_element(
+ aliveCells.begin(), aliveCells.end(),
+ [](const auto coord1, const auto coord2)
+ {
+ return coord1.second < coord2.second;
+ })
+ ->second +
+ 1;
+}
+
+std::uint8_t PatternSet::getSizeX() const
+{
+ return m_width;
+}
+
+std::uint8_t PatternSet::getSizeY() const
+{
+ return m_height;
+}
+
+bool PatternSet::getCell(std::uint8_t x, std::uint8_t y) const
+{
+ return m_aliveCells.contains(std::pair<std::uint8_t, std::uint8_t>(x, y));
+}