/nix/store/rr0r40cw3mzzbz0sxrnkvnrjpzb82wpc-j27cjzgh5nmq3y8k6hwa6zpi3qgcjia8-source/src/scoring/yakus/terminalsinallsets.cc
Line | Count | Source |
1 | | #include "scoring/yakus/terminalsinallsets.h" |
2 | | |
3 | | #include <vector> |
4 | | |
5 | | #include "analysis/handnode.h" |
6 | | #include "scoring/yakus.h" |
7 | | #include "types/gamestate.h" |
8 | | #include "types/hand.h" |
9 | | #include "types/sets.h" |
10 | | #include "types/yaku.h" |
11 | | |
12 | | namespace mahjong::yaku { |
13 | | bool isTerminalsInAllSets(const GameState& /*state*/, const Hand& hand, |
14 | 7 | const std::vector<const mahjong::Node*>& branch) { |
15 | 20 | for (const auto* node : branch) { |
16 | 20 | switch (node->type()) { |
17 | 0 | case SetType::kSingle: |
18 | 0 | return false; |
19 | 10 | case SetType::kChi: |
20 | 10 | if (!node->start().isTerminal() && !(node->start() + 2).isTerminal()) { |
21 | 1 | return false; |
22 | 1 | } |
23 | 9 | break; |
24 | 9 | case SetType::kPair: |
25 | 10 | case SetType::kPon: |
26 | 10 | case SetType::kKan: |
27 | 10 | case SetType::kConcealedKan: |
28 | 10 | if (!node->start().isTerminal()) { |
29 | 4 | return false; |
30 | 4 | } |
31 | 6 | break; |
32 | 20 | } |
33 | 20 | } |
34 | 2 | for (const auto& meld : hand.melds_range()) { |
35 | 1 | switch (meld.type) { |
36 | 0 | case SetType::kSingle: |
37 | 0 | return false; |
38 | 1 | case SetType::kChi: |
39 | 1 | if (!meld.start.isTerminal() && !(meld.start + 2).isTerminal()) { |
40 | 0 | return false; |
41 | 0 | } |
42 | 1 | break; |
43 | 1 | case SetType::kPair: |
44 | 0 | case SetType::kKan: |
45 | 0 | case SetType::kConcealedKan: |
46 | 0 | case SetType::kPon: |
47 | 0 | if (!meld.start.isTerminal()) { |
48 | 0 | return false; |
49 | 0 | } |
50 | 0 | break; |
51 | 1 | } |
52 | 1 | } |
53 | 2 | return true; |
54 | 2 | } |
55 | | |
56 | | REGISTER_YAKU({ |
57 | | .id = "terminalsinallsets", |
58 | | .name = "Terminals in all Sets", |
59 | | .type = Yaku::kBonusWhenClosed, |
60 | | .value = 2, |
61 | | .is_yaku_func = yaku::isTerminalsInAllSets, |
62 | | }); |
63 | | } // namespace mahjong::yaku |