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/exhaust.cc
Line
Count
Source
1
#include <array>
2
#include <memory>
3
#include <vector>
4
5
#include "analysis/util.h"
6
#include "statefunctions/router.h"
7
#include "types/gamestate.h"
8
#include "types/statefunction.h"
9
10
namespace mahjong {
11
12
namespace {
13
0
std::unique_ptr<GameState> Exhaust(std::unique_ptr<GameState> state) {
14
0
  std::array<int, 4> winning_players = {};
15
0
  int total_winners = 0;
16
0
  for (int i = 0; i < 4; i++) {
17
    // TODO(#21): Implement no tenpai if you have all pieces of your wait
18
0
    if (state->hands.at(i).riichi ||
19
0
        !isInTenpai13Pieces(state->hands.at(i).live, /*allWaits=*/false)
20
0
             .empty()) {
21
0
      winning_players.at(i) = 1;
22
0
      total_winners++;
23
0
    }
24
0
  }
25
0
  state->counters++;
26
0
  if (winning_players.at(state->roundNum % 4) == 0) {
27
0
    state->roundNum++;
28
0
  }
29
0
  if (total_winners < 4 && total_winners > 0) {
30
0
    for (int i = 0; i < 4; i++) {
31
0
      if (winning_players.at(i) != 0) {
32
0
        state->scores.at(i) = 3000 / total_winners;
33
0
      } else {
34
0
        switch (total_winners) {
35
0
          case 1:
36
0
            state->scores.at(i) = -1000;
37
0
            break;
38
0
          case 2:
39
0
            state->scores.at(i) = -1500;
40
0
            break;
41
0
          case 3:
42
0
            state->scores.at(i) = -3000;
43
0
            break;
44
0
          default:
45
0
            break;
46
0
        }
47
0
      }
48
0
      if (state->hands.at(i).riichi) {
49
0
        state->scores.at(i) -= 1000;
50
0
      }
51
0
    }
52
0
  }
53
0
  state->nextState = StateFunctionType::kRoundEnd;
54
0
  return state;
55
0
}
56
}  // namespace
57
58
REGISTER_ROUTE(Exhaust, StateFunctionType::kExhaust);
59
}  // namespace mahjong