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