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/halfflush.cc
Line
Count
Source
1
#include "scoring/yakus/halfflush.h"
2
3
#include <vector>
4
5
#include "analysis/handnode.h"
6
#include "scoring/yakus.h"
7
#include "scoring/yakus/fullflush.h"
8
#include "types/gamestate.h"
9
#include "types/yaku.h"
10
11
namespace mahjong::yaku {
12
bool isHalfFlush(const GameState& state, int player,
13
10
                 const std::vector<const mahjong::Node*>& /*branch*/) {
14
10
  const int suit = state.hands.at(player).live.front().getSuit();
15
10
  bool honors = false;
16
93
  for (const auto& piece : state.hands.at(player).live) {
17
93
    if (piece.isHonor()) {
18
12
      honors = true;
19
12
      continue;
20
12
    }
21
81
    if (suit != piece.getSuit()) {
22
4
      return false;
23
4
    }
24
81
  }
25
6
  for (const auto& meld : state.hands.at(player).melds) {
26
5
    if (meld.start.isHonor()) {
27
0
      honors = true;
28
0
      continue;
29
0
    }
30
5
    if (suit != meld.start.getSuit()) {
31
0
      return false;
32
0
    }
33
5
  }
34
  // Full Flush scores instead of Half Flush.
35
6
  return honors && !isFullFlush(state, player);
36
6
}
37
38
REGISTER_YAKU({
39
    .id = "halfflush",
40
    .name = "Half Flush",
41
    .type = Yaku::kBonusWhenClosed,
42
    .value = 1,
43
    .is_yaku_func = yaku::isHalfFlush,
44
});
45
}  // namespace mahjong::yaku