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/scoring/yakus/outsidehand.cc
Line
Count
Source
1
#include "scoring/yakus/outsidehand.h"
2
3
#include <vector>
4
5
#include "analysis/handnode.h"
6
#include "scoring/yakus.h"
7
#include "scoring/yakus/allterminalsandhonors.h"
8
#include "scoring/yakus/terminalsinallsets.h"
9
#include "types/gamestate.h"
10
#include "types/sets.h"
11
#include "types/yaku.h"
12
13
namespace mahjong::yaku {
14
bool isOutsideHand(const GameState& state, int player,
15
26
                   const std::vector<const mahjong::Node*>& branch) {
16
26
  bool chi = false;
17
138
  for (const auto* node : branch) {
18
138
    if (node->type() == SetType::kChi) {
19
12
      if (node->start().isTerminal() || (node->start() + 2).isTerminal()) {
20
4
        chi = true;
21
8
      } else {
22
8
        return false;
23
8
      }
24
126
    } else {
25
126
      if (!node->start().isTerminal() && !node->start().isHonor()) {
26
0
        return false;
27
0
      }
28
126
    }
29
138
  }
30
18
  for (const auto& meld : state.hands.at(player).melds) {
31
0
    if (meld.type == SetType::kChi) {
32
0
      if (meld.start.isTerminal() || (meld.start + 2).isTerminal()) {
33
0
        chi = true;
34
0
      } else {
35
0
        return false;
36
0
      }
37
0
    } else {
38
0
      if (!meld.start.isTerminal() && !meld.start.isHonor()) {
39
0
        return false;
40
0
      }
41
0
    }
42
0
  }
43
  // Terminals in all Sets and All Terminals and Honors are more valuable and score instead of Outside Hand.
44
18
  return chi && !isTerminalsInAllSets(state, player, branch) &&
45
18
         !isAllTerminalsAndHonors(state, player);
46
18
}
47
48
REGISTER_YAKU({
49
    .id = "outsidehand",
50
    .name = "Outside Hand",
51
    .type = Yaku::kBonusWhenClosed,
52
    .value = 1,
53
    .is_yaku_func = yaku::isOutsideHand,
54
});
55
}  // namespace mahjong::yaku