Skip to content

Commit

Permalink
mjproto からmjscoreへのテストケースを増やす2 (mjx-project#598)
Browse files Browse the repository at this point in the history
* feat: create correspond yakus in order to return doras together

* refactor: change determin_ura_doras_list

* refactor: refactor the test logic the previous case was passed

* refactor:refactor parse_discards to deal with tumogiri_riichi

* refactor: refactor check_uradoras , correspond_yakus, winner_yakus to deal with dora representation

* refactor: rename the fanctions to emphasize the hierarchy

* feat: create transform_red_stolen and transform_red_open

* Add files via upload

* Add files via upload

* add test for has_red is_red_stolen

* feat: create transform_red_stolen transform_red_open

* refactor transform_red_open

* refactor : incorporated transform_red_stolen and transform_red_open to open_stolen_tile_type and open_tile_types

* Rename test12010102910gm-00a9-0000-cdb9804c.json to 2010102910gm-00a9-0000-cdb9804c.json

* Rename test12010102910gm-00a9-0000-cdb9804c.mjlog to 2010102910gm-00a9-0000-cdb9804c.mjlog

* refactor: refactor to pass checks

* refactor: refactor doctest

* refactor: refactor doctest

* refactor: reformat mjconvert/mjscore_encoder.py

* feat: create function is_oya to determin if winner is oya

* refactor: refactor __change_action_fmt typo

* feat: add test for kan_closed and fix to pass test

* feat: change _change_action_format to respond kan_closed but not suceed

* change_func_nm

* Add files via upload

* Add files via upload

* refactor refactor parse_discards

* remove dupulication

* reformat file
  • Loading branch information
nissymori authored Dec 23, 2020
1 parent 1b4650e commit ac45edc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
34 changes: 26 additions & 8 deletions mjconvert/mjconvert/mjscore_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ def _change_action_format(bits: int) -> str: # TODO カン
elif event_type == mjproto.EVENT_TYPE_PON:
if open_from == mjproto.RELATIVE_POS_LEFT:
return "p" + str(stolen_tile) + str(open_tiles[0]) + str(open_tiles[1])
elif open_from == mjproto.RELATIVE_POS_LEFT:
elif open_from == mjproto.RELATIVE_POS_MID:
return str(stolen_tile) + "p" + str(open_tiles[0]) + str(open_tiles[1])
else:
return str(stolen_tile) + str(open_tiles[0]) + "p" + str(open_tiles[1])
elif event_type == mjproto.EVENT_TYPE_KAN_CLOSED:
return str(stolen_tile) + str(stolen_tile) + str(stolen_tile) + "a" + str(stolen_tile)
else:
return " "
return ""


# mjscore形式の配牌をソートする関数。
Expand Down Expand Up @@ -83,6 +85,8 @@ def parse_discards(events, abs_pos: int):
else:
riichi_tile_list.append(_change_tile_fmt(events[i + 1].tile))
# riichiの次のeventに宣言牌が記録されているのでそのtileを取得して後にindexを取得変更
elif event.type == mjproto.EVENT_TYPE_KAN_CLOSED and event.who == abs_pos:
discards.append(_change_action_format(event.open))
if is_reach:
riichi_tile = riichi_tile_list[0]
discards = [
Expand Down Expand Up @@ -244,7 +248,7 @@ def parse_draws(draws, events, abs_pos):
1100: "300-500",
1500: "400-700",
1600: "800-1600",
2000: "1000-2000",
2000: "500-1000",
2400: "600-1200",
2700: "700-1300",
3100: "800-1500",
Expand Down Expand Up @@ -288,16 +292,29 @@ def _fan_fu(who, fans: List[int], fu: int, ten) -> str:
return no_dealer_point_dict[ten]


def _winner_point(who: int, from_who: int, fans: List[int], fu: int, ten: int) -> str:
def _is_oya(who: int, round: int) -> bool: # 和了者が親かどうか判定する。
"""
>>> _winner_point(0, 0, [3, 0], 30, 6000)
>>> _is_oya(0, 3)
False
>>> _is_oya(0, 4)
True
"""
if round % 4 == who:
return True
else:
return False


def _winner_point(who: int, from_who: int, fans: List[int], fu: int, ten: int, round: int) -> str:
"""
>>> _winner_point(0, 0, [3, 0], 30, 6000, 0)
'30符3飜2000点∀'
>>> _winner_point(2, 0, [5, 0], 40, 8000)
>>> _winner_point(2, 0, [5, 0], 40, 8000, 0)
'満貫8000点'
"""
is_tsumo = who == from_who # ツモあがりかどうかを判定
if is_tsumo:
if who == mjproto.ABSOLUTE_POS_INIT_EAST: # 親かどうか
if _is_oya(who, round): # 親かどうか
return _fan_fu(who, fans, fu, ten) + str(int(ten / 3)) + "点∀"
else:
return _fan_fu(who, fans, fu, ten) + non_dealer_tsumo_dict[ten] + "点"
Expand Down Expand Up @@ -361,6 +378,7 @@ def parse_terminal(state: mjproto.State):
ten_changes = [i for i in state.terminal.no_winner.ten_changes]
return ["流局", ten_changes]
else:
round = state.init_score.round
who = state.terminal.wins[0].who
from_who = state.terminal.wins[0].from_who
ten_changes = [i for i in state.terminal.wins[0].ten_changes]
Expand All @@ -374,7 +392,7 @@ def parse_terminal(state: mjproto.State):
yakus: [役とドラの種類]
ten: 純粋に上がり点が表示される。ツモ上がりの際の対応が必要
"""
yaku_point_infos = [who, from_who, who, _winner_point(who, from_who, fans, fu, ten)]
yaku_point_infos = [who, from_who, who, _winner_point(who, from_who, fans, fu, ten, round)]
yaku_point_infos.extend(_winner_yakus(yakus, fans))
return [
"和了",
Expand Down
20 changes: 17 additions & 3 deletions mjconvert/mjconvert/open_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ def has_red_pon_kan_added(bits: int) -> bool: # TODO テスト ポンとカカ
return False


def has_red_kan_closed_kan_opend(bits: int) -> bool:
fives = [4, 13, 22]
stolen_tile_kind = open_stolen_tile_type(bits)
if stolen_tile_kind in fives:
return True
else:
return False


def has_red(bits: int) -> bool:
"""
>>> has_red(52503) # 赤5を含むチー
Expand All @@ -128,7 +137,7 @@ def has_red(bits: int) -> bool:
elif event_type == mjproto.EVENT_TYPE_PON or event_type == mjproto.EVENT_TYPE_KAN_ADDED:
return has_red_pon_kan_added(bits)
else:
return True # ダイミンカンとアンカンは必ず赤を含む
return has_red_kan_closed_kan_opend(bits) # ダイミンカンとアンカンは必ず赤を含む


def transform_red_stolen(bits: int, stolen_tile: int) -> int:
Expand All @@ -154,7 +163,8 @@ def transform_red_open(bits: int, open: List[int], event_type) -> List[int]:
open[-1] = red_dict[open[-1]]
return open
else:
return [0, 0, 0] # TODO カン
open[-1] = red_dict[open[-1]]
return open # TODO カン


def open_stolen_tile_type(bits: int) -> int:
Expand All @@ -165,6 +175,8 @@ def open_stolen_tile_type(bits: int) -> int:
20
>>> open_stolen_tile_type(28722)
18
>>> open_stolen_tile_type(31744) # 暗槓 白
31
"""
event_type = open_event_type(bits)
if event_type == mjproto.EVENT_TYPE_CHI:
Expand All @@ -175,7 +187,7 @@ def open_stolen_tile_type(bits: int) -> int:
stolen_tile_kind = (bits >> 9) // 3
return transform_red_stolen(bits, stolen_tile_kind)
else:
stolen_tile_kind = (bits >> 8) // 4 # TODO: add test case
stolen_tile_kind = (bits >> 8) // 4
return transform_red_stolen(bits, stolen_tile_kind)


Expand All @@ -187,6 +199,8 @@ def open_tile_types(bits: int) -> List[int]:
[20, 21, 22]
>>> open_tile_types(28722) # 加槓 s1
[18, 18, 18, 18]
>>> open_tile_types(31744) # 暗槓 白
[31, 31, 31, 31]
"""
event_type = open_event_type(bits)
if event_type == mjproto.EVENT_TYPE_CHI:
Expand Down
Loading

0 comments on commit ac45edc

Please sign in to comment.