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/scoring/yakus/purestraight.cc
Line
Count
Source
1
#include "scoring/yakus/purestraight.h"
2
3
#include <array>
4
#include <vector>
5
6
#include "analysis/handnode.h"
7
#include "scoring/yakus.h"
8
#include "types/gamestate.h"
9
#include "types/hand.h"
10
#include "types/sets.h"
11
#include "types/yaku.h"
12
13
namespace mahjong::yaku {
14
bool isPureStraight(const GameState& /* state */, const Hand& hand,
15
7
                    const std::vector<const mahjong::Node*>& branch) {
16
7
  const int k_firstchistart = 1;
17
7
  const int k_secondchistart = 4;
18
7
  const int k_thirdchistart = 7;
19
7
  std::array<bool, 3> bamboo_chi = {};
20
7
  std::array<bool, 3> char_chi = {};
21
7
  std::array<bool, 3> pin_chi = {};
22
39
  for (const auto* node : branch) {
23
39
    if (node->type() == SetType::kChi) {
24
18
      int ind = 0;
25
18
      if (node->start().getPieceNum() == k_firstchistart) {
26
7
        ind = 0;
27
11
      } else if (node->start().getPieceNum() == k_secondchistart) {
28
7
        ind = 1;
29
7
      } else if (node->start().getPieceNum() == k_thirdchistart) {
30
2
        ind = 2;
31
2
      } else {
32
2
        continue;
33
2
      }
34
16
      if (node->start().getSuit() == Piece::Type::kBambooSuit) {
35
0
        bamboo_chi.at(ind) = true;
36
0
      }
37
16
      if (node->start().getSuit() == Piece::Type::kCharacterSuit) {
38
15
        char_chi.at(ind) = true;
39
15
      }
40
16
      if (node->start().getSuit() == Piece::Type::kPinSuit) {
41
1
        pin_chi.at(ind) = true;
42
1
      }
43
16
    }
44
39
  }
45
7
  for (const auto& meld : hand.melds_range()) {
46
0
    if (meld.type == SetType::kChi) {
47
0
      int ind = 0;
48
0
      if (meld.start.getPieceNum() == k_firstchistart) {
49
0
        ind = 0;
50
0
      } else if (meld.start.getPieceNum() == k_secondchistart) {
51
0
        ind = 1;
52
0
      } else if (meld.start.getPieceNum() == k_thirdchistart) {
53
0
        ind = 2;
54
0
      } else {
55
0
        continue;
56
0
      }
57
0
      if (meld.start.getSuit() == Piece::Type::kBambooSuit) {
58
0
        bamboo_chi.at(ind) = true;
59
0
      }
60
0
      if (meld.start.getSuit() == Piece::Type::kCharacterSuit) {
61
0
        char_chi.at(ind) = true;
62
0
      }
63
0
      if (meld.start.getSuit() == Piece::Type::kPinSuit) {
64
0
        pin_chi.at(ind) = true;
65
0
      }
66
0
    }
67
0
  }
68
7
  if (bamboo_chi[0] && bamboo_chi[1] && bamboo_chi[2]) {
69
0
    return true;
70
0
  }
71
7
  if (char_chi[0] && char_chi[1] && char_chi[2]) {
72
2
    return true;
73
2
  }
74
5
  if (pin_chi[0] && pin_chi[1] && pin_chi[2]) {
75
0
    return true;
76
0
  }
77
5
  return false;
78
5
}
79
80
REGISTER_YAKU({
81
    .id = "purestraight",
82
    .name = "Pure Straight",
83
    .type = Yaku::kBonusWhenClosed,
84
    .value = 1,
85
    .is_yaku_func = yaku::isPureStraight,
86
});
87
}  // namespace mahjong::yaku