Libsaki
Core library of Pancake Mahjong
replay.h
1 #ifndef SAKI_REPLAY_H
2 #define SAKI_REPLAY_H
3 
4 #include "../table/table_observer.h"
5 #include "../table/girl.h"
6 
7 
8 
9 namespace saki
10 {
11 
12 
13 
14 struct PlayerSnap
15 {
18  std::vector<T37> river;
19  int riichiPos = -1;
20  bool riichiBar = false;
21 };
22 
23 struct TableSnap
24 {
25  std::array<PlayerSnap, 4> players;
26  Who whoDrawn;
27  T37 drawn;
28  std::array<int, 4> points;
31  int wallRemain;
32  int deadRemain;
33 
34  int round;
35  int extraRound;
36  Who dealer;
37  bool allLast;
38  int deposit;
39  uint32_t state;
40  int die1;
41  int die2;
42  RoundResult result;
43  bool endOfRound = false;
44  Who gunner;
45  T37 cannon;
46  std::vector<Who> openers;
47  std::vector<std::string> spells;
48  std::vector<std::string> charges;
49 
50  PlayerSnap &operator[](size_t w) { return players[w]; }
51  const PlayerSnap &operator[](size_t w) const { return players[w]; }
52 };
53 
55 {
56 public:
57  enum In
58  {
59  DRAW, CHII_AS_LEFT, CHII_AS_MIDDLE, CHII_AS_RIGHT,
60  PON, DAIMINKAN, RON, SKIP_IN
61  };
62 
63  enum Out
64  {
65  ADVANCE, SPIN, RIICHI_ADVANCE, RIICHI_SPIN, ANKAN, KAKAN,
66  RYUUKYOKU, TSUMO, SKIP_OUT
67  };
68 
69  struct InAct
70  {
71  explicit InAct(In act) : act(act) {}
72  explicit InAct(In act, const T37 &t) : act(act), t37(t) {}
73  explicit InAct(In act, int showAka5) : act(act), showAka5(showAka5) {}
74  In act;
75  union
76  {
77  T37 t37;
78  int showAka5;
79  };
80 
81  };
82 
83  struct OutAct
84  {
85  explicit OutAct(Out act) : act(act) {}
86  explicit OutAct(Out act, const T37 &t) : act(act), t37(t) {}
87  Out act;
88  T37 t37;
89  };
90 
91  struct Track
92  {
93  std::array<T37, 13> init;
94  std::vector<InAct> in;
95  std::vector<OutAct> out;
96  };
97 
98  struct Round
99  {
100  int round;
101  int extraRound;
102  Who dealer;
103  bool allLast;
104  int deposit;
105  uint32_t state;
106  int die1;
107  int die2;
108  RoundResult result = RoundResult::ABORT;
109  std::array<int, 4> resultPoints;
110  std::vector<std::string> spells;
111  std::vector<std::string> charges;
112  std::vector<T37> drids;
113  std::vector<T37> urids;
114  std::array<Track, 4> tracks;
115  };
116 
117  Replay() = default;
118  Replay(const Replay &copy) = default;
119  ~Replay() override = default;
120  Replay &operator=(const Replay &assign) = default;
121 
122  void onTableEvent(const Table &table, const TE::TableStarted &event) override;
123  void onTableEvent(const Table &table, const TE::RoundStarted &event) override;
124  void onTableEvent(const Table &table, const TE::Diced &event) override;
125  void onTableEvent(const Table &table, const TE::Dealt &event) override;
126  void onTableEvent(const Table &table, const TE::Flipped &event) override;
127  void onTableEvent(const Table &table, const TE::Drawn &event) override;
128  void onTableEvent(const Table &table, const TE::Discarded &event) override;
129  void onTableEvent(const Table &table, const TE::RiichiCalled &event) override;
130  void onTableEvent(const Table &table, const TE::Barked &event) override;
131  void onTableEvent(const Table &table, const TE::RoundEnded &event) override;
132  void onTableEvent(const Table &table, const TE::PointsChanged &event) override;
133 
134  TableSnap look(int roundId, int turn);
135 
136 private:
137  void addSkip(Who who, Who fromWhom);
138  void lookAdvance(TableSnap &snap, TileCount &hand, const T37 &t37, Who who);
139  void lookChii(TableSnap &snap, TileCount &hand, const InAct &in, Who who, Who lastDiscarder);
140  void lookPon(TableSnap &snap, TileCount &hand, int showAka5, Who who, Who lastDiscarder);
141  void lookDaiminkan(TableSnap &snap, TileCount &hand, Who who, Who lastDiscarder);
142  void lookAnkan(TableSnap &snap, TileCount &hand, T34 t34, Who who);
143  void lookKakan(TableSnap &snap, TileCount &hand, const T37 &t37, Who who);
144 
145 public:
146  std::array<Girl::Id, 4> girls;
147  std::array<int, 4> initPoints;
148  Rule rule;
149  uint32_t seed;
150  std::vector<Round> rounds;
151 
152 private:
153  bool mToEstablishRiichi = false;
154 };
155 
156 
157 
158 } // namespace saki
159 
160 
161 
162 #endif // SAKI_REPLAY_H
Definition: rule.h:13
Definition: table_event.h:82
Definition: replay.h:83
Definition: replay.h:23
Definition: table_observer.h:38
Definition: replay.h:69
Definition: table.h:87
Definition: tile.h:25
Definition: table_event.h:131
Definition: tile_count.h:17
Definition: table_event.h:140
Definition: table_event.h:94
Definition: ai.cpp:18
Definition: table_event.h:66
Definition: table_event.h:105
Definition: replay.h:91
Definition: table_event.h:99
Definition: replay.h:54
Definition: table_event.h:89
Definition: table_event.h:123
Definition: tile.h:353
Stactor = statically allocated vector.
Definition: stactor.h:247
Definition: table_event.h:54
Definition: table_event.h:111
Definition: replay.h:14
Definition: replay.h:98
Definition: who.h:14