GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 11 / 0 / 11
Functions: 100.0% 9 / 0 / 9
Branches: 71.4% 10 / 0 / 14

src/game/mahjong/data/lib.hpp
Line Branch Exec Source
1 #pragma once
2
3 #include "../../../util/traits/others/lib.hpp"
4
5 namespace tifa_libs {
6
7 struct mahjong_card {
8 static CEXP strn valid_rank = "123456789";
9 static CEXP strn valid_suit = "MPSZB";
10
11 static CEXP u32 rank_value(chr c) NE {
12 auto ret = valid_rank.find(c);
13 assert(ret != strn::npos);
14 return (u32)ret + 1;
15 }
16
17 859 static CEXP mahjong_card decode(u32 code) NE { return {code % 9 + 1, valid_suit[code / 9]}; }
18 4303 ND CEXP u32 encode() CNE { return (u32)valid_suit.find(suit) * 9 + rank - 1; }
19 ND CEXP bool valid() CNE {
20 retif_((rank < 1 || rank > 9), false);
21 retif_((suit == 'Z' && rank > 7), false);
22 retif_((suit == 'B' && rank > 8), false);
23 return valid_suit.find(suit) != strn::npos;
24 }
25
26 static CEXP bool is_mixed_terminal(u32 code) NE { return code <= 33 && (27 <= code || code % 9 == 0 || code % 9 == 8); }
27 static CEXP bool is_terminal(u32 code) NE { return code <= 26 && (code % 9 == 0 || code % 9 == 8); }
28
3/4
✓ Branch 0 taken 22050 times.
✓ Branch 1 taken 838999 times.
✓ Branch 2 taken 22050 times.
✗ Branch 3 not taken.
861049 static CEXP bool is_honor(u32 code) NE { return 27 <= code && code <= 33; }
29 static CEXP bool is_wind(u32 code) NE { return 27 <= code && code <= 30; }
30 static CEXP bool is_dragon(u32 code) NE { return 31 <= code && code <= 33; }
31 static CEXP bool is_bonus(u32 code) NE { return 36 <= code && code <= 43; }
32 static CEXP bool is_flower(u32 code) NE { return 36 <= code && code <= 39; }
33 static CEXP bool is_season(u32 code) NE { return 40 <= code && code <= 43; }
34
35 306 ND CEXP bool is_bonus() CNE { return suit == 'B'; }
36 ND CEXP bool is_mixed_terminal() CNE { return suit != 'B' && (suit == 'Z' || rank == 1 || rank == 9); }
37 ND CEXP bool is_terminal() CNE { return suit != 'Z' && is_mixed_terminal(); }
38 ND CEXP bool is_honor() CNE { return suit == 'Z'; }
39 ND CEXP bool is_wind() CNE { return suit == 'Z' && rank <= 4; }
40 ND CEXP bool is_dragon() CNE { return suit == 'Z' && rank > 4; }
41 ND CEXP bool is_flower() CNE { return suit == 'B' && rank <= 4; }
42 ND CEXP bool is_season() CNE { return suit == 'B' && rank > 4; }
43
44 14795 friend CEXP auto operator<=>(mahjong_card l, mahjong_card r) NE {
45
5/6
✓ Branch 0 taken 6714 times.
✓ Branch 1 taken 8081 times.
✓ Branch 2 taken 3808 times.
✓ Branch 3 taken 2906 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3808 times.
14795 if (l.suit == r.suit) return l.rank <=> r.rank;
46
2/4
✓ Branch 2 taken 8081 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8081 times.
✗ Branch 5 not taken.
8081 return valid_suit.find(l.suit) <=> valid_rank.find(r.suit);
47 }
48 friend CEXP bool operator==(mahjong_card l, mahjong_card r) NE { return std::is_eq(l <=> r); }
49 friend auto& operator>>(tifa_libs::istream_c auto& is, mahjong_card& p) NE {
50 chr c;
51 (is >> c >> p.suit), p.rank = rank_value(c), p.suit = toupper(p.suit);
52 return is;
53 }
54
55 u32 rank;
56 chr suit;
57 };
58 namespace literals {
59 81 CEXP mahjong_card operator""_mjm(unsigned long long x) NE { return {(u32)x, 'M'}; }
60 81 CEXP mahjong_card operator""_mjp(unsigned long long x) NE { return {(u32)x, 'P'}; }
61 81 CEXP mahjong_card operator""_mjs(unsigned long long x) NE { return {(u32)x, 'S'}; }
62 63 CEXP mahjong_card operator""_mjz(unsigned long long x) NE { return {(u32)x, 'Z'}; }
63 CEXP mahjong_card operator""_mjb(unsigned long long x) NE { return {(u32)x, 'B'}; }
64 } // namespace literals
65
66 } // namespace tifa_libs
67