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