/nix/store/rr0r40cw3mzzbz0sxrnkvnrjpzb82wpc-j27cjzgh5nmq3y8k6hwa6zpi3qgcjia8-source/src/statefunctions/gamestates/pon.cc
Line | Count | Source |
1 | | #include <array> |
2 | | #include <cstdint> |
3 | | #include <iostream> |
4 | | #include <memory> |
5 | | |
6 | | #include "statefunctions/router.h" |
7 | | #include "statefunctions/stateutilities.h" |
8 | | #include "types/event.h" |
9 | | #include "types/gamestate.h" |
10 | | #include "types/hand.h" |
11 | | #include "types/meld.h" |
12 | | #include "types/piecetype.h" |
13 | | #include "types/sets.h" |
14 | | #include "types/statefunction.h" |
15 | | |
16 | | namespace mahjong { |
17 | | |
18 | | namespace { |
19 | 1 | std::unique_ptr<GameState> Pon(std::unique_ptr<GameState> state) { |
20 | 1 | if (Hand& hand = state->hands[state->currentPlayer]; |
21 | 1 | hand.riichi && hand.discards_count == hand.riichiPieceDiscard) { |
22 | 0 | hand.riichiPieceDiscard++; |
23 | 0 | } |
24 | | |
25 | 1 | state->currentPlayer = state->lastCaller; |
26 | 1 | state->lastCall = state->turnNum; |
27 | 1 | state->concealedKan = false; |
28 | 1 | state->turnNum++; |
29 | | |
30 | 1 | Hand& hand = state->hands.at(state->currentPlayer); |
31 | 1 | hand.open = true; |
32 | 1 | if (RemovePieces(hand, state->pendingPiece, |
33 | 1 | /*count=*/2) != 2) { |
34 | 0 | std::cerr << "Not enough pieces to remove in Pon" << '\n'; |
35 | 0 | state->nextState = StateFunctionType::kError; |
36 | 0 | return state; |
37 | 0 | } |
38 | 1 | hand.melds[hand.meld_count++] = Meld{ |
39 | 1 | .type = SetType::kPon, |
40 | 1 | .start = state->pendingPiece, |
41 | 1 | }; |
42 | | |
43 | 1 | AlertPlayers(*state, Event{ |
44 | 1 | .type = Event::kPon, // type |
45 | 1 | .player = state->lastCaller, // player |
46 | 1 | .piece = static_cast<int16_t>( |
47 | 1 | state->pendingPiece.toUint8_t()), // piece |
48 | 1 | .decision = false, // decision |
49 | 1 | }); |
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 |