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/decisionfunction.cc
Line
Count
Source
1
#include "statefunctions/decisionfunction.h"
2
3
#include <algorithm>
4
#include <array>
5
6
#include "analysis/util.h"
7
#include "scoring/scoring.h"
8
#include "scoring/yakus/thirteenorphans.h"
9
#include "statefunctions/stateutilities.h"
10
#include "types/gamestate.h"
11
#include "types/hand.h"
12
#include "types/piecetype.h"
13
#include "types/sets.h"
14
#include "types/walls.h"
15
16
namespace mahjong {
17
18
// TODO(#18): "I really hate this" - alice
19
34
bool CanRon(const GameState& state, const Hand& hand) {
20
  // If the pending piece is your discard, you can't Ron
21
892
  for (const auto& piece : hand.discards) {
22
892
    if (state.pendingPiece == piece) {
23
1
      return false;
24
1
    }
25
892
  }
26
27
  // Build the theoretical hand
28
33
  Hand tmp_hand = hand;
29
33
  tmp_hand.live[tmp_hand.live_count++] = state.pendingPiece;
30
31
  // If this Ron is occurring due to a concealed kan discard,
32
33
  if (state.concealedKan) {
33
    // If it happens to be a ron for a thirteen orphans,
34
    // it's allowed and you can ron otherwise, you can't.
35
0
    return yaku::isThirteenOrphans(state, hand);
36
0
  }
37
  // if not a concealed kan, check if it's complete
38
33
  return isComplete(state, hand);
39
33
}
40
41
33
bool CanKan(const GameState& state, const Hand& hand) {
42
33
  if (Walls::GetRemainingPieces(state) == 0) {
43
0
    return false;
44
0
  }
45
33
  if (hand.riichi) {
46
0
    return false;
47
0
  }
48
33
  return CountPieces(hand, state.pendingPiece) == 3;
49
33
}
50
51
34
bool CanPon(const GameState& state, const Hand& hand) {
52
34
  if (hand.riichi) {
53
0
    return false;
54
0
  }
55
34
  return CountPieces(hand, state.pendingPiece) == 2;
56
34
}
57
58
39
bool CanChi(const GameState& state, const Hand& hand) {
59
39
  if (hand.riichi) {
60
0
    return false;
61
0
  }
62
39
  if (state.pendingPiece.isHonor()) {
63
10
    return false;
64
10
  }
65
29
  if (((state.currentPlayer + 1) % 4) != hand.id) {
66
17
    return false;
67
17
  }
68
12
  if (CountPieces(hand, state.pendingPiece - 2) > 0 &&
69
12
      CountPieces(hand, state.pendingPiece - 1) > 0) {
70
2
    return true;
71
2
  }
72
10
  if (CountPieces(hand, state.pendingPiece - 1) > 0 &&
73
10
      CountPieces(hand, state.pendingPiece + 1) > 0) {
74
1
    return true;
75
1
  }
76
9
  if (CountPieces(hand, state.pendingPiece + 1) > 0 &&
77
9
      CountPieces(hand, state.pendingPiece + 2) > 0) {
78
3
    return true;
79
3
  }
80
6
  return false;
81
9
}
82
83
10
bool CanTsumo(const GameState& state, const Hand& hand) {
84
10
  return isComplete(state, hand);
85
10
}
86
87
10
bool CanConvertedKan(const GameState& state, const Hand& hand) {
88
10
  if (Walls::GetRemainingPieces(state) == 0) {
89
0
    return false;
90
0
  }
91
10
  return std::any_of(
92
10
      hand.melds.begin(), hand.melds.begin() + hand.meld_count, [&](auto meld) {
93
0
        return meld.type == SetType::kPon && CountPieces(hand, meld.start) == 1;
94
0
      });
95
10
}
96
97
10
bool CanConcealedKan(const GameState& state, const Hand& hand) {
98
10
  if (Walls::GetRemainingPieces(state) == 0) {
99
0
    return false;
100
0
  }
101
  // TODO(#19): Allow riichi concealed kan under the right conditions
102
10
  if (hand.riichi) {
103
0
    return false;
104
0
  }
105
10
  return CountPieces(hand, state.pendingPiece) == 4;
106
10
}
107
108
10
bool CanRiichi(const GameState& /*unused*/, const Hand& hand) {
109
10
  if (hand.riichi) {
110
0
    return false;
111
0
  }
112
10
  if (hand.open) {
113
0
    return false;
114
0
  }
115
10
  return !getPossibleWaits(hand).empty();
116
10
}
117
}  // namespace mahjong