/nix/store/i1aar97n7b4yf8rk94p66if25brfvvdx-gqvzl8a5pvrg3xj44q0msrndcripi8dk-source/src/statefunctions/gamestates/replacement.cc
Line | Count | Source |
1 | | #include <array> |
2 | | #include <cstdint> |
3 | | #include <memory> |
4 | | #include <vector> |
5 | | |
6 | | #include "statefunctions/router.h" |
7 | | #include "statefunctions/stateutilities.h" |
8 | | #include "types/event.h" |
9 | | #include "types/gamestate.h" |
10 | | #include "types/piecetype.h" |
11 | | #include "types/statefunction.h" |
12 | | #include "types/walls.h" |
13 | | |
14 | | namespace mahjong { |
15 | | namespace { |
16 | 0 | std::unique_ptr<GameState> Replacement(std::unique_ptr<GameState> state) { |
17 | 0 | const Piece draw = state->walls.TakeReplacementTile(); |
18 | 0 | state->hands.at(state->currentPlayer).live.push_back(draw); |
19 | 0 | state->hands.at(state->currentPlayer).sort(); |
20 | 0 | state->pendingPiece = draw; |
21 | |
|
22 | 0 | AlertPlayers(*state, |
23 | 0 | Event{ |
24 | 0 | .type = Event::kDora, // type |
25 | 0 | .player = -1, // player |
26 | 0 | .piece = static_cast<int16_t>( |
27 | 0 | state->walls.GetDoras().back().toUint8_t()), // piece |
28 | 0 | .decision = false, // decision |
29 | 0 | }); |
30 | |
|
31 | 0 | state->nextState = StateFunctionType::kPlayerHand; |
32 | 0 | return state; |
33 | 0 | } |
34 | | } // namespace |
35 | | |
36 | | REGISTER_ROUTE(Replacement, StateFunctionType::kReplacement); |
37 | | } // namespace mahjong |