Libsaki
Core library of Pancake Mahjong
form.h
1 #ifndef SAKI_FORM_H
2 #define SAKI_FORM_H
3 
4 #include "explain.h"
5 
6 
7 
8 namespace saki
9 {
10 
11 
12 
13 enum Yaku {
14  // *** SYNC with Form::calcHan() ***
15  // *** SYNC with YAKU_STRS and Form::spell() ***
16  RC, IPT, MZCTMH, TYC, PF,
17  YKH1Y, YKH2Y, YKH3Y,
18  JKZ1F, JKZ2F, JKZ3F, JKZ4F,
19  BKZ1F, BKZ2F, BKZ3F, BKZ4F,
20  IPK, RSKH, HTRY_T, HTRY_R, CK,
21  SSKDJ_K, IKTK_K, HCTYC_K,
22 
23  DBRRC, SSKDJ, IKTK, HCTYC,
24  TTH, CTT, S3AK, S3KT, SSKDK, HRT, SSG, HIS_K, JCTYC_K,
25 
26  HIS, JCTYC, RPK, CIS_K, CIS,
27 
28  KKSMS, DSG, S4AK, TIS, SSS, DSS,
29  CRT, RIS, TH, CH, S4KT, CRPT,
30  KKSMS_A, S4AK_A, CRPT_A,
31 
32  NUM_YAKUS
33 };
34 
35 enum ManganType { HR, MG, HNM, BM, SBM, KZEYKM };
36 
37 extern std::array<const char *, NUM_YAKUS> YAKU_STRS;
38 
39 class Form
40 {
41 public:
42  enum class Type { F4, F7, F13 };
43 
44  using Yakus = std::bitset<Yaku::NUM_YAKUS>;
45 
46  Form(const Hand &ready, const T37 &pick, const FormCtx &ctx, const Rule &rule,
49  Form(const Hand &full, const FormCtx &ctx, const Rule &rule,
52 
53  ~Form() = default;
54 
55  bool isPrototypalYakuman() const;
56  int fu() const;
57  int han() const;
58  int base() const;
59  int dora() const;
60  int uradora() const;
61  int akadora() const;
62  const Yakus &yakus() const;
63  std::vector<const char *> keys() const;
64  ManganType manganType() const;
65  bool hasYaku() const;
66 
67  int netLoss(bool isDealer) const;
68  int netGain() const;
69  int loss(bool isDealer) const;
70  int gain() const;
71  std::string spell() const;
72  std::string charge() const;
73 
74 private:
75  void init13(const FormCtx &ctx, const TileCount &ready, T34 last);
76  void init4(const FormCtx &ctx, const Rule &rule, const Hand &hand, const T37 &last);
77  void init7(const FormCtx &ctx, const Rule &rule, const TileCount &ready);
78 
79  void init7Dye(const TileCount &ready);
80  void init7TanyaoOrHonroutou(const TileCount &ready);
81  void initDora(const util::Stactor<T37, 5> &drids, const util::Stactor<T37, 5> &urids,
82  const Hand &full);
83  void initDora(const util::Stactor<T37, 5> &drids, const util::Stactor<T37, 5> &urids,
84  const Hand &ready, const T37 &last);
85 
86  void checkPick(Yakus &ys, const FormCtx &ctx) const;
87  void checkRiichi(Yakus &ys, const FormCtx &ctx, const Rule &rule) const;
88  void checkTsumo(Yakus &ys, bool menzen) const;
89  void checkAge4(Yakus &ys, const Explain4 &exp, bool menzen) const;
90  void checkPinfu4(Yakus &ys, const FormCtx &ctx, const Explain4 &exp, bool menzen) const;
91  void checkDye4(Yakus &ys, const Explain4 &exp, bool menzen) const;
92  void checkCup4(Yakus &ys, const Explain4 &exp, bool menzen) const;
93  void checkYakuhai4(Yakus &ys, const FormCtx &ctx, const Explain4 &exp) const;
94  void checkIttsuu4(Yakus &ys, const Explain4 &exp, bool menzen) const;
95  void checkSanshoku4(Yakus &ys, const Explain4 &exp, bool menzen) const;
96  void checkX34s4(Yakus &ys, const Explain4 &exp) const;
97  void checkSanshokudoukou4(Yakus &ys, const Explain4 &exp) const;
98  void checkShousangen(Yakus &ys, const Explain4 &exp) const;
99 
100  Yakus calcYakuman4(const FormCtx &ctx, const Explain4 &exp,
101  const TileCount &closed, const T37 &last) const;
102  Yakus calcYaku4(const FormCtx &ctx, const Rule &rule,
103  bool menzen, const Explain4 &exp) const;
104  int calcFu(const FormCtx &ctx, const Explain4 &exp, bool menzen) const;
105  int calcHan(const Yakus &ys) const;
106  int calcBase(int fu, int han) const;
107 
108 private:
109  Type mType;
110  Yakus mYakus;
111  bool mYakuman = false;
112  bool mDealerWin;
113  bool mRon;
114  int mFu = 0;
115  int mHan = 0;
116  int mExtraRound;
117  int mBase = 0;
118  int mDora;
119  int mUradora;
120  int mAkadora;
121 };
122 
123 
124 
125 } // namepace saki
126 
127 
128 
129 #endif // SAKI_FORM_H
Definition: form.h:39
Definition: rule.h:13
Definition: form_ctx.h:11
Definition: tile.h:25
Definition: tile_count.h:17
Definition: ai.cpp:18
Definition: hand.h:17
Parsed 4-meld complete hand.
Definition: explain.h:27
Definition: tile.h:353
Stactor = statically allocated vector.
Definition: stactor.h:247