From dde56d26837dc52e05207c0672b3c4a1046f6cb2 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 27 Oct 2023 13:41:27 -0400 Subject: pulled out generation logic from sigma's rando --- ext/wittle_generator/PuzzleSymbols.h | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 ext/wittle_generator/PuzzleSymbols.h (limited to 'ext/wittle_generator/PuzzleSymbols.h') diff --git a/ext/wittle_generator/PuzzleSymbols.h b/ext/wittle_generator/PuzzleSymbols.h new file mode 100644 index 0000000..dedf61a --- /dev/null +++ b/ext/wittle_generator/PuzzleSymbols.h @@ -0,0 +1,59 @@ +#ifndef PUZZLESYMBOLS_H_9DD95900 +#define PUZZLESYMBOLS_H_9DD95900 + +#include +#include + +#include "Panel.h" +#include "Random.h" + +struct PuzzleSymbols { + std::map>> symbols; + std::vector>& operator[](int symbolType) { + return symbols[symbolType]; + } + int style; + int getNum(int symbolType) { + int total = 0; + for (auto& pair : symbols[symbolType]) total += pair.second; + return total; + } + bool any(int symbolType) { return symbols[symbolType].size() > 0; } + int popRandomSymbol() { + std::vector types; + for (auto& pair : symbols) + if (pair.second.size() > 0 && pair.first != Decoration::Start && + pair.first != Decoration::Exit && pair.first != Decoration::Gap && + pair.first != Decoration::Eraser) + types.push_back(pair.first); + int randType = types[Random::rand() % types.size()]; + int randIndex = Random::rand() % symbols[randType].size(); + while (symbols[randType][randIndex].second == 0 || + symbols[randType][randIndex].second >= 25) { + randType = types[Random::rand() % types.size()]; + randIndex = Random::rand() % symbols[randType].size(); + } + symbols[randType][randIndex].second--; + return symbols[randType][randIndex].first; + } + PuzzleSymbols(std::vector> symbolVec) { + for (std::pair s : symbolVec) { + if (s.first == Decoration::Gap || s.first == Decoration::Start || + s.first == Decoration::Exit) + symbols[s.first].push_back(s); + else if (s.first & Decoration::Dot) + symbols[Decoration::Dot].push_back(s); + else + symbols[s.first & 0x700].push_back(s); + } + style = 0; + if (any(Decoration::Dot)) style |= Panel::Style::HAS_DOTS; + if (any(Decoration::Stone)) style |= Panel::Style::HAS_STONES; + if (any(Decoration::Star)) style |= Panel::Style::HAS_STARS; + if (any(Decoration::Poly)) style |= Panel::Style::HAS_SHAPERS; + if (any(Decoration::Triangle)) style |= Panel::Style::HAS_TRIANGLES; + if (any(Decoration::Arrow)) style |= Panel::Style::HAS_TRIANGLES; + } +}; + +#endif /* end of include guard: PUZZLESYMBOLS_H_9DD95900 */ -- cgit 1.4.1