GithubHelp home page GithubHelp logo

python-hearthstone's Introduction

python-hearthstone

GitHub Workflow Status PyPI

A Hearthstone Python library containing:

  • A CardDefs.xml parser (hearthstone.cardxml)
  • A DbfXml parser (hearthstone.dbf)
  • A deck code encoder and decoder (hearthstone.deckstrings)
  • Hearthstone enums as IntEnum (hearthstone.enums)

The CardDefs.xml data for the latest build can optionally be installed from the python-hearthstone-data repository or on PyPI with pip install hearthstone_data. Otherwise, they will be download at runtime.

Requirements

  • Python 3.6+
  • lxml

Installation

  • To install from PyPI: pip install hearthstone

License

This project is licensed under the MIT license. The full license text is available in the LICENSE file.

Community

This is a HearthSim project. Join the HearthSim Developer community on Discord.

python-hearthstone's People

Contributors

azeier avatar beheh avatar chinesedfan avatar edipo2s avatar japalvia avatar jleclanche avatar joolean avatar mthuurne avatar robert-nix avatar shinoi2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-hearthstone's Issues

Split up hearthstone and hearthstone_data

I'd like to move the included CardDefs.xml / Strings stuff into a hearthstone_data package so that dependencies on the package are lighter (especially if they don't need the data, such as the hsredshift UDFs)

Whizbang GameTags

New game tags have been added in the latest expansion, from what I see in logs (and thrown exceptions), they are as follows:

  • MINIATURIZE
  • MINI
  • CREATED_BY_MINIATURIZE
  • ELUSIVE

Is adding these tags planned for development?
I could help with finding the values for them, but I dunno how.

P.S. I am working on an overlay, and trying to make it "automatic", but this issue stops me from further development.

STANDARD_SETS does not include HOF

STANDARD_SETS has dynamic card sets as YEAR and HOF(Hall of Fame) changes.
However the card set definition of some cards cannot match the newest ones.

This comes with the problems when set to the past years such as ZodiacYear.KRAKEN or set to the WILD env.

Decouple LogParser and PacketTree

In trying to make LogParser more usable for the HSReplay parser, I'm discovering that there are actually three distinct parts to our parser:

  • The Power.log parser
  • The Packet tree
  • The Entity tree

Currently, the Packet tree and the Power.log parser are tightly coupled. This is why it intuitively feels easy to make HSReplay output a packet tree, but it really isn't.

The reason they are coupled is because in order to set the entity attributes on the packets, those entities need to exist as actual entity objects, so we continuously update the entity tree as we read the log. Part of the reasoning behind that, IIRC, was to have semi-reliable Player entities that would have their name on all packets by the end of the game.

To decouple all this, here is what I propose:

  1. Change all entity attributes on the various packets to only be integers, except for players. This will be a tough change, which will require updating the XML dumper as well.
  2. Change Player entities to a lazy int so that it can be treated as an int, but it looks for its value in a known place.
  3. Add a mechanism to export a packet tree (or part of a packet tree?) to an entity tree.
  4. Remove the immediate updates on the game tree, replace it with the export
  5. Rework LogWatcher to base itself on the packet tree's export/update mechanism

Then, as long as we can export HSReplayDocument to a packet tree, we can use LogWatcher alongside it.

How to Use

it looks like good , can you make a example

I can not import from this code

# -*- coding: utf-8 -*-
from hearthstone import deckstrings
from hearthstone.enums import FormatType

s = "AAEBAf0EBu0FwcECyQOQErgIxQQMrAGKAZYF9w3XtgKYxALAAfsMqwTLBO0EuwIA"
#deck = deckstrings.Deck.from_deckstring(s)

deck = deckstrings.Deck()
deck.cards = [(749, 1), (41153, 1), (457, 1), (2320, 1), (1080, 1), (581, 1), (172, 2), (138, 2), (662, 2), (1783, 2), (39767, 2), (41496, 2), (192, 2), (1659, 2), (555, 2), (587, 2), (621, 2), (315, 2)]
deck.heroes = [637]
deck.format = FormatType.FT_WILD
print(deck.as_deckstring)

Blizzard Deckstrings didn't work for me

