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/kandiscard.cc
Line
Count
Source
1
#include <array>
2
#include <cstdint>
3
#include <memory>
4
5
#include "statefunctions/decisionfunction.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> KanDiscard(std::unique_ptr<GameState> state) {
18
0
  std::array<bool, 4> need_decision = {false, false, false, false};
19
0
  for (const Hand& hand : state->hands) {
20
0
    if (hand.id == state->currentPlayer) {
21
0
      continue;
22
0
    }
23
0
    if (CanRon(*state, hand)) {
24
0
      need_decision.at(hand.id) = true;
25
0
      state->controllers.at(state->currentPlayer)
26
0
          ->ReceiveEvent(Event{
27
0
              .type = Event::kRon,             // type
28
0
              .player = state->currentPlayer,  // player
29
0
              .piece = static_cast<int16_t>(
30
0
                  state->pendingPiece.toUint8_t()),  // piece
31
0
              .decision = true,                      // decision
32
0
          });
33
0
    }
34
0
  }
35
36
0
  bool have_ronned = false;
37
0
  for (Hand& hand : state->hands) {
38
0
    if (need_decision.at(hand.id)) {
39
0
      const Event temp_decision =
40
0
          GetValidDecisionOrThrow(*state, hand, /*inHand=*/false);
41
0
      if (temp_decision.type == Event::kRon) {
42
0
        hand.hasRonned = true;
43
0
        have_ronned = true;
44
0
      }
45
0
    }
46
0
  }
47
48
0
  if (have_ronned) {
49
0
    state->nextState = StateFunctionType::kRon;
50
0
  } else {
51
0
    state->nextState = StateFunctionType::kReplacement;
52
0
  }
53
54
0
  return state;
55
0
}
56
}  // namespace
57
58
REGISTER_ROUTE(KanDiscard, StateFunctionType::kKanDiscard);
59
}  // namespace mahjong