Libsaki
Core library of Pancake Mahjong
form_gb.h
1 #ifndef SAKI_FORM_GB_H
2 #define SAKI_FORM_GB_H
3 
4 #include "explain.h"
5 #include "hand.h"
6 
7 
8 
9 namespace saki
10 {
11 
12 
13 
14 enum Fan
15 {
16  // *** SYNC with FormGb::fan() ***
17  // *** SYNC with spell.js:fantr() ***
18  DSY88, DSX88, JLBD88, LQD88, SG88, LYS88, SSY88,
19  QYJ64, XSY64, XSX64, ZYS64, SAK64, YSSLH64,
20  YSSTS48, YSSJG48,
21  YSSBG32, SG32, HYJ32,
22  Q7D24, QSK24, QYS24, YSSTS24, YSSJG24, QDA24, QZ24, QX24,
23  QL16, SSSLH16, YSSBG16, QDW16, STK16, SAK16,
24  DYW12, XYW12, SFK12,
25  HL8, TBD8, SSSTS8, SSSJG8, WFH8, MSHC8, HDLY8, GSKH8, QGH8,
26  PPH6, HYS6, SSSBG6, WMQ6, QQR6, SAG6, SJK6,
27  MAG5,
28  QDY4, BQR4, SMG4, HJZ4,
29  JK2, QFK2, MFK2, MQQ2, PH2, SGY2, STK2, SAK2, AG2, DY2,
30  YBG1, XXF1, LL1, LSF1, YJK1, MG1, QYM1, WZ1, BZ1, KZ1, DDJ1, ZM1,
31  NUM_FANS
32 };
33 
34 class FormGb
35 {
36 public:
37  enum class Type { F4, F7, F13 };
38 
39  using Fans = std::vector<Fan>;
40 
41  FormGb(const Hand &ready, const T37 &pick, const FormCtx &ctx, bool juezhang);
42  FormGb(const Hand &full, const FormCtx &ctx, bool juezhang);
43  ~FormGb() = default;
44 
45  int fan() const;
46  const Fans &fans() const;
47 
48 private:
49  void init13(const FormCtx &ctx);
50 
51  static int calcFan(const Fans &fs);
52 
53  Fans calcFansF7(const FormCtx &ctx, const Hand &hand) const;
54  Fans calcFansF4(const FormCtx &ctx, const Hand &hand, const T37 &last,
55  const Explain4 &exp, bool juezhang) const;
56 
57  void checkV8864F4(Fans &res, const Hand &hand, const Explain4 &exp,
58  bool pure) const;
59  void checkV4832F4(Fans &res, const Explain4 &exp, bool pureNumMelds) const;
60  void checkV24F4(Fans &res, const Explain4 &exp, bool pure) const;
61  void checkV16F4(Fans &res, const Explain4 &exp) const;
62  void checkV12F4(Fans &res, const Explain4 &exp) const;
63  void checkV8F4(Fans &res, const Explain4 &exp, const FormCtx &ctx) const;
64  void checkV6F4(Fans &res, const Explain4 &exp, const Hand &hand) const;
65  void checkV5F4(Fans &res, const Explain4 &exp) const;
66  void checkV4F4(Fans &res, const Explain4 &exp, bool mqq, bool hjz) const;
67  void checkV2F4(Fans &res, const Explain4 &exp, const FormCtx &ctx,
68  const Hand &hand, const T37 &pick) const;
69  void checkV1F4(Fans &res, const Explain4 &exp, const FormCtx &ctx, const Hand &hand) const;
70 
71  void checkPick(Fans &fans, const FormCtx &ctx) const;
72 
73  bool seq3In3Or4(const Explain4 &exp, std::function<bool(T34, T34, T34)> p) const;
74 
75 private:
76  Type mType;
77  bool mDianpao;
78  Fans mFans;
79  int mFan = 0;
80 };
81 
82 
83 
84 } // namespace saki
85 
86 
87 
88 #endif // SAKI_FORM_GB_H
Definition: form_ctx.h:11
Definition: form_gb.h:34
Definition: tile.h:25
Definition: ai.cpp:18
Definition: hand.h:17
Parsed 4-meld complete hand.
Definition: explain.h:27
Definition: tile.h:353