Ledenel / auto-white-reimu

a mahjong library aimed to implement mahjong AIs by imitating white reimu -- a excellent mahjong player.
GNU General Public License v3.0
9 stars 1 forks source link

Fail to parse some tenhou records. #25

Open canuse opened 5 years ago

canuse commented 5 years ago

When parsing some files using from_file, an xml'Namespace' object has no attribute 'n0' (sometimes n1) error occured:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\canuse\PycharmProjects\auto-white-reimu\mahjong\record\reader.py", line 187, in from_file
    return TenhouRecord(next(ET.parse(file).iter()))
  File "C:\Users\canuse\PycharmProjects\auto-white-reimu\mahjong\record\reader.py", line 140, in __init__
    [meta.UN.n0, meta.UN.n1, meta.UN.n2, meta.UN.n3],
AttributeError: 'Namespace' object has no attribute 'n1'

A total of 18469 file was processed and this error occured 98 times ( with 'n0' 83 times and 'n1' 15 times)

For example, 2019010115gm-00a9-0000-21b95613.xml raised an 'n1' error and 2019010202gm-00a9-0000-3142addc.xml raised an 'n0' error 2019010115gm-00a9-0000-21b95613.zip 2019010202gm-00a9-0000-3142addc.zip

Ledenel commented 5 years ago

This example shows that there should be some internel wrong assumption made by me. Could you please provide the tenhou.net paifu link, to visualize that what is really happening during the game?

canuse commented 5 years ago

http://tenhou.net/3/?log=2019010115gm-00a9-0000-21b95613 http://tenhou.net/3/?log=2019010202gm-00a9-0000-3142addc

Ledenel commented 5 years ago

I've not found anything useful in visualization, but for mesages below:

    <GO type="169" lobby="0" />
    <UN n0="%E3%81%84%E3%81%AA%E3%81%97%E3%82%93%E3%80%82" n1="%42%41%52%34" n2="%E3%81%82%E3%81%A1%E3%82%87%E3%83%BC" n3="%E6%81%A9%E7%94%B0%E5%B8%8C" dan="17,16,16,17" rate="2197.33,2149.89,2024.85,2159.75" sx="M,M,M,F" />
    <TAIKYOKU oya="0" />
    <BYE who="0" />
    <UN n0="%E3%81%84%E3%81%AA%E3%81%97%E3%82%93%E3%80%82" />
    <INIT seed="0,0,0,3,0,8" ten="250,250,250,250" oya="0" hai0="103,107,95,48,32,126,108,101,100,14,135,9,61" hai1="5,71,113,53,55,22,36,125,105,132,128,79,52" hai2="81,121,6,35,70,18,111,83,110,87,93,29,34" hai3="66,20,91,92,94,104,123,33,21,96,57,45,43" />

You could see that player 0 has disconnected and immediately reconnected before the first name (maybe some network issue)

The issue is, when treat event before INIT as game meta settings I assumed that each element will only appeared once, which is wrong since above UN appeared twice.

https://github.com/Ledenel/auto-white-reimu/blob/90f002077fcf0137ca66b45d80b77fb884450606/mahjong/record/reader.py#L116

Here, when reducing multiple elements, this will replace the old attributes when same element re-appeared. add some condition to merge may solve this issue.