Libsaki
Core library of Pancake Mahjong
girl.h
1 #ifndef SAKI_GIRL_H
2 #define SAKI_GIRL_H
3 
4 #include "../table/mount.h"
5 #include "../table/table_observer.h"
6 #include "../table/choices.h"
7 
8 #include "../util/misc.h"
9 
10 #include <optional>
11 
12 
13 
14 namespace saki
15 {
16 
17 
18 
19 class Hand;
20 class Table;
21 class Choices;
22 class Action;
23 class IrsCtrl;
24 class HrhBargainer;
25 struct HrhInitFix;
26 
27 
28 
35 class Girl : public TableObserver
36 {
37 public:
38  // *INDENT-OFF*
39  enum class Id
40  {
41  DOGE = 0, CUSTOM = 1,
42 
43  // IH71 A-Block
44  MIYANAGA_TERU = 710111, HIROSE_SUMIRE = 710112, SHIBUYA_TAKAMI = 710113,
45  MATANO_SEIKO = 710114, OOHOSHI_AWAI = 710115,
46  MATSUMI_KURO = 712411, MATSUMI_YUU = 712412, ATARASHI_AKO = 712413,
47  SAGIMORI_ARATA = 712414, TAKAKAMO_SHIZUNO = 712415,
48  ONJOUJI_TOKI = 712611, NIJOU_IZUMI = 712612, EGUCHI_SERA = 712613,
49  FUNAKUBO_HIROKO = 712614, SHIMIZUDANI_RYUUKA = 712615,
50 
51  // IH71 B-Block
52  USUZUMI_HATSUMI = 712714, IWATO_KASUMI = 712715,
53  ANETAI_TOYONE = 712915,
54  KATAOKA_YUUKI = 713311, SOMEYA_MAKO = 713312, TAKEI_HISA = 713313,
55  HARAMURA_NODOKA = 713314, MIYANAGA_SAKI = 713315,
56  NANPO_KAZUE = 713301,
57  UESHIGE_SUZU = 713811, SUEHARA_KYOUKO = 713815,
58  TSUJIGAITO_SATOHA = 715211, HAO_HUIYU = 715212, CHOI_MYEONGHWA = 715213,
59  MEGAN_DAVIN = 715214, NELLY_VIRSALADZE = 715215,
60  SHISHIHARA_SAWAYA = 714915,
61 
62  // Others
63  INAMURA_KYOUKA = 990001, SHIRATSUKI_SHINO = 990002, HONDOU_YUE = 990003,
64  MIHOROGI_UTA = 990011, TAKUWA_RIO = 990014,
65  KAJINO_YUI = 990024
66  };
67  // *INDENT-ON*
68 
78  {
79  public:
80  template<typename IrsCtrlImpl, typename GirlImpl>
81  static IrsCtrlImpl Girl::*upcast(IrsCtrlImpl GirlImpl::*mem)
82  {
83  return static_cast<IrsCtrlImpl Girl::*>(mem);
84  }
85 
86  template<typename IrsCtrlImpl, typename GirlImpl>
87  IrsCtrlGetter(IrsCtrlImpl GirlImpl::*mem)
88  : mImpl(mem == nullptr ? nullptr : std::make_unique<Impl<IrsCtrlImpl>>(upcast(mem)))
89  {
90  }
91 
92  IrsCtrlGetter(std::nullptr_t)
93  {
94  }
95 
96  IrsCtrlGetter(const IrsCtrlGetter &copy)
97  : mImpl(copy.mImpl == nullptr ? nullptr : copy.mImpl->clone())
98  {
99  }
100 
102  : mImpl(std::move(move.mImpl))
103  {
104  }
105 
106  IrsCtrlGetter &operator=(IrsCtrlGetter &&that)
107  {
108  mImpl = std::move(that.mImpl);
109  return *this;
110  }
111 
112  bool ready() const
113  {
114  return mImpl != nullptr;
115  }
116 
117  IrsCtrl &get(Girl &girl) const
118  {
119  return mImpl->get(girl);
120  }
121 
122  private:
123  class ImplBase
124  {
125  public:
126  virtual ~ImplBase() = default;
127  virtual std::unique_ptr<ImplBase> clone() = 0;
128  virtual IrsCtrl &get(Girl &girl) = 0;
129  };
130 
131  template<typename IrsCtrlType>
132  class Impl : public ImplBase
133  {
134  public:
135  Impl(IrsCtrlType Girl::*ptrToMem)
136  : mPtrToMem(ptrToMem)
137  {
138  }
139 
140  std::unique_ptr<ImplBase> clone() override
141  {
142  return std::make_unique<Impl>(*this);
143  }
144 
145  IrsCtrl &get(Girl &girl) override
146  {
147  return girl.*mPtrToMem;
148  }
149 
150  private:
151  IrsCtrlType Girl::*mPtrToMem;
152  };
153 
154  private:
155  std::unique_ptr<ImplBase> mImpl;
156  };
157 
158  static std::unique_ptr<Girl> create(Who who, Id id);
159 
160  Girl(Who who, Id id);
161  ~Girl() override = default;
162  Girl(const Girl &copy) = default;
163  Girl &operator=(const Girl &assign) = delete;
164 
165  virtual std::unique_ptr<Girl> clone() const;
166 
167  Id getId() const;
168 
169  virtual void onDice(util::Rand &rand, const Table &table);
170  virtual void onMonkey(std::array<Exist, 4> &exists, const Table &table);
171  virtual bool checkInit(Who who, const Hand &init, const Table &table, int iter);
172  virtual void onInbox(Who who, const Action &action);
173  virtual void onDraw(const Table &table, Mount &mount, Who who, bool rinshan);
174  virtual void onChooseFirstDealer(util::Rand &rand, Who tempDealer, int &die1, int &die2);
175  virtual void onIrsChecked(const Table &table, Mount &mount);
176  virtual void onFlipKandoraIndic(const Table &table, Mount &mount);
177  virtual void onDigUradoraIndic(const Table &table, Mount &mount, util::Stactor<Who, 4> openers);
178 
179  void onFilterChoice(const Table &table, Who who, ChoiceFilter &filter);
180  void onActivateDice(const Table &table);
181  void onActivate(const Table &table);
182 
183  bool irsReady() const;
184  const Choices &irsChoices() const;
185 
186  virtual std::optional<HrhInitFix> onHrhRaid(const Table &table);
187  virtual HrhBargainer *onHrhBargain(const Table &table);
188  virtual std::optional<HrhInitFix> onHrhBeg(util::Rand &rand, const Table &table, const TileCount &stock);
189 
190  virtual std::string popUpStr() const;
191 
192  bool handleIrs(const Table &table, Mount &mount, const Action &action);
193 
194 protected:
195  static void eraseRivered(util::Stactor<T34, 34> &ts, const River &river);
196  static void eraseRivered(std::bitset<34> &ts, const River &river);
197  void accelerate(Mount &mount, const Hand &hand, const River &river, int delta);
198 
199  virtual ChoiceFilter filterChoice(const Table &table, Who who);
200  virtual IrsCtrlGetter attachIrsOnDice();
201  virtual IrsCtrlGetter attachIrsOnDrawn(const Table &table);
202 
203 protected:
204  const Who mSelf;
205  const Id mId;
206 
207 private:
208  IrsCtrlGetter mIrsCtrlGetter = nullptr;
209 };
210 
211 template<typename Derived>
212 class GirlCrtp : public Girl
213 {
214 public:
215  using Girl::Girl;
216 
217  std::unique_ptr<Girl> clone() const final
218  {
219  if constexpr (std::is_base_of_v<GirlCrtp<Derived>, Derived>)
220  return std::make_unique<Derived>(static_cast<const Derived &>(*this));
221  else // NOLINT
222  static_assert(False<Derived>::value, "Must follow CRTP");
223  }
224 
225 private:
226  template<typename T> struct False : std::false_type {};
227 };
228 
229 
230 
231 } // namespace saki
232 
233 
234 
235 #endif // SAKI_GIRL_H
virtual void onFlipKandoraIndic(const Table &table, Mount &mount)
Called before flipping kandora indicator.
Definition: girl.cpp:137
Definition: lobject.h:497
Interface for working with the &#39;bargain&#39; stage.
Definition: princess.h:38
Definition: mount.h:54
virtual IrsCtrlGetter attachIrsOnDrawn(const Table &table)
Overriden to define a drawn-time IRS&#39;s showing condition.
Definition: girl.cpp:288
virtual void onDice(util::Rand &rand, const Table &table)
Called when someone is about to dice.
Definition: girl.cpp:93
virtual void onDraw(const Table &table, Mount &mount, Who who, bool rinshan)
Called when someone is about to draw a tile from the mountain.
Definition: girl.cpp:116
void onFilterChoice(const Table &table, Who who, ChoiceFilter &filter)
Called on the choice-filtering stage.
Definition: girl.cpp:154
virtual void onIrsChecked(const Table &table, Mount &mount)
Called after self&#39;s IRS-check action.
Definition: girl.cpp:129
Definition: table.h:87
Definition: rand.h:19
const Choices & irsChoices() const
IRS choice set if IRS-ready, undefined otherwise.
Definition: girl.cpp:196
virtual IrsCtrlGetter attachIrsOnDice()
Overriden to define a dice-time IRS&#39;s showing condition.
Definition: girl.cpp:278
Definition: tile_count.h:17
Choice set of one player.
Definition: choices.h:122
Definition: choices.h:100
Definition: irs_ctrl.h:29
Definition: table_observer.h:23
void onActivate(const Table &table)
Called when self is about to be activated.
Definition: girl.cpp:171
Definition: action.h:27
Definition: ai.cpp:18
bool irsReady() const
Whether the girl is ready to process an IRS action input.
Definition: girl.cpp:187
virtual void onDigUradoraIndic(const Table &table, Mount &mount, util::Stactor< Who, 4 > openers)
Called after someone&#39;s win, before digging uradora indicator.
Definition: girl.cpp:146
Definition: hand.h:17
Wrapper of a "T Girl::*" value where T implements IrsCtrl.
Definition: girl.h:77
bool handleIrs(const Table &table, Mount &mount, const Action &action)
Process an IRS action input.
Definition: girl.cpp:231
Stactor = statically allocated vector.
Definition: stactor.h:247
Definition: girl.h:212
Base class for skill implementation.
Definition: girl.h:35
void onActivateDice(const Table &table)
Called when the dealer (self or not) is about to dice.
Definition: girl.cpp:162
Definition: who.h:14