/nix/store/rr0r40cw3mzzbz0sxrnkvnrjpzb82wpc-j27cjzgh5nmq3y8k6hwa6zpi3qgcjia8-source/src/scoring/yakus/halfflush.cc
Line | Count | Source |
1 | | #include "scoring/yakus/halfflush.h" |
2 | | |
3 | | #include <vector> |
4 | | |
5 | | #include "analysis/handnode.h" |
6 | | #include "scoring/yakus.h" |
7 | | #include "scoring/yakus/fullflush.h" |
8 | | #include "types/gamestate.h" |
9 | | #include "types/hand.h" |
10 | | #include "types/yaku.h" |
11 | | |
12 | | namespace mahjong::yaku { |
13 | | bool isHalfFlush(const GameState& state, const Hand& hand, |
14 | 11 | const std::vector<const mahjong::Node*>& /*branch*/) { |
15 | 11 | const int suit = hand.live[0].getSuit(); |
16 | 11 | bool honors = false; |
17 | 97 | for (const auto& piece : hand.live_range()) { |
18 | 97 | if (piece.isHonor()) { |
19 | 12 | honors = true; |
20 | 12 | continue; |
21 | 12 | } |
22 | 85 | if (suit != piece.getSuit()) { |
23 | 5 | return false; |
24 | 5 | } |
25 | 85 | } |
26 | 6 | for (const auto& meld : hand.melds_range()) { |
27 | 5 | if (meld.start.isHonor()) { |
28 | 0 | honors = true; |
29 | 0 | continue; |
30 | 0 | } |
31 | 5 | if (suit != meld.start.getSuit()) { |
32 | 0 | return false; |
33 | 0 | } |
34 | 5 | } |
35 | | // Full Flush scores instead of Half Flush. |
36 | 6 | return honors && !isFullFlush(state, hand); |
37 | 6 | } |
38 | | |
39 | | REGISTER_YAKU({ |
40 | | .id = "halfflush", |
41 | | .name = "Half Flush", |
42 | | .type = Yaku::kBonusWhenClosed, |
43 | | .value = 1, |
44 | | .is_yaku_func = yaku::isHalfFlush, |
45 | | }); |
46 | | } // namespace mahjong::yaku |