/nix/store/i1aar97n7b4yf8rk94p66if25brfvvdx-gqvzl8a5pvrg3xj44q0msrndcripi8dk-source/src/scoring/yakus/triplepon.cc
Line | Count | Source |
1 | | #include "scoring/yakus/triplepon.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 isTriplePon(const GameState& state, int player, |
14 | 17 | const std::vector<const mahjong::Node*>& branch) { |
15 | 17 | std::array<bool, 9> bamboo_pon = {}; |
16 | 17 | std::array<bool, 9> char_pon = {}; |
17 | 17 | std::array<bool, 9> pin_pon = {}; |
18 | 117 | for (const auto* node : branch) { |
19 | 117 | if (node->type() == SetType::kPon) { |
20 | 36 | if (node->start().getSuit() == Piece::Type::kBambooSuit) { |
21 | 1 | bamboo_pon.at(node->start().getPieceNum() - 1) = true; |
22 | 1 | } |
23 | 36 | if (node->start().getSuit() == Piece::Type::kCharacterSuit) { |
24 | 17 | char_pon.at(node->start().getPieceNum() - 1) = true; |
25 | 17 | } |
26 | 36 | if (node->start().getSuit() == Piece::Type::kPinSuit) { |
27 | 9 | pin_pon.at(node->start().getPieceNum() - 1) = true; |
28 | 9 | } |
29 | 36 | } |
30 | 117 | } |
31 | 17 | for (const auto& meld : state.hands.at(player).melds) { |
32 | 0 | if (meld.type >= SetType::kPon) { |
33 | 0 | if (meld.start.getSuit() == Piece::Type::kBambooSuit) { |
34 | 0 | bamboo_pon.at(meld.start.getPieceNum() - 1) = true; |
35 | 0 | } |
36 | 0 | if (meld.start.getSuit() == Piece::Type::kCharacterSuit) { |
37 | 0 | char_pon.at(meld.start.getPieceNum() - 1) = true; |
38 | 0 | } |
39 | 0 | if (meld.start.getSuit() == Piece::Type::kPinSuit) { |
40 | 0 | pin_pon.at(meld.start.getPieceNum() - 1) = true; |
41 | 0 | } |
42 | 0 | } |
43 | 0 | } |
44 | 161 | for (int i = 0; i < 9; i++) { |
45 | 145 | if (bamboo_pon.at(i) && char_pon.at(i) && pin_pon.at(i)) { |
46 | 1 | return true; |
47 | 1 | } |
48 | 145 | } |
49 | 16 | return false; |
50 | 17 | } |
51 | | |
52 | | REGISTER_YAKU({ |
53 | | .id = "triplepon", |
54 | | .name = "Triple Pon", |
55 | | .type = Yaku::kOpen, |
56 | | .value = 2, |
57 | | .is_yaku_func = yaku::isTriplePon, |
58 | | }); |
59 | | } // namespace mahjong::yaku |