Coverage Report

Created: 2025-09-03 03:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/nix/store/i1aar97n7b4yf8rk94p66if25brfvvdx-gqvzl8a5pvrg3xj44q0msrndcripi8dk-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/piecetype.h"
11
#include "types/statefunction.h"
12
13
namespace mahjong {
14
15
namespace {
16
0
std::unique_ptr<GameState> Tsumo(std::unique_ptr<GameState> state) {
17
0
  AlertPlayers(*state, Event{
18
0
                           .type = Event::kTsumo,           // type
19
0
                           .player = state->currentPlayer,  // player
20
0
                           .piece = static_cast<int16_t>(
21
0
                               state->pendingPiece.toUint8_t()),  // piece
22
0
                           .decision = false,                     // decision
23
0
                       });
24
0
  const int basic_points =
25
0
      getBasicPoints(scoreHand(*state, state->currentPlayer));
26
0
  state->scores.at(state->currentPlayer) += state->riichiSticks * 1000;
27
0
  state->riichiSticks = 0;
28
0
  state->scores.at(state->currentPlayer) += state->counters * 300;
29
30
0
  for (int i = 0; i < 4; i++) {
31
0
    if (i == state->currentPlayer) {
32
0
      if (state->hands.at(state->currentPlayer).riichi) {
33
0
        state->scores.at(i) -= 1000;
34
0
      }
35
0
      continue;
36
0
    }
37
0
    int amount = 0;
38
0
    if (state->currentPlayer == state->roundNum % 4 ||
39
0
        i == state->roundNum % 4) {
40
0
      amount = 2 * basic_points;
41
0
    } else {
42
0
      amount = basic_points;
43
0
    }
44
0
    if ((amount % 100) != 0) {
45
0
      amount = amount + (100 - (amount % 100));
46
0
    }
47
0
    state->scores.at(i) -= amount;
48
0
    state->scores.at(i) -= state->counters * 100;
49
0
    if (state->hands.at(i).riichi) {
50
0
      state->scores.at(i) -= 1000;
51
0
    }
52
0
    state->scores.at(state->currentPlayer) += amount;
53
0
  }
54
55
0
  if (state->currentPlayer == state->roundNum % 4) {
56
0
    state->counters++;
57
0
  } else {
58
0
    state->roundNum++;
59
0
    state->counters = 0;
60
0
  }
61
0
  state->nextState = StateFunctionType::kRoundEnd;
62
0
  return state;
63
0
}
64
}  // namespace
65
66
REGISTER_ROUTE(Tsumo, StateFunctionType::kTsumo);
67
}  // namespace mahjong