Closed jsettlem closed 2 years ago
Thanks for the report. Please check if it still reproducible on latest master version
I can confirm that all the test cases I provided now result in "hand_not_correct." I generated ~9 billion random hands and encountered no further exceptions.
However, this does lead to a slight inconsistency. Some invalid hands result in "hand_not_correct" and some result in "hand_not_winning." Invalid winning hands do seem to score correctly (at least the couple I tested):
[[12, 13, 4, 5, 6, 7, 7, 28, 36, 40, 44, 92, 96, 100, 0],
[12, 13, 16, 17, 18, 19, 19, 28, 36, 40, 44, 92, 96, 100, 0],
[12, 13, 20, 21, 22, 23, 23, 28, 36, 40, 44, 92, 96, 100, 0],
[12, 13, 17, 17, 17, 17, 17, 17, 36, 40, 44, 92, 96, 100, 0],
[12, 13, 14, 16, 17, 18, 19, 19, 36, 40, 44, 92, 96, 100, 0]]
hand: 22222448m123p678s
winning tile: 4m
dora: 1m
Result: hand_not_correct
hand: 44055558m123p678s
winning tile: 4m
dora: 1m
Result: hand_not_correct
hand: 44666668m123p678s
winning tile: 4m
dora: 1m
Result: hand_not_winning
hand: 44555555m123p678s
winning tile: 4m
dora: 1m
Result: 1 han, 40 fu
hand: 44405555m123p678s
winning tile: 4m
dora: 1m
Result: 2 han, 30 fu
While testing this, I also realized one_line_string_to_136_array()
(understandably) breaks these invalid hands:
hand='22222448m123p678s'
TilesConverter.one_line_string_to_136_array(hand, has_aka_dora=True)=[4, 5, 6, 7, 8, 12, 13, 28, 36, 40, 44, 92, 96, 100]
TilesConverter.to_one_line_string(TilesConverter.one_line_string_to_136_array(hand, has_aka_dora=True), print_aka_dora=True)='22223448m123p678s'
hand='44055558m123p678s'
TilesConverter.one_line_string_to_136_array(hand, has_aka_dora=True)=[12, 13, 16, 17, 18, 19, 20, 28, 36, 40, 44, 92, 96, 100]
TilesConverter.to_one_line_string(TilesConverter.one_line_string_to_136_array(hand, has_aka_dora=True), print_aka_dora=True)='44055568m123p678s'
hand='44666668m123p678s'
TilesConverter.one_line_string_to_136_array(hand, has_aka_dora=True)=[12, 13, 20, 21, 22, 23, 24, 28, 36, 40, 44, 92, 96, 100]
TilesConverter.to_one_line_string(TilesConverter.one_line_string_to_136_array(hand, has_aka_dora=True), print_aka_dora=True)='44666678m123p678s'
hand='44555555m123p678s'
TilesConverter.one_line_string_to_136_array(hand, has_aka_dora=True)=[12, 13, 17, 18, 19, 20, 21, 22, 36, 40, 44, 92, 96, 100]
TilesConverter.to_one_line_string(TilesConverter.one_line_string_to_136_array(hand, has_aka_dora=True), print_aka_dora=True)='44555666m123p678s'
hand='22222244m123p678s'
TilesConverter.one_line_string_to_136_array(hand, has_aka_dora=True)=[4, 5, 6, 7, 8, 9, 12, 13, 36, 40, 44, 92, 96, 100]
TilesConverter.to_one_line_string(TilesConverter.one_line_string_to_136_array(hand, has_aka_dora=True), print_aka_dora=True)='22223344m123p678s'
In each case a five of a kind becomes four of a kind plus the next tile up when passed through one_line_string_to_136_array
(so 22222m
becomes 22223m
).
Obviously these are very exceptional cases and I don't actually need support for them for my use case, so I understand if you want to consider them "out of scope," but I did want to at least mention them.
Background
While playing around with this library, I was randomly generating and evaluating hands and accidentally made some hands with five of the same tile. In some cases, this leads to an IndexError
Code
Result
A whole bunch of stack traces
``` "C:\Program Files\Python39\python.exe" Z:/Dropbox/PyCharm/mahjong-master/mahjong-master/doc/reproduce_the_mahjong.py hand 44000008m123p678s winning tile 1p dora 1m Traceback (most recent call last): File "Z:\Dropbox\PyCharm\mahjong-master\mahjong-master\doc\reproduce_the_mahjong.py", line 29, inExpected
I'm not sure? Obviously this is an exceptional case, but the library gracefully handles many other exceptional cases so I would expect it to handle this one as well.
Environment
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Reproduced with both 1.1.11 from PyPI and the latest master commit. The stack traces are based off c3e64e5f04a49153564be58a2dd30eb495553a84