Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage example #9

Open
aidiss opened this issue Jan 26, 2020 · 2 comments
Open

Usage example #9

aidiss opened this issue Jan 26, 2020 · 2 comments

Comments

@aidiss
Copy link

aidiss commented Jan 26, 2020

Could you provide an example of using this package?

@samuel-chp
Copy link

I had a hard time to figure out how it works, so I can try to show you how I used it to parse the log when playing Battlegrounds. You can also check how the tests work in the test directory, it can be a good way to start with.

You first need to create a Parser and choose an Exporter to process the entities of the log. You can also define your own exporter, see export.py.

from hslog.parser import LogParser
from hslog.export import EntityTreeExporter

parser = LogParser()
with open("Power.log") as f:
    parser.read(f)
packet_tree = parser.games[0]
exporter = EntityTreeExporter(packet_tree)
export = exporter.export()

And to get the current board's of the two players:

player1= game.players[0]
player2 = game.players[1]


def get_current_minions(player):
    minions = []
    for e in player.entities:
        if e.tags[GameTag.CONTROLLER] == player.tags[GameTag.CONTROLLER] and e.zone == Zone.PLAY:
            if GameTag.CARDTYPE in e.tags.keys() and e.tags[GameTag.CARDTYPE] == CardType.MINION:
                minions.append(e)
    return minions

You can then explore the attributes of the "export" object and the "game" object more precisely to fully understand how it works.
I'm really not an expert but I hope it will help a little.

@beheh beheh changed the title Usage exampl Usage example Nov 8, 2021
@AidaMati
Copy link

@samuel-chp I'm confused as to where the 'game' in player1 = game.players[0] comes from. I thought it would be the 'Game' from hearthstone.entities but that doesn't have a 'players' attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants