/nix/store/i1aar97n7b4yf8rk94p66if25brfvvdx-gqvzl8a5pvrg3xj44q0msrndcripi8dk-source/src/statefunctions/gamestates/kandiscard.cc
Line | Count | Source |
1 | | #include <array> |
2 | | #include <cstdint> |
3 | | #include <memory> |
4 | | |
5 | | #include "controllers/playercontroller.h" |
6 | | #include "statefunctions/decisionfunction.h" |
7 | | #include "statefunctions/router.h" |
8 | | #include "statefunctions/stateutilities.h" |
9 | | #include "types/event.h" |
10 | | #include "types/gamestate.h" |
11 | | #include "types/piecetype.h" |
12 | | #include "types/statefunction.h" |
13 | | |
14 | | namespace mahjong { |
15 | | |
16 | | namespace { |
17 | 0 | std::unique_ptr<GameState> KanDiscard(std::unique_ptr<GameState> state) { |
18 | 0 | std::array<bool, 4> need_decision = {false, false, false, false}; |
19 | 0 | for (int player = 0; player < 4; player++) { |
20 | 0 | if (player == state->currentPlayer) { |
21 | 0 | continue; |
22 | 0 | } |
23 | 0 | if (CanRon(*state, player)) { |
24 | 0 | need_decision.at(player) = true; |
25 | 0 | state->players.at(state->currentPlayer) |
26 | 0 | .controller->ReceiveEvent(Event{ |
27 | 0 | .type = Event::kRon, // type |
28 | 0 | .player = state->currentPlayer, // player |
29 | 0 | .piece = static_cast<int16_t>( |
30 | 0 | state->pendingPiece.toUint8_t()), // piece |
31 | 0 | .decision = true, // decision |
32 | 0 | }); |
33 | 0 | } |
34 | 0 | } |
35 | |
|
36 | 0 | bool have_ronned = false; |
37 | 0 | for (int i = 0; i < 4; i++) { |
38 | 0 | if (need_decision.at(i)) { |
39 | 0 | const Event temp_decision = |
40 | 0 | GetValidDecisionOrThrow(*state, i, /*inHand=*/false); |
41 | 0 | if (temp_decision.type == Event::kRon) { |
42 | 0 | state->hasRonned.at(i) = true; |
43 | 0 | have_ronned = true; |
44 | 0 | } |
45 | 0 | } |
46 | 0 | } |
47 | |
|
48 | 0 | if (have_ronned) { |
49 | 0 | state->nextState = StateFunctionType::kRon; |
50 | 0 | } else { |
51 | 0 | state->nextState = StateFunctionType::kReplacement; |
52 | 0 | } |
53 | |
|
54 | 0 | return state; |
55 | 0 | } |
56 | | } // namespace |
57 | | |
58 | | REGISTER_ROUTE(KanDiscard, StateFunctionType::kKanDiscard); |
59 | | } // namespace mahjong |