I want to get the deckstrings use you program in python hearthston
i use the data as below and i get the id from hearthstonejson
heroes 813
format 2
cards [(279, 2), (42046, 1), (613, 2), (40938, 2), (1099, 2), (41935, 1), (41169, 2), (39442, 2), (1363, 2), (40373, 2), (1014, 2), (1367, 2), (41176, 2), (41177, 2), (39034, 2), (30, 2)]
when i run the program i got a code like this
ACgxLCkoMiwpKDEsKSgxNzMsKSg2LCkoMiwpKDE5MCwpKDIwMCwpKDIsKSgyMDcsKSgxOTksKSgyLCkoMTQsKSgxNTEsKSgyLCkoMjI5LCkoNCwpKDIzNCwpKDE5MSwpKDIsKSgyMDMsKSg4LCkoMjA5LCkoMTkzLCkoMiwpKDE0NiwpKDE4MCwpKDIsKSgyMTEsKSgxMCwpKDE4MSwpKDE4NywpKDIsKSgyNDYsKSg3LCkoMjE1LCkoMTAsKSgyMTYsKSgxOTMsKSgyLCkoMjE3LCkoMTkzLCkoMiwpKDI1MCwpKDE3NiwpKDIsKSgzMCwpKDAsKQ==
this obviously not the right code ,Is there anything wrong for my data, Glad for you replay

How does quest tracking work?

My little script parses each line as it is written to the log. I seem to be unable to access the quest tags. I've tried something like the following

...
game = packet_tree.export().game
print game.tags.get(GameTag.QUEST)
print game.tags.get(GameTag.QUEST_PROGRESS)
print game.tags.get(GameTag.QUEST_PROGRESS_TOTAL)
for player in game.players:
  print player.tags.get(GameTag.QUEST)
  print player.tags.get(GameTag.QUEST_PROGRESS)
  print player.tags.get(GameTag.QUEST_PROGRESS_TOTAL)

Which returns

None
None
None
None
None
None

What am I doing wrong?

Player.initial_deck is sometimes missing cards

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')

Issues on Google Colab

Dear team,
I'm runing gym environment from SethKitchen (https://github.com/SethKitchen/hearthstone-gym). It uses fireplace and hearthstone packages. Running it locally (python 3.9) it works like a charm. I'm trying to run on Google Colab (python 3.8) and it fails when importing cardxml. However, other modules are properly imported:

image

I have no idea what is going wrong. Could you give me a hand please?

Hidden CHANGE_ENTITY results in invalid initial_card_id

Hidden CHANGE_ENTITY's result in non-collectible cards being in the initial deck. More specifically, entities = player.initial_deck will have entities where entity.initial_card_id is a card that was changed in the opponents hand. For some cards, such as transformed Worgens/identitied items/upgraded Spellstones we can reasonably assume that the cards were their non-transformed/unidentified/base Spellstone at the beginning of the game.

In hsredshift, we use a manually maintained map to correct these deck lists. We should make sure we also apply this for all games processed on HSReplay.net. For the sake of having a single source of truth, we could implement this map in HSReplay.net.

If we think this doesn't make sense in the library, we should reopen an issue on HSReplay.net and implement the map there as well. In that case we'd need to maintain two lists though (one in hsredshift and one in HSReplay.net), as the Redshift exporter directly uses the python-hearthstone exporter and does not pass through the HSReplay.net codebase.

Fix guess_friendly_player helpers with the new parser

There's a weird inter-linking between the packettree logic ("what happened from the player's POV") and the entitytree logic ("what happened in the game"). We iterate over the packets to find a specific entity not being revealed at a point we know the player couldn't have not seen it.

  • Move the method/logic to EntityTree rather than PacketTree?
  • Store the initial controller on entity? I think that's probably generally a good idea

Or... hmm. Maybe we write a separate exporter for it?! Like a FriendlyPlayerExporter. Oh that sounds good.

Parser Is Reporting Uncollectible Cards In Player Decklists

Hello

I found this project recently.
I wonder how I can run this project. Can you explain more clearly,many thanks.
: )

Serialize the parser?

I'm trying to save a parser object in a redis key/value store. I am able to pickle the parser on complete logs (i.e. parser.read()), but when pickling a parser mid stream (i.e. parser.read_line())
I get pickling errors.

This example runs successfully for a while until a bit after a new game is started then fails on the pickle.dumps line.

pickled = None

def test(line):
  global pickled
  if pickled:
    parser = pickle.loads(pickled)
  else:
    parser = LogParser()
  parser.read_line(line)
  pickled = pickle.dumps(parser)

AttributeError: Can't get attribute 'Player' on <module 'hearthstone.hslog.packets' from '/lib/python3.4/site-packages/hearthstone/hslog/packets.py'>
Can't pickle <class 'hearthstone.hslog.packets.CreateGame.Player'>: it's not found as hearthstone.hslog.packets.Player

Is there a way to export/import game data so I can pick up where I left off?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.