-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathangang.cpp
58 lines (46 loc) · 1.61 KB
/
angang.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
58
#include "simulation/angang.hpp"
#include "simulation/hule.hpp"
#include "simulation/zimo.hpp"
#include "simulation/game_log.hpp"
#include "simulation/round_state.hpp"
#include "common/throw.hpp"
#include <functional>
#include <any>
#include <utility>
#include <stdexcept>
#include <limits>
#include <cstdint>
namespace {
using std::placeholders::_1;
} // namespace `anonymous`
namespace Kanachan{
std::any angang(
Kanachan::RoundState &round_state, std::uint_fast8_t const zimo_tile,
std::uint_fast8_t const encode, Kanachan::GameLog &game_log)
{
if (zimo_tile >= 37u) {
KANACHAN_THROW<std::invalid_argument>(_1) << static_cast<unsigned>(zimo_tile);
}
if (encode >= 34u) {
KANACHAN_THROW<std::invalid_argument>(_1) << static_cast<unsigned>(encode);
}
std::uint_fast16_t const action = round_state.onAngang(zimo_tile, encode, game_log);
if (action == UINT_FAST16_MAX) {
// Si Gang San Le (四槓散了) の成立は打牌直後.
auto zimo = std::bind(&Kanachan::zimo, std::ref(round_state), std::ref(game_log));
std::function<std::any()> next_step(std::move(zimo));
return next_step;
}
if (action == 543u) {
// Qiang Gang (槍槓)
std::uint_fast8_t const zimo_tile_ = UINT_FAST8_MAX;
auto hule = std::bind(&Kanachan::hule, std::ref(round_state), zimo_tile_, std::ref(game_log));
std::function<std::any()> next_step(std::move(hule));
return next_step;
}
KANACHAN_THROW<std::logic_error>(_1) << action << ": An invalid action on an gang.";
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type"
}
#pragma GCC diagnostic pop
} // namespace Kanachan