/nix/store/i1aar97n7b4yf8rk94p66if25brfvvdx-gqvzl8a5pvrg3xj44q0msrndcripi8dk-source/src/statefunctions/gamestates/roundstart.cc
Line | Count | Source |
1 | | #include <array> |
2 | | #include <cstddef> |
3 | | #include <cstdint> |
4 | | #include <memory> |
5 | | #include <vector> |
6 | | |
7 | | #include "controllers/playercontroller.h" |
8 | | #include "statefunctions/router.h" |
9 | | #include "statefunctions/stateutilities.h" |
10 | | #include "types/event.h" |
11 | | #include "types/gamestate.h" |
12 | | #include "types/hand.h" |
13 | | #include "types/statefunction.h" |
14 | | #include "types/walls.h" |
15 | | #include "types/winds.h" |
16 | | |
17 | | namespace mahjong { |
18 | | |
19 | | namespace { |
20 | 12 | std::unique_ptr<GameState> RoundStart(std::unique_ptr<GameState> state) { |
21 | 12 | state->walls = Walls(state->g); |
22 | 60 | for (size_t i = 0; i < 4; i++) { |
23 | 48 | auto hand = state->walls.TakeHand(); |
24 | 48 | state->players.at(i).controller->RoundStart( |
25 | 48 | hand, static_cast<Wind>((i + 3 * (state->roundNum % 4)) % 4), |
26 | 48 | (state->roundNum > 3) ? kSouth : kEast); |
27 | 48 | state->hands.at(i) = Hand(hand); |
28 | 48 | } |
29 | | |
30 | 12 | AlertPlayers(*state, |
31 | 12 | Event{ |
32 | 12 | .type = Event::kDora, // type |
33 | 12 | .player = -1, // player |
34 | 12 | .piece = static_cast<int16_t>( |
35 | 12 | state->walls.GetDoras()[0].toUint8_t()), // piece |
36 | 12 | .decision = false, // decision |
37 | 12 | }); |
38 | | |
39 | 12 | state->nextState = StateFunctionType::kDraw; |
40 | 12 | return state; |
41 | 12 | } |
42 | | } // namespace |
43 | | |
44 | | REGISTER_ROUTE(RoundStart, StateFunctionType::kRoundStart); |
45 | | } // namespace mahjong |