about summary refs log tree commit diff stats
path: root/ext/wittle_generator/PuzzleSymbols.h
diff options
context:
space:
mode:
Diffstat (limited to 'ext/wittle_generator/PuzzleSymbols.h')
-rw-r--r--ext/wittle_generator/PuzzleSymbols.h59
1 files changed, 59 insertions, 0 deletions
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 @@
1#ifndef PUZZLESYMBOLS_H_9DD95900
2#define PUZZLESYMBOLS_H_9DD95900
3
4#include <map>
5#include <vector>
6
7#include "Panel.h"
8#include "Random.h"
9
10struct PuzzleSymbols {
11 std::map<int, std::vector<std::pair<int, int>>> symbols;
12 std::vector<std::pair<int, int>>& operator[](int symbolType) {
13 return symbols[symbolType];
14 }
15 int style;
16 int getNum(int symbolType) {
17 int total = 0;
18 for (auto& pair : symbols[symbolType]) total += pair.second;
19 return total;
20 }
21 bool any(int symbolType) { return symbols[symbolType].size() > 0; }
22 int popRandomSymbol() {
23 std::vector<int> types;
24 for (auto& pair : symbols)
25 if (pair.second.size() > 0 && pair.first != Decoration::Start &&
26 pair.first != Decoration::Exit && pair.first != Decoration::Gap &&
27 pair.first != Decoration::Eraser)
28 types.push_back(pair.first);
29 int randType = types[Random::rand() % types.size()];
30 int randIndex = Random::rand() % symbols[randType].size();
31 while (symbols[randType][randIndex].second == 0 ||
32 symbols[randType][randIndex].second >= 25) {
33 randType = types[Random::rand() % types.size()];
34 randIndex = Random::rand() % symbols[randType].size();
35 }
36 symbols[randType][randIndex].second--;
37 return symbols[randType][randIndex].first;
38 }
39 PuzzleSymbols(std::vector<std::pair<int, int>> symbolVec) {
40 for (std::pair<int, int> s : symbolVec) {
41 if (s.first == Decoration::Gap || s.first == Decoration::Start ||
42 s.first == Decoration::Exit)
43 symbols[s.first].push_back(s);
44 else if (s.first & Decoration::Dot)
45 symbols[Decoration::Dot].push_back(s);
46 else
47 symbols[s.first & 0x700].push_back(s);
48 }
49 style = 0;
50 if (any(Decoration::Dot)) style |= Panel::Style::HAS_DOTS;
51 if (any(Decoration::Stone)) style |= Panel::Style::HAS_STONES;
52 if (any(Decoration::Star)) style |= Panel::Style::HAS_STARS;
53 if (any(Decoration::Poly)) style |= Panel::Style::HAS_SHAPERS;
54 if (any(Decoration::Triangle)) style |= Panel::Style::HAS_TRIANGLES;
55 if (any(Decoration::Arrow)) style |= Panel::Style::HAS_TRIANGLES;
56 }
57};
58
59#endif /* end of include guard: PUZZLESYMBOLS_H_9DD95900 */