/nix/store/i1aar97n7b4yf8rk94p66if25brfvvdx-gqvzl8a5pvrg3xj44q0msrndcripi8dk-source/src/scoring/yakus/twicepuredoublechi.cc
Line | Count | Source |
1 | | #include "scoring/yakus/twicepuredoublechi.h" |
2 | | |
3 | | #include <cstddef> |
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 isTwicePureDoubleChi(const GameState& state, int player, |
14 | 8 | const std::vector<const mahjong::Node*>& branch) { |
15 | 8 | if (state.hands.at(player).open) { |
16 | 4 | return false; |
17 | 4 | } |
18 | 4 | int pairs = 0; |
19 | 25 | for (size_t i = 0; i < branch.size(); i++) { |
20 | 21 | if (branch.at(i)->type() != SetType::kChi) { |
21 | 9 | continue; |
22 | 9 | } |
23 | 32 | for (size_t j = i + 1; j < branch.size(); j++) { |
24 | 20 | if (branch.at(j)->type() == SetType::kChi && |
25 | 20 | branch.at(i)->start() == branch.at(j)->start()) { |
26 | 4 | pairs++; |
27 | 4 | } |
28 | 20 | } |
29 | 12 | } |
30 | 4 | return pairs == 2; |
31 | 8 | } |
32 | | |
33 | | REGISTER_YAKU({ |
34 | | .id = "twicepuredoublechi", |
35 | | .name = "Twice Pure Double Chi", |
36 | | .type = Yaku::kClosed, |
37 | | .value = 3, |
38 | | .is_yaku_func = yaku::isTwicePureDoubleChi, |
39 | | }); |
40 | | } // namespace mahjong::yaku |