Libsaki
Core library of Pancake Mahjong
parsed.h
1 #ifndef SAKI_PARSED_H
2 #define SAKI_PARSED_H
3 
4 #include "../unit/comeld.h"
5 
6 #include <optional>
7 #include <vector>
8 
9 
10 
11 namespace saki
12 {
13 
14 
15 
16 class Parsed4
17 {
18 public:
20 
21  static int workOfHeads(const Heads &heads);
22 
23  explicit Parsed4(const Heads &heads, int barkCt);
24 
25  const Heads &heads() const;
26  int barkCt() const;
27 
28  int step4() const;
29  std::bitset<34> effA4Set() const;
30 
31  util::Stactor<T34, 9> claim3sk() const;
32 
33  bool operator==(const Parsed4 &that) const;
34 
35 private:
36  util::Stactor<T34, 9> minTilesTo(const std::array<C34, 3> &cs) const;
37  util::Stactor<T34, 3> minTilesTo(const C34 &cs) const;
38 
39  void computeEffA4() const;
40 
41 private:
42  Heads mHeads;
43  int mBarkCt;
44  mutable std::optional<std::bitset<34>> mEffA4SetCache;
45 };
46 
47 
48 
49 inline std::ostream &operator<<(std::ostream &os, const Parsed4 &p)
50 {
51  return os << p.heads();
52 }
53 
54 
55 
56 class Parsed4s
57 {
58 public:
59  using Container = std::vector<Parsed4>;
60 
61  explicit Parsed4s(Container &&parseds);
62 
63  const Container &data() const;
64  int size() const;
65  int barkCt() const;
66  Container::const_iterator begin() const;
67  Container::const_iterator end() const;
68 
69  int step4() const;
70  util::Stactor<T34, 34> effA4() const;
71  std::bitset<34> effA4Set() const;
72 
73 private:
74  Container mParseds;
75  mutable std::optional<std::bitset<34>> mEffA4SetCache;
76 };
77 
78 
79 
80 class Parsed7
81 {
82 public:
83  explicit Parsed7(const std::bitset<34> &plurals, const std::bitset<34> &floats);
84 
85  int step7() const;
86  std::bitset<34> effA7Set() const;
87 
88 private:
89  std::bitset<34> mPlurals;
90  std::bitset<34> mFloats;
91  int mNeedKind;
92 };
93 
94 
95 
96 class Parsed13
97 {
98 public:
99  explicit Parsed13(const std::bitset<34> &yaos, bool hasYaoPair);
100 
101  int step13() const;
102  std::bitset<34> effA13Set() const;
103 
104 private:
105  std::bitset<34> mYaos;
106  bool mHasYaoPair;
107  mutable std::optional<std::bitset<34>> mEffA13SetCache;
108 };
109 
110 
111 
112 class Parseds
113 {
114 public:
115  static const int STEP_INF = 14;
116 
117  explicit Parseds(const Parsed4s &p4, const Parsed7 &p7, const Parsed13 &p13);
118  explicit Parseds(const Parsed4s &p4);
119 
120  const Parsed4s &get4s() const;
121 
122  int step() const;
123  int step4() const;
124  int step7() const;
125  int step13() const;
126 
127  util::Stactor<T34, 34> effA() const;
128  util::Stactor<T34, 34> effA4() const;
129  std::bitset<34> effASet() const;
130  std::bitset<34> effA4Set() const;
131  std::bitset<34> effA7Set() const;
132  std::bitset<34> effA13Set() const;
133 
134 private:
135  void computeEffA() const;
136 
137 private:
138  Parsed4s mParsed4s;
139  std::optional<Parsed7> mParsed7;
140  std::optional<Parsed13> mParsed13;
141  mutable std::optional<std::bitset<34>> mEffASetCache;
142 };
143 
144 
145 
146 } // namespace saki
147 
148 
149 
150 #endif // SAKI_PARSED_H
Definition: parsed.h:16
static int workOfHeads(const Heads &heads)
Shanten number by which this parsing result decreases to the hand.
Definition: parsed.cpp:18
Definition: parsed.h:112
Comeld, a meld or a part of a meld.
Definition: comeld.h:18
Parsed4(const Heads &heads, int barkCt)
Construct from raw comeld data.
Definition: parsed.cpp:35
Definition: ai.cpp:18
int step4() const
Compute 4-meld shanten number with given bark count.
Definition: parsed.cpp:56
bool operator==(const Parsed4 &that) const
ordered equal, not set equal
Definition: parsed.cpp:99
Definition: parsed.h:80
Definition: parsed.h:96
std::bitset< 34 > effA4Set() const
Get the set of first-class effective tiles of this parse formation.
Definition: parsed.cpp:64
Definition: parsed.h:56