Usage example
aidiss opened this issue · 2 comments
Could you provide an example of using this package?
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.
@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.