/nix/store/rr0r40cw3mzzbz0sxrnkvnrjpzb82wpc-j27cjzgh5nmq3y8k6hwa6zpi3qgcjia8-source/src/statefunctions/gamestates/tsumo.cc
Line | Count | Source |
1 | | #include <array> |
2 | | #include <cstdint> |
3 | | #include <memory> |
4 | | |
5 | | #include "scoring/scoring.h" |
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/piecetype.h" |
12 | | #include "types/statefunction.h" |
13 | | |
14 | | namespace mahjong { |
15 | | |
16 | | namespace { |
17 | 0 | std::unique_ptr<GameState> Tsumo(std::unique_ptr<GameState> state) { |
18 | 0 | AlertPlayers(*state, Event{ |
19 | 0 | .type = Event::kTsumo, // type |
20 | 0 | .player = state->currentPlayer, // player |
21 | 0 | .piece = static_cast<int16_t>( |
22 | 0 | state->pendingPiece.toUint8_t()), // piece |
23 | 0 | .decision = false, // decision |
24 | 0 | }); |
25 | |
|
26 | 0 | Hand& winning_hand = state->hands[state->currentPlayer]; |
27 | 0 | const int basic_points = getBasicPoints(scoreHand(*state, winning_hand)); |
28 | 0 | winning_hand.score += state->riichiSticks * 1000; |
29 | 0 | state->riichiSticks = 0; |
30 | 0 | winning_hand.score += state->counters * 300; |
31 | |
|
32 | 0 | for (Hand& hand : state->hands) { |
33 | 0 | if (hand.id == winning_hand.id) { |
34 | 0 | if (hand.riichi) { |
35 | 0 | hand.score -= 1000; |
36 | 0 | } |
37 | 0 | continue; |
38 | 0 | } |
39 | 0 | int amount = 0; |
40 | 0 | if (state->currentPlayer == state->roundNum % 4 || |
41 | 0 | hand.id == state->roundNum % 4) { |
42 | 0 | amount = 2 * basic_points; |
43 | 0 | } else { |
44 | 0 | amount = basic_points; |
45 | 0 | } |
46 | 0 | if ((amount % 100) != 0) { |
47 | 0 | amount = amount + (100 - (amount % 100)); |
48 | 0 | } |
49 | 0 | hand.score -= amount; |
50 | 0 | hand.score -= state->counters * 100; |
51 | 0 | if (hand.riichi) { |
52 | 0 | hand.score -= 1000; |
53 | 0 | } |
54 | 0 | winning_hand.score += amount; |
55 | 0 | } |
56 | |
|
57 | 0 | if (state->currentPlayer == state->roundNum % 4) { |
58 | 0 | state->counters++; |
59 | 0 | } else { |
60 | 0 | state->roundNum++; |
61 | 0 | state->counters = 0; |
62 | 0 | } |
63 | 0 | state->nextState = StateFunctionType::kRoundEnd; |
64 | 0 | return state; |
65 | 0 | } |
66 | | } // namespace |
67 | | |
68 | | REGISTER_ROUTE(Tsumo, StateFunctionType::kTsumo); |
69 | | } // namespace mahjong |