yuufyu / mjlegal

麻雀の合法手を生成するプログラム(開発中)
0 stars 1 forks source link

extra_anpaisに同じ牌が多重に追加される #3

Closed yuufyu closed 3 years ago

yuufyu commented 3 years ago

現象

MjaiLoader.actionはprevious_actionを使ってextra_anpaisを更新する(牌を追加)。 previous_actionが更新されないままMjaiLoader.actionが2回以上呼ばれる(例:action_type=noneなど)と、extra_anpaisに同じ牌が多重追加されることがある。 これによってsutehai + extra_anpaisに同じ牌が4個より多く追加されると、HandTool.is_furitenのTilesUtil.tiles_to_tiles34で期待と異なる動作をする場合がある。

問題箇所

https://github.com/yuugata/mjlegal/blob/ce86ae914fc37d16f692489c0e9b8a62f8525ea8/mjlegal/mjai.py#L13

エラー再現Test

ce86ae914fc37d16f692489c0e9b8a62f8525ea8 player0は中をsutehaiに3個, extra_anpaisに1個持つ。previous_action=dahaiのままMjaiLoader.actionを2回呼び出すと中を合計5個持つことになり、HandTool.is_furitenのTilesUtil.tiles_to_tiles34でクラッシュする。

{"type":"tsumo","actor":0,"pai":"C"}
{"type":"dahai","actor":0,"pai":"C","tsumogiri":true}
{"type":"tsumo","actor":1,"pai":"E"}
{"type":"dahai","actor":1,"pai":"F","tsumogiri":false}
{"type":"tsumo","actor":2,"pai":"3p"}
{"type":"dahai","actor":2,"pai":"P","tsumogiri":false}
{"type":"tsumo","actor":0,"pai":"C"}
{"type":"dahai","actor":0,"pai":"C","tsumogiri":true}
  :
{"type":"tsumo","actor":0,"pai":"C"}
{"type":"dahai","actor":0,"pai":"C","tsumogiri":true}
{"type":"tsumo","actor":1,"pai":"C"}
{"type":"dahai","actor":1,"pai":"C","tsumogiri":true}
{"type":"ryukyoku","reason":"fanpai","tehais":[["2p","3p","4p","4p","5p","6p","7p","8p","3s","4s","5s","8s","8s"],["?","?","?","?","?","?","?","?","?","?","?","?","?"],["?","?","?","?","?","?","?","?","?","?","?","?","?"]],"tenpais":[true,false,false],"deltas":[2000,-1000,-1000,0],"scores":[27100,23800,53100,0]}
yuufyu commented 3 years ago

多重追加のみ回避 95ca2ba0eaa557a657a53ec09f598048bf4c92ad