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/ron.cc
Line
Count
Source
1
#include <array>
2
#include <cstdint>
3
#include <memory>
4
#include <vector>
5
6
#include "scoring/scoring.h"
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/statefunction.h"
13
14
namespace mahjong {
15
16
namespace {
17
0
std::unique_ptr<GameState> Ron(std::unique_ptr<GameState> state) {
18
0
  state->hands.at(state->lastCaller).live.push_back(state->pendingPiece);
19
0
  state->hands.at(state->lastCaller).sort();
20
21
0
  std::array<int, 4> basic_points = {};
22
0
  if (state->hands.at(state->currentPlayer).riichi &&
23
0
      state->hands.at(state->currentPlayer).discards.size() ==
24
0
          state->hands.at(state->currentPlayer).riichiPieceDiscard) {
25
0
    state->riichiSticks--;
26
0
    state->hands.at(state->currentPlayer).riichi = false;
27
0
  }
28
0
  for (int player = 0; player < 4; player++) {
29
0
    if (state->hasRonned.at(player)) {
30
0
      AlertPlayers(*state, Event{
31
0
                               .type = Event::kRon,  // type
32
0
                               .player = player,     // player
33
0
                               .piece = static_cast<int16_t>(
34
0
                                   state->pendingPiece.toUint8_t()),  // piece
35
0
                               .decision = false,  // decision
36
0
                           });
37
0
      basic_points.at(player) = getBasicPoints(scoreHand(*state, player));
38
0
    }
39
0
    if (state->hands.at(player).riichi) {
40
0
      state->scores.at(player) -= 1000;
41
0
    }
42
0
  }
43
0
  int payment = 0;
44
0
  for (int i = 0; i < 4; i++) {
45
0
    const int player = (state->roundNum + i) % 4;
46
0
    if (state->hasRonned.at(player)) {
47
0
      state->scores.at(player) += 1000 * state->riichiSticks;
48
0
      state->riichiSticks = 0;
49
0
      state->scores.at(player) += 300 * state->counters;
50
0
      payment += 300 * state->counters;
51
0
      if (i == state->roundNum % 4) {
52
0
        int amount = 6 * basic_points.at(player);
53
0
        if ((amount % 100) != 0) {
54
0
          amount = amount + (100 - (amount % 100));
55
0
        }
56
0
        state->scores.at(player) += amount;
57
0
        payment += amount;
58
0
      } else {
59
0
        int amount = 4 * basic_points.at(player);
60
0
        if ((amount % 100) != 0) {
61
0
          amount = amount + (100 - (amount % 100));
62
0
        }
63
0
        state->scores.at(player) += amount;
64
0
        payment += amount;
65
0
      }
66
0
    }
67
0
  }
68
69
0
  state->scores.at(state->currentPlayer) -= payment;
70
71
0
  if (state->hasRonned.at(state->roundNum % 4)) {
72
0
    state->counters++;
73
0
  } else {
74
0
    state->roundNum++;
75
0
    state->counters = 0;
76
0
  }
77
78
0
  bool allzeros = true;
79
0
  for (int i = 0; i < 4; i++) {
80
0
    if (state->scores.at(i) != 0) {
81
0
      allzeros = false;
82
0
    }
83
0
  }
84
0
  if (allzeros) {
85
0
    throw "oof";
86
0
  }
87
88
0
  state->nextState = StateFunctionType::kRoundEnd;
89
0
  return state;
90
0
}
91
}  // namespace
92
93
REGISTER_ROUTE(Ron, StateFunctionType::kRon);
94
}  // namespace mahjong