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