Skip to content

Commit bf355f7

Browse files
authored
refactor: Fix lint collapsible-if (SIM102) (#173)
* refactor: Fix lint collapsible-if (SIM102) * refactor: Remove unnecessary parentheses * refactor: Merge duplicated sashikomi yaku conditions
1 parent 34cf7bd commit bf355f7

File tree

5 files changed

+28
-30
lines changed

5 files changed

+28
-30
lines changed

mahjong/hand_calculating/fu.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ def calculate_fu(
111111
continue
112112

113113
# chi: count matches for win_group open/closed detection
114-
if win_group_is_chi and grp_len == 3:
115-
if grp[0] == wg0 and grp[1] == wg1 and grp[2] == wg2:
116-
win_group_chi_count_in_hand += 1
114+
if win_group_is_chi and grp_len == 3 and grp[0] == wg0 and grp[1] == wg1 and grp[2] == wg2:
115+
win_group_chi_count_in_hand += 1
117116

118117
# preprocess melds into a fixed-size state table (tile_34 -> bit flags)
119118
is_open_hand = False

mahjong/hand_calculating/hand.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,8 @@ def estimate_hand_value(
195195
kan_sets = [x for x in hand if is_kan(x)]
196196
chi_sets = [x for x in hand if is_chi(x)]
197197

198-
if config.is_tsumo:
199-
if not is_open_hand:
200-
hand_yaku.append(config.yaku.tsumo)
198+
if config.is_tsumo and not is_open_hand:
199+
hand_yaku.append(config.yaku.tsumo)
201200

202201
if is_pinfu:
203202
hand_yaku.append(config.yaku.pinfu)
@@ -234,7 +233,7 @@ def estimate_hand_value(
234233
if (
235234
not config.is_tsumo
236235
and config.options.has_sashikomi_yakuman
237-
and ((config.yaku.daburu_open_riichi in hand_yaku) or (config.yaku.open_riichi in hand_yaku))
236+
and (config.yaku.daburu_open_riichi in hand_yaku or config.yaku.open_riichi in hand_yaku)
238237
):
239238
hand_yaku.append(config.yaku.sashikomi)
240239

@@ -449,14 +448,13 @@ def estimate_hand_value(
449448
else:
450449
hand_yaku.append(config.yaku.kokushi)
451450

452-
if not config.is_tsumo and config.options.has_sashikomi_yakuman:
453-
if config.is_riichi and not config.is_daburu_riichi:
454-
if config.is_open_riichi:
455-
hand_yaku.append(config.yaku.sashikomi)
456-
457-
if config.is_daburu_riichi:
458-
if config.is_open_riichi:
459-
hand_yaku.append(config.yaku.sashikomi)
451+
if (
452+
not config.is_tsumo
453+
and config.options.has_sashikomi_yakuman
454+
and config.is_open_riichi
455+
and (config.is_daburu_riichi or config.is_riichi)
456+
):
457+
hand_yaku.append(config.yaku.sashikomi)
460458

461459
if config.is_renhou and config.options.renhou_as_yakuman:
462460
hand_yaku.append(config.yaku.renhou_yakuman)

mahjong/hand_calculating/scores.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,22 @@ def aotenjou_filter_yaku(hand_yaku: MutableSequence[Yaku] | MutableSet[Yaku], co
200200
# for daisuushi we need to remove toitoi
201201
hand_yaku.remove(config.yaku.toitoi)
202202

203-
if config.yaku.suuankou in hand_yaku or config.yaku.suuankou_tanki in hand_yaku:
203+
if (
204+
config.yaku.suuankou in hand_yaku or config.yaku.suuankou_tanki in hand_yaku
205+
) and config.yaku.toitoi in hand_yaku:
204206
# for suu ankou we need to remove toitoi and sanankou (sanankou is already removed by default)
205-
if config.yaku.toitoi in hand_yaku:
206-
# toitoi is "optional" in closed suukantsu, maybe a bug? or toitoi is not given when it's kans?
207-
hand_yaku.remove(config.yaku.toitoi)
207+
# toitoi is "optional" in closed suukantsu, maybe a bug? or toitoi is not given when it's kans?
208+
hand_yaku.remove(config.yaku.toitoi)
208209

209210
if config.yaku.chinroto in hand_yaku:
210211
# for chinroto we need to remove toitoi and honroto
211212
hand_yaku.remove(config.yaku.toitoi)
212213
hand_yaku.remove(config.yaku.honroto)
213214

214-
if config.yaku.suukantsu in hand_yaku:
215+
if config.yaku.suukantsu in hand_yaku and config.yaku.toitoi in hand_yaku:
215216
# for suukantsu we need to remove toitoi and sankantsu (sankantsu is already removed by default)
216-
if config.yaku.toitoi in hand_yaku:
217-
# same as above?
218-
hand_yaku.remove(config.yaku.toitoi)
217+
# same as above?
218+
hand_yaku.remove(config.yaku.toitoi)
219219

220220
if config.yaku.chuuren_poutou in hand_yaku or config.yaku.daburu_chuuren_poutou in hand_yaku:
221221
# for chuuren poutou we need to remove chinitsu
@@ -232,7 +232,6 @@ def aotenjou_filter_yaku(hand_yaku: MutableSequence[Yaku] | MutableSet[Yaku], co
232232
if config.yaku.chiitoitsu in hand_yaku:
233233
hand_yaku.remove(config.yaku.chiitoitsu)
234234

235-
if config.yaku.ryuisou in hand_yaku:
235+
if config.yaku.ryuisou in hand_yaku and config.yaku.honitsu in hand_yaku:
236236
# for ryuisou we need to remove honitsu, if it is there
237-
if config.yaku.honitsu in hand_yaku:
238-
hand_yaku.remove(config.yaku.honitsu)
237+
hand_yaku.remove(config.yaku.honitsu)

mahjong/shanten.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,12 @@ def _update_result(self) -> None:
211211
n_mentsu_kouho = self._number_melds + self._number_tatsu
212212
if self._number_pairs:
213213
n_mentsu_kouho += self._number_pairs - 1
214-
elif self._flag_four_copies and self._flag_isolated_tiles:
215-
if (self._flag_four_copies | self._flag_isolated_tiles) == self._flag_four_copies:
216-
ret_shanten += 1
214+
elif (
215+
self._flag_four_copies
216+
and self._flag_isolated_tiles
217+
and (self._flag_four_copies | self._flag_isolated_tiles) == self._flag_four_copies
218+
):
219+
ret_shanten += 1
217220

218221
if n_mentsu_kouho > 4:
219222
ret_shanten += n_mentsu_kouho - 4

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ ignore = [
8686
# Will be fixed later
8787
"COM812",
8888
"PLW1641",
89-
"SIM102",
9089
"SIM108",
9190
"PLW2901",
9291
"PGH003",

0 commit comments

Comments
 (0)