How to use hearthstone - 10 common examples

To help you get started, we’ve selected a few hearthstone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HearthSim / python-hearthstone / tests / test_hslog.py View on Github external
assert game.players[0].account_hi == 1
	assert game.players[0].account_lo == 0
	assert game.players[0].is_ai
	assert not game.players[0].name

	assert game.players[1].id == 3
	assert game.players[1].player_id == 2
	assert game.players[1].account_hi == 3
	assert game.players[1].account_lo == 2
	assert not game.players[1].is_ai
	assert not game.players[1].name

	# Test packet structure
	assert len(packet_tree.packets) == 1
	packet = packet_tree.packets[0]
	assert packet.power_type == PowerType.CREATE_GAME
	assert packet.entity == game.id == 1

	# Player packet objects are not the same as players
	assert int(packet.players[0].entity) == game.players[0].id
	assert packet.players[0].player_id == game.players[0].player_id
	assert int(packet.players[1].entity) == game.players[1].id
	assert packet.players[1].player_id == game.players[1].player_id

	# All tags should be empty (we didn't pass any)
	assert not game.tags
	assert not game.players[0].tags
	assert not game.players[1].tags

	# Check some basic logic
	assert game.get_player(1) is game.players[0]
	assert game.get_player(2) is game.players[1]
github HearthSim / python-hslog / tests / test_main.py View on Github external
assert game.players[0].account_hi == 1
	assert game.players[0].account_lo == 0
	assert game.players[0].is_ai
	assert not game.players[0].name

	assert game.players[1].id == 3
	assert game.players[1].player_id == 2
	assert game.players[1].account_hi == 3
	assert game.players[1].account_lo == 2
	assert not game.players[1].is_ai
	assert not game.players[1].name

	# Test packet structure
	assert len(packet_tree.packets) == 1
	packet = packet_tree.packets[0]
	assert packet.power_type == PowerType.CREATE_GAME
	assert packet.entity == game.id == 1

	# Player packet objects are not the same as players
	assert int(packet.players[0].entity) == game.players[0].id
	assert packet.players[0].player_id == game.players[0].player_id
	assert int(packet.players[1].entity) == game.players[1].id
	assert packet.players[1].player_id == game.players[1].player_id

	# All tags should be empty (we didn't pass any)
	assert not game.tags
	assert not game.players[0].tags
	assert not game.players[1].tags

	# Check some basic logic
	assert game.get_player(1) is game.players[0]
	assert game.get_player(2) is game.players[1]
github HearthSim / python-hearthstone / tests / test_hslog.py View on Github external
def test_tag_change_unknown_entity_format():
	# Format changed in 15590
	parser = LogParser()
	parser.read(StringIO(INITIAL_GAME))
	parser.flush()

	entity_format = (
		"[name=UNKNOWN ENTITY [cardType=INVALID] id=24 zone=DECK zonePos=0 cardId= player=1]"
	)
	id = parse_entity_id(entity_format)
	assert id == 24

	data = "TAG_CHANGE Entity=%s tag=ZONE value=HAND" % (entity_format)
	packet = parser.handle_power(None, "TAG_CHANGE", data)
	assert packet.power_type == PowerType.TAG_CHANGE
	assert packet.entity == id
	assert packet.tag == GameTag.ZONE
	assert packet.value == Zone.HAND
github HearthSim / python-hearthstone / tests / test_enums.py View on Github external
def test_cardclass():
	playable_cards = [
		enums.CardClass.DRUID,
		enums.CardClass.HUNTER,
		enums.CardClass.MAGE,
		enums.CardClass.PALADIN,
		enums.CardClass.PRIEST,
		enums.CardClass.ROGUE,
		enums.CardClass.SHAMAN,
		enums.CardClass.WARLOCK,
		enums.CardClass.WARRIOR
	]

	for c in playable_cards:
		assert c.is_playable

	for c in enums.CardClass:
		if c not in playable_cards:
			assert not c.is_playable
