/nix/store/rr0r40cw3mzzbz0sxrnkvnrjpzb82wpc-j27cjzgh5nmq3y8k6hwa6zpi3qgcjia8-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/hand.h" |
10 | | #include "types/sets.h" |
11 | | #include "types/yaku.h" |
12 | | |
13 | | namespace mahjong::yaku { |
14 | | bool isTriplePon(const GameState& /* state */, const Hand& hand, |
15 | 18 | const std::vector<const mahjong::Node*>& branch) { |
16 | 18 | std::array<bool, 9> bamboo_pon = {}; |
17 | 18 | std::array<bool, 9> char_pon = {}; |
18 | 18 | std::array<bool, 9> pin_pon = {}; |
19 | 122 | for (const auto* node : branch) { |
20 | 122 | if (node->type() == SetType::kPon) { |
21 | 36 | if (node->start().getSuit() == Piece::Type::kBambooSuit) { |
22 | 1 | bamboo_pon.at(node->start().getPieceNum() - 1) = true; |
23 | 1 | } |
24 | 36 | if (node->start().getSuit() == Piece::Type::kCharacterSuit) { |
25 | 17 | char_pon.at(node->start().getPieceNum() - 1) = true; |
26 | 17 | } |
27 | 36 | if (node->start().getSuit() == Piece::Type::kPinSuit) { |
28 | 9 | pin_pon.at(node->start().getPieceNum() - 1) = true; |
29 | 9 | } |
30 | 36 | } |
31 | 122 | } |
32 | 18 | for (const auto& meld : hand.melds_range()) { |
33 | 0 | if (meld.type >= SetType::kPon) { |
34 | 0 | if (meld.start.getSuit() == Piece::Type::kBambooSuit) { |
35 | 0 | bamboo_pon.at(meld.start.getPieceNum() - 1) = true; |
36 | 0 | } |
37 | 0 | if (meld.start.getSuit() == Piece::Type::kCharacterSuit) { |
38 | 0 | char_pon.at(meld.start.getPieceNum() - 1) = true; |
39 | 0 | } |
40 | 0 | if (meld.start.getSuit() == Piece::Type::kPinSuit) { |
41 | 0 | pin_pon.at(meld.start.getPieceNum() - 1) = true; |
42 | 0 | } |
43 | 0 | } |
44 | 0 | } |
45 | 171 | for (int i = 0; i < 9; i++) { |
46 | 154 | if (bamboo_pon.at(i) && char_pon.at(i) && pin_pon.at(i)) { |
47 | 1 | return true; |
48 | 1 | } |
49 | 154 | } |
50 | 17 | return false; |
51 | 18 | } |
52 | | |
53 | | REGISTER_YAKU({ |
54 | | .id = "triplepon", |
55 | | .name = "Triple Pon", |
56 | | .type = Yaku::kOpen, |
57 | | .value = 2, |
58 | | .is_yaku_func = yaku::isTriplePon, |
59 | | }); |
60 | | } // namespace mahjong::yaku |