Libsaki
Core library of Pancake Mahjong
choices.h
1 #ifndef SAKI_CHOICES_H
2 #define SAKI_CHOICES_H
3 
4 #include "../unit/action.h"
5 
6 
7 
8 namespace saki
9 {
10 
11 
12 
14 {
15 public:
16  IrsCheckItem() = default;
17 
18  enum Init
19  {
20  // Choices::sweep() of IRS_CHECK relys on the fact
21  // that radio button can only be child of a check box
22  // by assuming checking nothing is always a legal action
23  CHECK_DISABLED, CHECK_ENABLED,
24  CHILD_RADIO_DEFAULT, CHILD_RADIO,
25  CHILD_CHECK
26  };
27 
28  IrsCheckItem(Init config)
29  {
30  switch (config) {
31  case CHECK_DISABLED:
32  init(false, false, false, false);
33  break;
34  case CHECK_ENABLED:
35  init(false, false, true, false);
36  break;
37  case CHILD_RADIO_DEFAULT:
38  init(true, true, false, true);
39  break;
40  case CHILD_RADIO:
41  init(true, true, false, false);
42  break;
43  case CHILD_CHECK:
44  init(false, true, false, false);
45  break;
46  default:
47  break;
48  }
49  }
50 
51  bool mono() const
52  {
53  return mBits[MONO];
54  }
55 
56  bool indent() const
57  {
58  return mBits[INDENT];
59  }
60 
61  bool able() const
62  {
63  return mBits[ABLE];
64  }
65 
66  bool on() const
67  {
68  return mBits[ON];
69  }
70 
71  void setAble(bool v)
72  {
73  mBits[ABLE] = v;
74  }
75 
76  void setOn(bool v)
77  {
78  mBits[ON] = v;
79  }
80 
81 private:
82  void init(bool mono, bool indent, bool able, bool on)
83  {
84  mBits[MONO] = mono;
85  mBits[INDENT] = indent;
86  setAble(able);
87  setOn(on);
88  }
89 
90  enum Offset : unsigned { MONO, INDENT, ABLE, ON };
91 
92  std::bitset<4> mBits;
93 };
94 
95 // assume 16 is enough
97 
98 
99 
101 {
102  union
103  {
104  bool noTsumo = false;
105  bool noRon;
106  };
107 
108  bool noRiichi = false;
109 
110  void join(ChoiceFilter that)
111  {
112  noTsumo = noTsumo || that.noTsumo;
113  noRiichi = noRiichi || that.noRiichi;
114  }
115 };
116 
117 
118 
122 class Choices
123 {
124 public:
125  enum class Mode
126  {
127  WATCH, IRS_CHECK, DICE, DRAWN, BARK, END
128  };
129 
131  {
132  ModeIrsCheck(const char *n, IrsCheckList l) : name(n), list(l) {}
133  const char *name = nullptr;
134  IrsCheckList list;
135 
136  bool any() const;
137  };
138 
139  struct ModeDrawn
140  {
141  bool swapOut = false;
142  bool spinRiichi = false;
143  bool tsumo = false;
144  bool kskp = false;
145  util::Stactor<T34, 3> ankans;
146  util::Stactor<int, 3> kakans;
147  util::Stactor<T37, 13> swapRiichis;
148  };
149 
150  struct ModeBark
151  {
152  bool chiiL = false;
153  bool chiiM = false;
154  bool chiiR = false;
155  bool pon = false;
156  bool dmk = false;
157  bool ron = false;
158  util::Stactor<T37, 13> swapBarks;
159  T34 focus;
160 
161  bool any() const;
162  };
163 
164  struct ModeEnd
165  {
166  bool end = false;
167  bool next = false;
168  };
169 
170  Choices();
171 
172  bool any() const;
173 
174  Mode mode() const;
175  bool can(ActCode act) const;
176  bool canRiichi() const;
177  bool spinOnly() const;
178 
179  Action timeout() const;
180 
181  const ModeIrsCheck &irsCheck() const;
182  const ModeDrawn &drawn() const;
183  const ModeBark &bark() const;
184 
185  void setWatch();
186  void setIrsCheck(const ModeIrsCheck &irsCheck);
187  void setDice();
188  void setDrawn(const ModeDrawn &mode);
189  void setBark(const ModeBark &mode);
190  void setEnd(const ModeEnd &mode);
191 
192  void setIrsClick(const Choices &from);
193 
194  void filter(const ChoiceFilter &f);
195 
196 private:
197  Choices &operator=(const Choices &assign) = default;
198 
199 private:
200  Mode mMode = Mode::WATCH;
201  bool mIrsClick = false;
202 
203  union
204  {
205  ModeIrsCheck mModeIrsCheck;
206  ModeDrawn mModeDrawn;
207  ModeBark mModeBark;
208  ModeEnd mModeEnd;
209  };
210 
211 };
212 
213 
214 
215 } // namespace saki
216 
217 
218 
219 #endif // SAKI_CHOICES_H
Definition: choices.h:139
Definition: choices.h:13
Definition: tile.h:25
Choice set of one player.
Definition: choices.h:122
Definition: choices.h:100
Definition: choices.h:150
Definition: action.h:27
Definition: ai.cpp:18
Definition: choices.h:130
Definition: choices.h:164