github HearthSim / python-hearthstone / tests / test_enums.py View on Github external
def test_cardclass():
	playable_cards = [
		enums.CardClass.DRUID,
		enums.CardClass.HUNTER,
		enums.CardClass.MAGE,
		enums.CardClass.PALADIN,
		enums.CardClass.PRIEST,
		enums.CardClass.ROGUE,
		enums.CardClass.SHAMAN,
		enums.CardClass.WARLOCK,
		enums.CardClass.WARRIOR
	]

	for c in playable_cards:
		assert c.is_playable

	for c in enums.CardClass:
		if c not in playable_cards:
			assert not c.is_playable
github HearthSim / python-hslog / tests / test_logs.py View on Github external
def test_debugprintgame(parser):
	with open(logfile("23576_debugprintgame.power.log")) as f:
		parser.read(f)

	assert parser.game_meta == {
		"BuildNumber": 23576,
		"FormatType": FormatType.FT_WILD,
		"GameType": GameType.GT_RANKED,
		"ScenarioID": 2,
	}
github HearthSim / python-hearthstone / tests / test_hslog.py View on Github external
def test_empty_entity_in_options():
	parser = LogParser()
	parser.read(StringIO(INITIAL_GAME))
	parser.flush()

	data = "target 0 entity="
	with pytest.raises(ParsingError):
		# This can happen, but the game is corrupt
		parser.handle_options(None, data)
github HearthSim / python-hslog / tests / test_main.py View on Github external
def test_tag_value_parsing():
	tag, value = parse_initial_tag("tag=ZONE value=PLAY")
	assert tag == GameTag.ZONE
	assert value == Zone.PLAY

	tag, value = parse_initial_tag("tag=CARDTYPE value=PLAYER")
	assert tag == GameTag.CARDTYPE
	assert value == CardType.PLAYER

	tag, value = parse_initial_tag("tag=1 value=2")
	assert tag == 1
	assert value == 2

	tag, value = parse_initial_tag("tag=9999998 value=123")
	assert tag == 9999998
	assert value == 123
github HearthSim / python-hearthstone / tests / test_hslog.py View on Github external
parser = LogParser()
	parser.read(StringIO(INITIAL_GAME))
	parser.flush()

	assert len(parser.games) == 1
	packet_tree = parser.games[0]
	game = packet_tree.export().game
	assert len(game.entities) == 3
	assert len(game.players) == 2

	assert game.tags == {
		GameTag.TURN: 1,
		GameTag.ZONE: Zone.PLAY,
		GameTag.ENTITY_ID: 1,
		GameTag.NEXT_STEP: Step.BEGIN_MULLIGAN,
		GameTag.CARDTYPE: CardType.GAME,
		GameTag.STATE: State.RUNNING,
	}
	assert game.initial_state == State.RUNNING
	assert game.initial_step == Step.INVALID

	assert game.players[0].tags == {
		GameTag.PLAYSTATE: PlayState.PLAYING,
		GameTag.PLAYER_ID: 1,
		GameTag.TEAM_ID: 1,
		GameTag.ZONE: Zone.PLAY,
		GameTag.CONTROLLER: 1,
		GameTag.ENTITY_ID: 2,
		GameTag.CARDTYPE: CardType.PLAYER,
	}

	assert game.players[1].tags == {
github HearthSim / python-hslog / tests / test_main.py View on Github external
GameTag.ZONE: Zone.PLAY,
		GameTag.CONTROLLER: 1,
		GameTag.ENTITY_ID: 2,
		GameTag.CARDTYPE: CardType.PLAYER,
	}

	assert game.players[1].tags == {
		GameTag.PLAYSTATE: PlayState.PLAYING,
		GameTag.CURRENT_PLAYER: 1,
		GameTag.FIRST_PLAYER: 1,
		GameTag.PLAYER_ID: 2,
		GameTag.TEAM_ID: 2,
		GameTag.ZONE: Zone.PLAY,
		GameTag.CONTROLLER: 2,
		GameTag.ENTITY_ID: 3,
		GameTag.CARDTYPE: CardType.PLAYER,
	}