/nix/store/i1aar97n7b4yf8rk94p66if25brfvvdx-gqvzl8a5pvrg3xj44q0msrndcripi8dk-source/src/statefunctions/gamestates/pon.cc
Line | Count | Source |
1 | | #include <array> |
2 | | #include <cstdint> |
3 | | #include <iostream> |
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/piecetype.h" |
12 | | #include "types/sets.h" |
13 | | #include "types/statefunction.h" |
14 | | |
15 | | namespace mahjong { |
16 | | |
17 | | namespace { |
18 | 1 | std::unique_ptr<GameState> Pon(std::unique_ptr<GameState> state) { |
19 | 1 | state->hands.at(state->lastCaller).open = true; |
20 | | |
21 | 1 | AlertPlayers(*state, Event{ |
22 | 1 | .type = Event::kPon, // type |
23 | 1 | .player = state->lastCaller, // player |
24 | 1 | .piece = static_cast<int16_t>( |
25 | 1 | state->pendingPiece.toUint8_t()), // piece |
26 | 1 | .decision = false, // decision |
27 | 1 | }); |
28 | | |
29 | 1 | if (state->hands.at(state->currentPlayer).riichi && |
30 | 1 | state->hands.at(state->currentPlayer).discards.size() == |
31 | 0 | state->hands.at(state->currentPlayer).riichiPieceDiscard) { |
32 | 0 | state->hands.at(state->currentPlayer).riichiPieceDiscard++; |
33 | 0 | } |
34 | | |
35 | 1 | state->currentPlayer = state->lastCaller; |
36 | 1 | state->hands.at(state->lastCaller).live.push_back(state->pendingPiece); |
37 | 1 | state->hands.at(state->lastCaller).sort(); |
38 | 1 | state->lastCall = state->turnNum; |
39 | 1 | state->concealedKan = false; |
40 | 1 | state->turnNum++; |
41 | | |
42 | 1 | if (RemovePieces(*state, state->lastCaller, state->pendingPiece, |
43 | 1 | /*count=*/3) != 3) { |
44 | 0 | std::cerr << "Not enough pieces to remove in Pon" << '\n'; |
45 | 0 | state->nextState = StateFunctionType::kError; |
46 | 0 | return state; |
47 | 0 | } |
48 | 1 | state->hands.at(state->lastCaller) |
49 | 1 | .melds.push_back({SetType::kPon, state->pendingPiece}); |
50 | | |
51 | 1 | state->pendingPiece = AskForDiscard(*state); |
52 | | |
53 | 1 | state->nextState = StateFunctionType::kDiscard; |
54 | 1 | return state; |
55 | 1 | } |
56 | | } // namespace |
57 | | |
58 | | REGISTER_ROUTE(Pon, StateFunctionType::kPon); |
59 | | } // namespace mahjong |