forked from Cryolite/kanachan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jiagang.cpp
57 lines (45 loc) · 1.59 KB
/
jiagang.cpp
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
#include "simulation/jiagang.hpp"
#include "simulation/hule.hpp"
#include "simulation/zimo.hpp"
#include "simulation/round_state.hpp"
#include "common/assert.hpp"
#include "common/throw.hpp"
#include <boost/python/dict.hpp>
#include <functional>
#include <any>
#include <utility>
#include <stdexcept>
#include <limits>
#include <cstdint>
namespace {
using std::placeholders::_1;
namespace python = boost::python;
} // namespace `anonymous`
namespace Kanachan{
std::any jiagang(
Kanachan::RoundState &round_state, std::uint_fast8_t const zimo_tile,
std::uint_fast8_t const encode, python::dict result)
{
if (zimo_tile >= 37u) {
KANACHAN_THROW<std::invalid_argument>(_1) << static_cast<unsigned>(zimo_tile);
}
if (encode >= 37u) {
KANACHAN_THROW<std::invalid_argument>(_1) << static_cast<unsigned>(encode);
}
std::uint_fast16_t const action = round_state.onJiagang(zimo_tile, encode);
if (action == std::numeric_limits<std::uint_fast16_t>::max()) {
// Si Gang San Le (四槓散了) の成立は打牌直後.
auto zimo = std::bind(&Kanachan::zimo, std::ref(round_state), result);
std::function<std::any()> next_step(std::move(zimo));
return next_step;
}
if (action == 543u) {
// Qiang Gang (槍槓)
std::uint_fast8_t const zimo_tile = std::numeric_limits<std::uint_fast8_t>::max();
auto hule = std::bind(&Kanachan::hule, std::ref(round_state), zimo_tile, result);
std::function<std::any()> next_step(std::move(hule));
return next_step;
}
KANACHAN_THROW<std::logic_error>(_1) << action << ": An invalid action on jia gang.";
}
} // namespace Kanachan