Coverage Report

Created: 2026-11-14 03:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/nix/store/rr0r40cw3mzzbz0sxrnkvnrjpzb82wpc-j27cjzgh5nmq3y8k6hwa6zpi3qgcjia8-source/src/statefunctions/gamestates/ron.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> Ron(std::unique_ptr<GameState> state) {
18
0
  if (Hand& hand = state->hands[state->currentPlayer];
19
0
      hand.riichi && hand.discards_count == hand.riichiPieceDiscard) {
20
0
    state->riichiSticks--;
21
0
    hand.riichi = false;
22
0
  }
23
24
0
  state->hands[state->lastCaller]
25
0
      .live[state->hands[state->lastCaller].live_count++] = state->pendingPiece;
26
27
0
  std::array<int, 4> basic_points = {};
28
0
  for (Hand& hand : state->hands) {
29
0
    if (hand.hasRonned) {
30
0
      AlertPlayers(*state, Event{
31
0
                               .type = Event::kRon,  // type
32
0
                               .player = hand.id,    // 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(hand.id) = getBasicPoints(scoreHand(*state, hand));
38
0
    }
39
0
    if (hand.riichi) {
40
0
      hand.score -= 1000;
41
0
    }
42
0
  }
43
0
  int payment = 0;
44
0
  for (Hand& hand : state->hands) {
45
0
    if (hand.hasRonned) {
46
0
      hand.score += 1000 * state->riichiSticks;
47
0
      state->riichiSticks = 0;
48
0
      hand.score += 300 * state->counters;
49
0
      payment += 300 * state->counters;
50
0
      if (hand.id == state->roundNum % 4) {
51
0
        int amount = 6 * basic_points.at(hand.id);
52
0
        if ((amount % 100) != 0) {
53
0
          amount = amount + (100 - (amount % 100));
54
0
        }
55
0
        hand.score += amount;
56
0
        payment += amount;
57
0
      } else {
58
0
        int amount = 4 * basic_points.at(hand.id);
59
0
        if ((amount % 100) != 0) {
60
0
          amount = amount + (100 - (amount % 100));
61
0
        }
62
0
        hand.score += amount;
63
0
        payment += amount;
64
0
      }
65
0
    }
66
0
  }
67
68
0
  state->hands[state->currentPlayer].score -= payment;
69
70
0
  if (state->hands[state->roundNum % 4].hasRonned) {
71
0
    state->counters++;
72
0
  } else {
73
0
    state->roundNum++;
74
0
    state->counters = 0;
75
0
  }
76
77
0
  bool allzeros = true;
78
0
  for (int i = 0; i < 4; i++) {
79
0
    if (state->hands[i].score != 0) {
80
0
      allzeros = false;
81
0
    }
82
0
  }
83
0
  if (allzeros) {
84
0
    throw "oof";
85
0
  }
86
87
0
  state->nextState = StateFunctionType::kRoundEnd;
88
0
  return state;
89
0
}
90
}  // namespace
91
92
REGISTER_ROUTE(Ron, StateFunctionType::kRon);
93
}  // namespace mahjong