Skip to content

Commit

Permalink
更新向听单测
Browse files Browse the repository at this point in the history
  • Loading branch information
ssttkkl committed Oct 28, 2022
1 parent 0842e19 commit 81c9465
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 232 deletions.
36 changes: 18 additions & 18 deletions mahjong_utils/shanten.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def kokushi_shanten(tiles: List[Tile]) -> ShantenResult:
return ShantenResult(type="kokushi",
shanten=shanten,
hands=hands,
advance=advance,
advance=None,
discard_to_advance=discard_to_advance)


Expand Down Expand Up @@ -263,43 +263,43 @@ def shanten(tiles: List[Tile], furo: Optional[List[Furo]] = None) -> UnionShante
hands = list()

if not with_got:
advance = set()
discard_to_advance = None
advance_aggregated = set()
discard_to_advance_aggregated = None

if regular.shanten == shanten:
advance |= regular.advance
advance_aggregated |= regular.advance
hands += regular.hands
if chitoi.shanten == shanten:
advance |= chitoi.advance
advance_aggregated |= chitoi.advance
hands += chitoi.hands
if kokushi.shanten == shanten:
advance |= kokushi.advance
advance_aggregated |= kokushi.advance
hands += kokushi.hands
else:
advance = None
discard_to_advance = dict()
advance_aggregated = None
discard_to_advance_aggregated = dict()

if regular.shanten == shanten:
hands += regular.hands
for discard, advance in regular.discard_to_advance.items():
if discard not in discard_to_advance:
discard_to_advance[discard] = set()
discard_to_advance[discard] |= advance
if discard not in discard_to_advance_aggregated:
discard_to_advance_aggregated[discard] = set()
discard_to_advance_aggregated[discard] |= advance
if chitoi.shanten == shanten:
hands += chitoi.hands
for discard, advance in chitoi.discard_to_advance.items():
if discard not in discard_to_advance:
discard_to_advance[discard] = set()
discard_to_advance[discard] |= advance
if discard not in discard_to_advance_aggregated:
discard_to_advance_aggregated[discard] = set()
discard_to_advance_aggregated[discard] |= advance
if kokushi.shanten == shanten:
hands += kokushi.hands
for discard, advance in kokushi.discard_to_advance.items():
if discard not in discard_to_advance:
discard_to_advance[discard] = set()
discard_to_advance[discard] |= advance
if discard not in discard_to_advance_aggregated:
discard_to_advance_aggregated[discard] = set()
discard_to_advance_aggregated[discard] |= advance

return UnionShantenResult(type="union", shanten=shanten, hands=hands,
advance=advance, discard_to_advance=discard_to_advance,
advance=advance_aggregated, discard_to_advance=discard_to_advance_aggregated,
regular=regular, chitoi=None, kokushi=None)


Expand Down
17 changes: 1 addition & 16 deletions test/test_hora.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from mahjong_utils.hora import build_hora
from mahjong_utils.models.furo import parse_furo
from mahjong_utils.models.tile import tile, parse_tiles
from mahjong_utils.models.wind import Wind
Expand All @@ -8,8 +9,6 @@


def test_build_hora():
from mahjong_utils.hora import build_hora

hora = build_hora(parse_tiles("1112356778899p"), None, tile("4p"), True, dora=4, extra_yaku={richi})

assert hora.yaku == {richi, ittsu, chinitsu, ipe, tsumo, pinhu}
Expand All @@ -20,8 +19,6 @@ def test_build_hora():


def test_build_hora_2():
from mahjong_utils.hora import build_hora

hora = build_hora(parse_tiles("1112356789999p"), None, tile("4p"), True, extra_yaku={richi})

assert hora.yaku == {churen}
Expand All @@ -31,8 +28,6 @@ def test_build_hora_2():


def test_build_hora_3():
from mahjong_utils.hora import build_hora

hora = build_hora(parse_tiles("1345556m111z2m"), [parse_furo("789m")], tile("2m"), True)

assert hora.yaku == {ittsu, honitsu}
Expand All @@ -43,8 +38,6 @@ def test_build_hora_3():


def test_build_hora_4():
from mahjong_utils.hora import build_hora

hora = build_hora(parse_tiles("12323467m11z5m"), [parse_furo("789p")], tile("5m"), True, dora=13)

assert len(hora.yaku) == 0
Expand All @@ -55,8 +48,6 @@ def test_build_hora_4():


def test_build_hora_5():
from mahjong_utils.hora import build_hora

hora = build_hora(parse_tiles("1112223334445z"), None, tile("5z"), True, extra_yaku={tenhou})

assert hora.yaku == {tsuiso, daisushi, suanko_tanki, tenhou}
Expand All @@ -66,8 +57,6 @@ def test_build_hora_5():


def test_build_hora_6():
from mahjong_utils.hora import build_hora

hora = build_hora(parse_tiles("6z"),
[parse_furo("3333s"), parse_furo("2222s"), parse_furo("0440s"), parse_furo("8888s")], tile("6z"),
True)
Expand All @@ -79,8 +68,6 @@ def test_build_hora_6():


def test_build_hora_7():
from mahjong_utils.hora import build_hora

hora = build_hora(parse_tiles("6z"),
[parse_furo("0330s"), parse_furo("0220s"), parse_furo("0440s"), parse_furo("0880s")], tile("6z"),
True)
Expand All @@ -92,8 +79,6 @@ def test_build_hora_7():


def test_build_hora_8():
from mahjong_utils.hora import build_hora

hora = build_hora(parse_tiles("111333555z22s44p"), None, tile("2s"), False, dora=4,
self_wind=Wind.west, round_wind=Wind.east,
extra_yaku={richi, ippatsu})
Expand Down
Loading

0 comments on commit 81c9465

Please sign in to comment.