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/roundend.cc
Line
Count
Source
1
#include <array>
2
#include <cstdint>
3
#include <memory>
4
#include <vector>
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/piecetype.h"
12
#include "types/statefunction.h"
13
14
namespace mahjong {
15
16
namespace {
17
0
std::unique_ptr<GameState> RoundEnd(std::unique_ptr<GameState> state) {
18
0
  state->currentPlayer = -1;
19
0
  state->turnNum = -1;
20
0
  state->lastCall = -1;
21
0
  state->concealedKan = false;
22
0
  state->lastCaller = -1;
23
0
  state->pendingPiece = Piece(Piece::kError);
24
0
  for (auto& hand : state->hands) {
25
0
    hand.hasRonned = false;
26
0
  }
27
28
0
  state->controllers = {};
29
30
0
  const int last_round = 3;
31
0
  if (state->roundNum > last_round && state->riichiSticks > 0) {
32
0
    std::vector<int> winners;
33
0
    int highscore = -100000;
34
0
    for (const Hand& hand : state->hands) {
35
0
      if (hand.points + hand.score > highscore) {
36
0
        highscore = hand.points + hand.score;
37
0
        winners.clear();
38
0
        winners.push_back(hand.id);
39
0
      } else if (hand.points + hand.score == highscore) {
40
0
        winners.push_back(hand.id);
41
0
      }
42
0
    }
43
0
    for (const auto& winner : winners) {
44
0
      state->hands.at(winner).score +=
45
0
          (state->riichiSticks * 1000) / winners.size();
46
0
    }
47
0
  }
48
49
  // TODO(#17): Scoring
50
0
  for (Hand& hand : state->hands) {
51
0
    AlertPlayers(*state, Event{.type = Event::kPointDiff,
52
0
                               .player = hand.id,
53
0
                               .piece = static_cast<int16_t>(hand.score / 100),
54
0
                               .decision = false});
55
0
    hand.points += hand.score;
56
0
    hand.score = 0;
57
0
  }
58
59
  // TODO (#14): for now naively increment the round number
60
0
  state->roundNum++;
61
62
  // TODO (#16): East wind only for now
63
0
  if (state->roundNum > last_round) {
64
0
    state->nextState = StateFunctionType::kGameEnd;
65
0
  } else {
66
0
    state->nextState = StateFunctionType::kRoundStart;
67
0
  }
68
0
  return state;
69
0
}
70
}  // namespace
71
72
REGISTER_ROUTE(RoundEnd, StateFunctionType::kRoundEnd);
73
}  // namespace mahjong