Skip to content

Instantly share code, notes, and snippets.

@synap5e
Last active August 29, 2015 14:26
Show Gist options
  • Save synap5e/6a41bd51b68e4a55662d to your computer and use it in GitHub Desktop.
Save synap5e/6a41bd51b68e4a55662d to your computer and use it in GitHub Desktop.
import sys; sys.path.append("./fireplace")
from fireplace import utils, cards, targeting
import fireplace
from fireplace.cards import heroes
from fireplace.player import Player
from fireplace.game import BaseGame, GameOver
from fireplace.card import Minion
from fireplace.enums import CardType, GameTag
from collections import defaultdict
ARMOR_PLATING = 'PART_001'
WHIRLING_BLADES = 'PART_007'
RUSTY_HORN = 'PART_003'
SILENCE = 'EX1_332'
WISP = "CS2_231"
THAURISSAN = "BRM_028"
def give_hand(game, player, hand):
player.discard_hand()
discounts = defaultdict(list)
max_discount = 0
for card_data in hand:
card_id, cost = card_data['id'], card_data['cost']
original_cost = getattr(fireplace.cards, card_id).cost
assert original_cost >= cost
discount = original_cost - cost
max_discount = max(max_discount, discount)
discounts[discount].append(card_id)
thaurissan = player.summon(THAURISSAN)
for discount in range(max_discount, -1, -1):
game.end_turn()
game.end_turn()
for card_id in discounts[discount]:
player.give(card_id)
thaurissan.destroy()
return
for card_data in hand:
card_id, cost = card_data['id'], card_data['cost']
print( ['%d == %d (%s)' % (c.cost, cost, c.id) for c in player.hand if c.id == card_id])
assert any(c.cost == cost and c.id == card_id for c in player.hand)
def create_game(data):
#print(data)
deck1 = [WISP] * 30
deck2 = [WISP] * 30
player1 = Player(name="Player1")
player1.prepare_deck(deck1, heroes.WARRIOR)
player2 = Player(name="Player2")
player2.prepare_deck(deck2, getattr(heroes, data['their_hero'].upper()))
game = BaseGame(players=(player1, player2))
game.start()
player1.max_mana = 10
player2.max_mana = 10
player1.cant_draw = True
player1.max_hand_size = 11
player2.cant_draw = True
give_hand(game, player1, data['hand'])
# TODO
#data['my_health'] = 30
#data['their_health'] = 30
player1.hero.damage = 30 - data['my_health']
assert player1.hero.health == data['my_health']
player1.hero.armor = data['my_armor']
player2.hero.damage = 30 - data['their_health']
assert player2.hero.health == data['their_health']
player2.hero.armor = data['their_armor']
# player 2's turn now
game.end_turn()
for player, cards in [
(player1, data['my_field']),
(player2, data['their_field'])
]:
game.end_turn()
for card_data in cards:
card_id, health, attack = card_data['id'], card_data['health'], card_data['attack']
card = player.summon(card_id)
player.used_mana = 0
has_taunt = card.taunt
player.give(SILENCE).play(target=card)
if has_taunt:
player.give(RUSTY_HORN).play(target=card)
while card.atk < attack:
player.give(WHIRLING_BLADES).play(target=card)
player.used_mana = 0
while card.health < health:
player.give(ARMOR_PLATING).play(target=card)
player.used_mana = 0
card.damage = card.max_health - health
assert card.id == card_id
assert card.atk == attack
assert card.health == health
game.end_turn()
weapon_data = data.get('weapon')
if weapon_data:
weapon = player1.summon(weapon_data['id'])
weapon.durability = - weapon_data['health']
assert weapon.atk == weapon_data['attack']
#print(weapon.durability)
player1.max_mana = data['my_mana'] # TODO
return game
if __name__ == '__main__':
game = create_game(
{
'my_health': 8,
'hand': [
{'id': 'CS2_189', 'cost': 1, 'health': 0, 'attack': 0},
#{'id': 'EX1_007', 'cost': 2, 'health': 0, 'attack': 0},
#{'id': 'CS2_108', 'cost': 0, 'health': 0, 'attack': 0},
#{'id': 'EX1_096', 'cost': 2, 'health': 0, 'attack': 0}
],
'my_mana': 10,
'their_field': [
{'id': 'CS2_150', 'cost': 0, 'health': 2, 'attack': 4},
{'id': 'DS1_175', 'cost': 0, 'health': 1, 'attack': 1}
],
'their_health': 12,
'my_field': [
{'id': 'EX1_604', 'cost': 0, 'health': 4, 'attack': 9},
{'id': 'CS2_147', 'cost': 0, 'health': 4, 'attack': 2},
{'id': 'BRM_019', 'cost': 0, 'health': 3, 'attack': 3},
{'id': 'BRM_019', 'cost': 0, 'health': 3, 'attack': 3},
{'id': 'BRM_019', 'cost': 0, 'health': 3, 'attack': 3}
],
'weapon': None,
'my_armor': 10,
'their_hero': 'Hunter',
'their_armor': 0
}
)
import heu3
heu3.print_game(game)
data2 = { 'my_health': 8,
'hand': [
{'id': 'CS2_189', 'cost': 1, 'health': 0, 'attack': 0},
{'id': 'EX1_007', 'cost': 2, 'health': 0, 'attack': 0},
{'id': 'CS2_108', 'cost': 0, 'health': 0, 'attack': 0},
], 'my_mana': 9, 'their_field': [{'id': 'CS2_196', 'cost': 0, 'health': 3, 'attack': 2}, {'id': 'CS2_boar', 'cost': 0, 'health': 1, 'attack': 1}], 'their_health': 21, 'my_field': [{'id': 'EX1_402', 'cost': 0, 'health': 3, 'attack': 1}, {'id': 'EX1_604', 'cost': 0, 'health': 4, 'attack': 2}, {'id': 'CS2_147', 'cost': 0, 'health': 4, 'attack': 2}, {'id': 'BRM_019', 'cost': 0, 'health': 2, 'attack': 3}, {'id': 'BRM_019', 'cost': 0, 'health': 3, 'attack': 3}, {'id': 'BRM_019', 'cost': 0, 'health': 3, 'attack': 3}], 'weapon': None, 'my_armor': 6, 'their_hero': 'Hunter', 'their_armor': 0}
game = create_game(data2)
heu3.print_game(game)
data3 = {'their_field': [{'cost': 0, 'health': -1, 'id': 'CS2_222', 'attack': 6}, {'cost': 0, 'health': 1, 'id': 'CS2_101t', 'attack': 1}], 'hand': [{'cost': 2, 'health': 0, 'id': 'CS2_009', 'attack': 0}, {'cost': 6, 'health': 0, 'id': 'EX1_173', 'attack': 0}, {'cost': 5, 'health': 0, 'id': 'NEW1_007', 'attack': 0}, {'cost': 5, 'health': 0, 'id': 'FP1_014', 'attack': 0}, {'cost': 0, 'health': 0, 'id': 'GAME_005', 'attack': 0}], 'their_armor': 0, 'weapon': None, 'my_armor': 0, 'their_health': 25, 'my_mana': 10, 'my_field': [], 'their_hero': 'Paladin', 'my_health': 30}
game = create_game(data3)
heu3.print_game(game)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment