HearthSim / python-hearthstone

Hearthstone Python library (CardDefs, DBF, enums, log parser)
MIT License
246 stars 62 forks source link

Player.initial_deck is sometimes missing cards #6

Closed beheh closed 8 years ago

beheh commented 8 years ago

Downstream issue: HearthSim/HSReplay.net#43

This log file is missing cards in the initial_deck of player "Red1010". The replay itself contains a lot more cards (a seen in the replay).

I'm testing with the following script:

import sys
from datetime import datetime
from hsreplay.dumper import parse_log

file = open(sys.argv[1], "r")
parser = parse_log(file, processor="GameState", date=datetime.now())
file.close()
game_tree = parser.games[0]

for player in game_tree.game.players:
    print("Found player %s" % player.name)
    for card in player.initial_deck:
        print("...with card %s" % card)

...and am only getting the following cards for the second player:

Found player Red1010
...with card Card(id=60, card_id='EX1_391')
...with card Card(id=61, card_id=None)
...with card Card(id=62, card_id=None)
...with card Card(id=63, card_id=None)
...with card Card(id=64, card_id=None)
...with card Card(id=65, card_id=None)
...with card Card(id=66, card_id=None)
...with card Card(id=67, card_id='OG_283')
beheh commented 8 years ago

It seems to be boiling down to the hardcoded id range check:

@property
def initial_deck(self):
    for entity in self.entities:
        if 3 < entity.id < 68:
            if entity.tags.get(GameTag.CARDTYPE) not in (
                CardType.HERO, CardType.HERO_POWER
            ):
                yield entity

That block looks flaky to me - especially in brawls or adventures, where deck sizes may vary (and where no deck list is supplemented from the uploading client). In this case it seems to be choice cards with extra entities.

We probably need some extra logic to filter the cards, or keep a list of ids somewhere.

jleclanche commented 8 years ago

I don't think there's really a surefire way of getting the deck. And now that I remember, setaside cards will break the algorithm too.

beheh commented 8 years ago

I'm sure we can think of a way - maybe by looking at entities that are in the deck at mulligan time.