本文整理汇总了Python中hearthbreaker.game_objects.Game类的典型用法代码示例。如果您正苦于以下问题:Python Game类的具体用法?Python Game怎么用?Python Game使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Game类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ManaWyrm
def test_ManaWyrm(self):
deck1 = StackedDeck([ManaWyrm(), IceLance(), ManaWyrm(), IceLance(), IceLance(), IceLance()],
CHARACTER_CLASS.MAGE)
deck2 = StackedDeck([IronbeakOwl()], CHARACTER_CLASS.PALADIN)
game = Game([deck1, deck2], [CardTestingAgent(), OneCardPlayingAgent()])
game.pre_game()
game.current_player = 1
game.play_single_turn()
self.assertEqual(1, len(game.current_player.minions))
self.assertEqual(1, game.current_player.minions[0].calculate_attack())
self.assertEqual(3, game.current_player.minions[0].health)
self.assertEqual(3, game.current_player.minions[0].calculate_max_health())
self.assertEqual("Mana Wyrm", game.current_player.minions[0].card.name)
game.play_single_turn()
game.play_single_turn()
self.assertEqual(2, len(game.current_player.minions))
self.assertEqual(1, game.current_player.minions[0].calculate_attack())
self.assertEqual(3, game.current_player.minions[0].health)
self.assertEqual(3, game.current_player.minions[0].calculate_max_health())
self.assertEqual(2, game.current_player.minions[1].calculate_attack())
self.assertEqual(3, game.current_player.minions[1].health)
self.assertEqual(3, game.current_player.minions[1].calculate_max_health())
game.play_single_turn()
game.play_single_turn()
self.assertEqual(2, len(game.current_player.minions))
self.assertEqual(1, game.current_player.minions[0].calculate_attack())
self.assertEqual(3, game.current_player.minions[0].health)
self.assertEqual(3, game.current_player.minions[0].calculate_max_health())
self.assertEqual(5, game.current_player.minions[1].calculate_attack())
self.assertEqual(3, game.current_player.minions[1].health)
self.assertEqual(3, game.current_player.minions[1].calculate_max_health())
示例2: test_SorcerersApprentice
def test_SorcerersApprentice(self):
deck1 = StackedDeck([SorcerersApprentice(), ArcaneMissiles(), SorcerersApprentice(), Frostbolt(), Frostbolt(),
Frostbolt()], CHARACTER_CLASS.MAGE)
deck2 = StackedDeck([StonetuskBoar()], CHARACTER_CLASS.PRIEST)
game = Game([deck1, deck2], [SpellTestingAgent(), DoNothingBot()])
game.pre_game()
game.current_player = game.players[1]
game.play_single_turn()
game.play_single_turn()
game.play_single_turn()
self.assertEqual(1, len(game.current_player.minions))
self.assertEqual(3, game.current_player.minions[0].calculate_attack())
self.assertEqual(2, game.current_player.minions[0].health)
self.assertEqual("Sorcerer's Apprentice", game.current_player.minions[0].card.name)
# Arcane missiles should also have been played, since it is now free
self.assertEqual(27, game.other_player.hero.health)
# Make sure the other frostbolts have been properly reduced
self.assertEqual(1, game.current_player.hand[1].mana_cost(game.current_player))
self.assertEqual(1, game.current_player.hand[2].mana_cost(game.current_player))
game.play_single_turn()
game.play_single_turn()
# Both Sorcer's Apprentices are killed by friendly Frostbolts.
self.assertEqual(0, len(game.current_player.minions))
# Make sure that the cards in hand are no longer reduced
self.assertEqual(2, game.current_player.hand[0].mana)
示例3: generate_game_for
def generate_game_for(card1, card2, first_agent_type, second_agent_type):
if not isinstance(card1, collections.Sequence):
card_set1 = [card1()]
else:
card_set1 = [card() for card in card1]
class1 = CHARACTER_CLASS.MAGE
for card in card_set1:
if card.character_class != CHARACTER_CLASS.ALL:
class1 = card.character_class
break
if not isinstance(card2, collections.Sequence):
card_set2 = [card2()]
else:
card_set2 = [card() for card in card2]
class2 = CHARACTER_CLASS.MAGE
for card in card_set2:
if card.character_class != CHARACTER_CLASS.ALL:
class2 = card.character_class
break
deck1 = StackedDeck(card_set1, class1)
deck2 = StackedDeck(card_set2, class2)
game = Game([deck1, deck2], [first_agent_type(), second_agent_type()])
game.current_player = game.players[1]
game.other_player = game.players[0]
game.pre_game()
return game
示例4: do_stuff
def do_stuff(net):
def play_game():
new_game = game.copy()
new_game.start()
deck1 = load_deck("example.hsdeck")
deck2 = load_deck("example.hsdeck")
game = Game([deck1, deck2], [CustomAgent(net), TradeAgent()])
#print(timeit.timeit(play_game, 'gc.enable()', number=1000))
return game.start()
示例5: do_stuff
def do_stuff():
def play_game():
new_game = game.copy()
new_game.start()
deck1 = load_deck("example.hsdeck")
deck2 = load_deck("example.hsdeck")
game = Game([deck1, deck2], [RandomAgent(), RandomAgent()])
game.start()
print(timeit.timeit(play_game, 'gc.enable()', number=1000))
示例6: test_SavageRoar
def test_SavageRoar(self):
deck1 = StackedDeck([StonetuskBoar(), StonetuskBoar(), SavageRoar()], CHARACTER_CLASS.DRUID)
deck2 = StackedDeck([StonetuskBoar()], CHARACTER_CLASS.MAGE)
game = Game([deck1, deck2], [OneCardPlayingAgent(), OneCardPlayingAgent()])
game.current_player = 1
game.play_single_turn()
game.play_single_turn()
game.play_single_turn()
game.play_single_turn()
minion_increase_mock = mock.Mock()
game.other_player.minions[0].bind("attack_changed", minion_increase_mock)
game.other_player.minions[1].bind("attack_changed", minion_increase_mock)
player_increase_mock = mock.Mock()
game.other_player.hero.bind("attack_changed", player_increase_mock)
game.play_single_turn()
self.assertEqual(0, game.current_player.mana)
# Make sure the attack got increased
self.assertListEqual([mock.call(2), mock.call(2)], minion_increase_mock.call_args_list)
self.assertListEqual([mock.call(2)], player_increase_mock.call_args_list)
# And make sure that it went down again
self.assertEqual(1, game.current_player.minions[0].calculate_attack())
self.assertEqual(1, game.current_player.minions[1].calculate_attack())
self.assertEqual(0, game.current_player.hero.calculate_attack())
示例7: test_deck_shortening
def test_deck_shortening(self):
deck1 = Deck([RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(),
RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(),
RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(),
RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(),
RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(),
RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(),
RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(), RagnarosTheFirelord(),
GoldshireFootman(), GoldshireFootman()], CHARACTER_CLASS.DRUID)
deck2 = StackedDeck([StonetuskBoar()], CHARACTER_CLASS.HUNTER)
game = Game([deck1, deck2], [RandomAgent(), RandomAgent()])
replay = record(game)
game.start()
replay.write(StringIO())
示例8: test_first_turn
def test_first_turn(self):
card_set1 = []
card_set2 = []
for cardIndex in range(0, 30):
card_set1.append(card_lookup("Stonetusk Boar"))
card_set2.append(card_lookup("Novice Engineer"))
deck1 = Deck(card_set1, CHARACTER_CLASS.DRUID)
deck2 = Deck(card_set2, CHARACTER_CLASS.MAGE)
agent1 = mock.Mock(spec=DoNothingBot(), wraps=DoNothingBot())
agent2 = mock.Mock(spec=DoNothingBot(), wraps=DoNothingBot())
game = Game([deck1, deck2], [agent1, agent2])
game.start()
示例9: test_create_game
def test_create_game(self):
card_set1 = []
card_set2 = []
test_env = self
for cardIndex in range(0, 30):
card_set1.append(card_lookup("Stonetusk Boar"))
card_set2.append(card_lookup("Novice Engineer"))
deck1 = Deck(card_set1, CHARACTER_CLASS.DRUID)
deck2 = Deck(card_set2, CHARACTER_CLASS.MAGE)
checked_cards = []
class MockAgent1:
def do_card_check(self, cards):
test_env.assertEqual(len(cards), 3)
checked_cards.append(list(cards))
return [False, True, True]
def set_game(self, game):
pass
class MockAgent2:
def do_card_check(self, cards):
test_env.assertEqual(len(cards), 4)
checked_cards.append(list(cards))
return [False, True, True, False]
def set_game(self, game):
pass
agent1 = mock.Mock(spec=MockAgent1(), wraps=MockAgent1())
agent2 = mock.Mock(spec=MockAgent2(), wraps=MockAgent2())
game = Game([deck1, deck2], [agent1, agent2])
game.pre_game()
self.assertEqual(agent1.method_calls[0][0], "do_card_check", "Agent not asked to select cards")
self.assertEqual(agent2.method_calls[0][0], "do_card_check", "Agent not asked to select cards")
self.assertTrue(game.players[0].deck == deck1, "Deck not assigned to player")
self.assertTrue(game.players[1].deck == deck2, "Deck not assigned to player")
self.assertTrue(game.players[0].agent == agent1, "Agent not stored in the hearthbreaker")
self.assertTrue(game.players[1].agent == agent2, "Agent not stored in the hearthbreaker")
self.assertListEqual(checked_cards[0][1:], game.players[0].hand[:-1], "Cards not retained after request")
self.assertListEqual(checked_cards[1][1:2], game.players[1].hand[:-4], "Cards not retained after request")
示例10: test_recording_game
def test_recording_game(self):
self.maxDiff = None
random.seed(9876)
deck1 = hearthbreaker.game_objects.Deck([StonetuskBoar() for i in range(0, 30)], CHARACTER_CLASS.MAGE)
deck2 = hearthbreaker.game_objects.Deck([Naturalize() for i in range(0, 30)], CHARACTER_CLASS.DRUID)
agent1 = PredictableAgent()
agent2 = PredictableAgent()
game = Game([deck1, deck2], [agent1, agent2])
replay = record(game)
game.start()
output = StringIO()
replay.write_json(output)
f = open("tests/replays/stonetusk_innervate.hsreplay", "r")
dif = self.__compare_json(output.getvalue(), f.read())
self.assertTrue(dif)
f.close()
示例11: deserialize
def deserialize(json_string, agents):
"""
Decode the given game instance from a JSON formatted string.
:param string json_string: The string representation of the game
:rtype: :class:`hearthbreaker.game_objects.Game`
"""
d = json.loads(json_string)
return Game.__from_json__(d, agents)
示例12: test_json_saving
def test_json_saving(self):
self.maxDiff = 6000
deck1 = hearthbreaker.game_objects.Deck([RagnarosTheFirelord() for i in range(0, 30)], CHARACTER_CLASS.MAGE)
deck2 = hearthbreaker.game_objects.Deck([StonetuskBoar() for i in range(0, 30)], CHARACTER_CLASS.DRUID)
agent1 = PlayAndAttackAgent()
agent2 = OneCardPlayingAgent()
random.seed(4879)
game = Game([deck1, deck2], [agent1, agent2])
replay = record(game)
game.pre_game()
for turn in range(0, 17):
game.play_single_turn()
output = StringIO()
replay.write_json(output)
inp = StringIO(output.getvalue())
new_replay = Replay()
new_replay.read_json(inp)
old_output = output.getvalue()
other_output = StringIO()
new_replay.write_json(other_output)
self.assertEqual(other_output.getvalue(), old_output)
示例13: test_random_character_saving
def test_random_character_saving(self):
deck1 = hearthbreaker.game_objects.Deck([RagnarosTheFirelord() for i in range(0, 30)], CHARACTER_CLASS.MAGE)
deck2 = hearthbreaker.game_objects.Deck([StonetuskBoar() for i in range(0, 30)], CHARACTER_CLASS.DRUID)
agent1 = PlayAndAttackAgent()
agent2 = OneCardPlayingAgent()
random.seed(4879)
game = Game([deck1, deck2], [agent1, agent2])
replay = record(game)
game.pre_game()
for turn in range(0, 17):
game.play_single_turn()
output = StringIO()
replay.write_json(output)
random.seed(4879)
new_game = playback(Replay(StringIO(output.getvalue())))
new_game.pre_game()
for turn in range(0, 17):
new_game.play_single_turn()
self.assertEqual(2, len(new_game.current_player.minions))
self.assertEqual(30, new_game.other_player.hero.health)
self.assertEqual(5, len(new_game.other_player.minions))
示例14: test_CircleOfHealing
def test_CircleOfHealing(self):
deck1 = StackedDeck(
[CircleOfHealing(), MogushanWarden(), CircleOfHealing(), CircleOfHealing(), CircleOfHealing(),
CircleOfHealing(), CircleOfHealing()], CHARACTER_CLASS.PRIEST)
deck2 = StackedDeck([MogushanWarden()], CHARACTER_CLASS.PALADIN)
game = Game([deck1, deck2], [SpellTestingAgent(), MinionPlayingAgent()])
game.pre_game()
game.current_player = 1
for turn in range(0, 8):
game.play_single_turn()
game.players[0].minions[0].health = 4
game.players[1].minions[0].health = 4
game.play_single_turn() # Circle of Healing should be played
self.assertEqual(game.players[0].minions[0].calculate_max_health(), game.players[0].minions[0].health)
self.assertEqual(game.players[1].minions[0].calculate_max_health(), game.players[1].minions[0].health)
示例15: test_HolyNova
def test_HolyNova(self):
deck1 = StackedDeck([MogushanWarden(), HolyNova()], CHARACTER_CLASS.PRIEST)
deck2 = StackedDeck([MogushanWarden()], CHARACTER_CLASS.PALADIN)
game = Game([deck1, deck2], [SpellTestingAgent(), MinionPlayingAgent()])
game.pre_game()
game.current_player = 1
for turn in range(0, 8):
game.play_single_turn()
self.assertEqual(1, len(game.players[0].minions))
self.assertEqual(1, len(game.players[1].minions))
game.players[0].minions[0].health = 4 # Fake damage
self.assertEqual(4, game.players[0].minions[0].health)
self.assertEqual(7, game.players[1].minions[0].health)
game.play_single_turn() # Holy Nova should be played
self.assertEqual(6, game.players[0].minions[0].health)
self.assertEqual(5, game.players[1].minions[0].health)