forked from Cryolite/kanachan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
round_state.hpp
143 lines (96 loc) · 4.34 KB
/
round_state.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#if !defined(KANACHAN_SIMULATION_ROUND_STATE_HPP_INCLUDE_GUARD)
#define KANACHAN_SIMULATION_ROUND_STATE_HPP_INCLUDE_GUARD
#include "simulation/shoupai.hpp"
#include "simulation/paishan.hpp"
#include "simulation/game_state.hpp"
#include <boost/python/dict.hpp>
#include <vector>
#include <array>
#include <utility>
#include <limits>
#include <cstdint>
namespace Kanachan{
class RoundState
{
public:
RoundState(
std::vector<std::uint_least32_t> const &seed, Kanachan::GameState &game_state,
Kanachan::Paishan const *p_test_paishan);
RoundState(RoundState const &) = delete;
RoundState(RoundState &&) = delete;
RoundState &operator=(RoundState const &) = delete;
RoundState &operator=(RoundState &&) = delete;
public:
std::uint_fast8_t getPlayerGrade(std::uint_fast8_t seat) const;
std::uint_fast8_t getChang() const;
std::uint_fast8_t getJu() const;
std::uint_fast8_t getBenChang() const;
std::uint_fast8_t getNumLizhiDeposits() const;
std::int_fast32_t getPlayerScore(std::uint_fast8_t seat) const;
std::uint_fast8_t getPlayerRanking(std::uint_fast8_t seat) const;
std::uint_fast8_t getDoraIndicator(std::uint_fast8_t index) const;
std::uint_fast8_t getNumLeftTiles() const;
std::int_fast32_t getPlayerDeltaScore(std::uint_fast8_t seat) const;
bool isPlayerMenqian(std::uint_fast8_t seat) const;
bool isPlayerTingpai(std::uint_fast8_t seat) const;
bool checkPlayerLiujuManguan(std::uint_fast8_t seat) const;
bool checkSifengLianda() const;
bool checkSigangSanle() const;
bool checkSijiaLizhi() const;
private:
std::pair<std::uint_fast8_t, std::uint_fast8_t> getLastDapai_() const;
std::uint_fast8_t drawLingshangPai_();
std::pair<std::vector<std::uint_fast16_t>, std::vector<std::uint_fast32_t>>
constructFeatures_(std::uint_fast8_t seat, std::uint_fast8_t zimo_tile) const;
std::uint_fast16_t selectAction_(
std::uint_fast8_t seat, std::vector<std::uint_fast16_t> &&sparse,
std::vector<std::uint_fast32_t> &&numeric, std::vector<uint_fast16_t> &&progression,
std::vector<std::uint_fast16_t> &&candidates) const;
long encodeToolConfig_(std::uint_fast8_t seat, bool rong) const;
std::vector<std::uint_fast8_t> constructDoraIndicators_(std::uint_fast8_t seat) const;
std::pair<std::uint_fast8_t, std::uint_fast8_t> checkDaSanyuanPao_() const;
std::pair<std::uint_fast8_t, std::uint_fast8_t> checkDaSixiPao_() const;
std::pair<std::uint_fast8_t, std::uint_fast8_t> calculateHand_(
std::uint_fast8_t seat, std::uint_fast8_t hupai, long config) const;
void settleLizhiDeposits_();
public:
std::pair<std::uint_fast16_t, std::uint_fast8_t> onZimo();
std::pair<std::uint_fast8_t, std::uint_fast16_t>
onDapai(std::uint_fast8_t tile, bool moqi, bool lizhi);
std::uint_fast16_t onChi(std::uint_fast8_t encode);
std::uint_fast16_t onPeng(std::uint_fast8_t encode);
void onDaminggang();
std::uint_fast16_t onAngang(
std::uint_fast8_t zimo_tile, std::uint_fast8_t encode);
std::uint_fast16_t onJiagang(
std::uint_fast8_t zimo_tile, std::uint_fast8_t encode);
bool onHule(std::uint_fast8_t zimo_tile, boost::python::dict result);
bool onHuangpaiPingju(boost::python::dict result);
void onLiuju(boost::python::dict result);
private:
Kanachan::GameState &game_state_;
std::array<std::int_fast32_t, 4u> initial_scores_{
std::numeric_limits<std::int_fast32_t>::max(),
std::numeric_limits<std::int_fast32_t>::max(),
std::numeric_limits<std::int_fast32_t>::max(),
std::numeric_limits<std::int_fast32_t>::max()
};
Kanachan::Paishan paishan_;
std::uint_fast8_t zimo_index_ = 4u * 13u;
std::uint_fast8_t lingshang_zimo_count_ = 0u;
std::uint_fast8_t gang_dora_count_ = 0u;
std::array<Kanachan::Shoupai, 4u> shoupai_list_;
std::uint_fast8_t seat_;
std::array<std::uint_fast8_t, 4u> lizhi_list_{ 0u, 0u, 0u, 0u };
std::uint_fast8_t lizhi_delayed_ = 0u;
bool angang_dora_delayed_ = false;
bool minggang_dora_delayed_ = false;
std::array<bool, 4u> first_zimo_ = { true, true, true, true };
std::array<bool, 4u> yifa_ = { false, false, false, false };
bool lingshang_kaihua_delayed_ = false;
bool qianggang_delayed_ = false;
std::array<bool, 4u> rong_delayed_ = { false, false, false, false };
std::vector<std::uint_fast16_t> progression_;
}; // class RoundState
} // namespace Kanachan
#endif // !defined(KANACHAN_SIMULATION_ROUND_STATE_HPP_INCLUDE_GUARD)