Beispiel #1
0
    def test_random_character_saving(self):
        deck1 = hearthbreaker.engine.Deck(
            [RagnarosTheFirelord() for i in range(0, 30)], Jaina())
        deck2 = hearthbreaker.engine.Deck(
            [StonetuskBoar() for i in range(0, 30)], Malfurion())
        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))
Beispiel #2
0
 def test_SoulOfTheForest(self):
     game = playback(Replay("tests/replays/card_tests/SoulOfTheForest.hsreplay"))
     game.start()
     self.assertEqual(2, len(game.other_player.minions))
     self.assertEqual(2, game.other_player.minions[0].calculate_attack())
     self.assertEqual(2, game.other_player.minions[0].health)
     self.assertEqual("Treant", game.other_player.minions[0].card.name)
Beispiel #3
0
 def test_SoulOfTheForest(self):
     game = playback(Replay("tests/replays/card_tests/SoulOfTheForest.hsreplay"))
     game.start()
     self.assertEqual(2, len(game.other_player.minions))
     self.assertEqual(2, game.other_player.minions[0].calculate_attack())
     self.assertEqual(2, game.other_player.minions[0].health)
     self.assertEqual("Treant", game.other_player.minions[0].card.name)
 def test_BlessingOfWisdom(self):
     game = playback(Replay("tests/replays/card_tests/BlessingOfWisdom.hsreplay"))
     game.start()
     self.assertEqual(3, len(game.current_player.minions))
     # 7 cards have been drawn.
     # 3 for starting first, 3 for new turn and 1 for minion attack with Blessing of Wisdom
     # (the second minion who had it got silenced)
     self.assertEqual(23, game.other_player.deck.left)
Beispiel #5
0
 def test_BlessingOfWisdom(self):
     game = playback(Replay("tests/replays/card_tests/BlessingOfWisdom.hsreplay"))
     game.start()
     self.assertEqual(3, len(game.current_player.minions))
     # 7 cards have been drawn.
     # 3 for starting first, 3 for new turn and 1 for minion attack with Blessing of Wisdom
     # (the second minion who had it got silenced)
     self.assertEqual(23, game.other_player.deck.left)
Beispiel #6
0
 def test_option_replay(self):
     game = playback(Replay("tests/replays/stonetusk_power.hsreplay"))
     game.start()
     self.assertEqual(1, len(game.other_player.minions))
     panther = game.other_player.minions[0]
     self.assertEqual(panther.card.name, "Panther")
     self.assertEqual(panther.health, 3)
     self.assertEqual(panther.calculate_attack(), 4)
     self.assertEqual(panther.index, 0)
 def test_option_replay(self):
     game = playback(Replay("tests/replays/stonetusk_power.hsreplay"))
     game.start()
     self.assertEqual(1, len(game.other_player.minions))
     panther = game.other_player.minions[0]
     self.assertEqual(panther.card.name, "Panther")
     self.assertEqual(panther.health, 3)
     self.assertEqual(panther.calculate_attack(), 4)
     self.assertEqual(panther.index, 0)
    def test_loading_game(self):
        game = playback(Replay("tests/replays/example.hsreplay"))

        game.start()

        self.assertEqual(game.current_player.deck.character_class, CHARACTER_CLASS.DRUID)
        self.assertEqual(game.other_player.deck.character_class, CHARACTER_CLASS.MAGE)

        self.assertEqual(game.current_player.hero.health, 29)
        self.assertTrue(game.current_player.hero.dead)
    def test_loading_game(self):
        game = playback(Replay("tests/replays/example.hsreplay"))

        game.start()

        self.assertEqual(game.current_player.deck.hero.name, "Malfurion Stormrage")
        self.assertEqual(game.other_player.deck.hero.name, "Jaina Proudmoore")

        self.assertEqual(game.current_player.hero.health, 29)
        self.assertTrue(game.current_player.hero.dead)
Beispiel #10
0
    def test_ArcaneMissilesWithSpellPower(self):
        game = playback(Replay("tests/replays/card_tests/ArcaneMissilesWithSpellDamage.hsreplay"))
        game.start()

        self.assertEqual(1, len(game.current_player.minions))
        self.assertEqual(1, len(game.other_player.minions))
        self.assertEqual(1, game.other_player.minions[0].health)
        self.assertEqual(2, game.other_player.minions[0].calculate_max_health())
        self.assertEqual(27, game.other_player.hero.health)

        return game
Beispiel #11
0
    def test_loading_game(self):
        game = playback(Replay("tests/replays/example.hsreplay"))

        game.start()

        self.assertEqual(game.current_player.deck.hero.name,
                         "Malfurion Stormrage")
        self.assertEqual(game.other_player.deck.hero.name, "Jaina Proudmoore")

        self.assertEqual(game.current_player.hero.health, 29)
        self.assertTrue(game.current_player.hero.dead)
Beispiel #12
0
    def test_loading_game(self):
        game = playback(Replay("tests/replays/example.hsreplay"))

        game.start()

        self.assertEqual(game.current_player.deck.character_class,
                         CHARACTER_CLASS.DRUID)
        self.assertEqual(game.other_player.deck.character_class,
                         CHARACTER_CLASS.MAGE)

        self.assertEqual(game.current_player.hero.health, 29)
        self.assertTrue(game.current_player.hero.dead)
    def test_NobleSacrifice(self):
        game = generate_game_for(NobleSacrifice, StonetuskBoar, CardTestingAgent, PlayAndAttackAgent)

        game.play_single_turn()  # NobleSacrifice should be played
        self.assertEqual(1, len(game.players[0].secrets))
        self.assertEqual("Noble Sacrifice", game.players[0].secrets[0].name)

        game.play_single_turn()
        # Attack with Stonetusk should happen, and the secret should trigger. Both minions should die.
        self.assertEqual(0, len(game.players[0].secrets))
        self.assertEqual(0, len(game.players[0].minions))
        self.assertEqual(0, len(game.players[1].minions))
        self.assertEqual(30, game.players[0].hero.health)

        # Test with 7 minions
        game = playback(Replay("tests/replays/card_tests/NobleSacrifice.hsreplay"))
        game.start()
        self.assertEqual(7, len(game.players[0].minions))
        self.assertEqual(29, game.players[0].hero.health)
        self.assertEqual(1, len(game.players[0].secrets))
        self.assertEqual("Noble Sacrifice", game.players[0].secrets[0].name)
Beispiel #14
0
    def test_NobleSacrifice(self):
        game = generate_game_for(NobleSacrifice, StonetuskBoar, CardTestingAgent, PlayAndAttackAgent)

        game.play_single_turn()  # NobleSacrifice should be played
        self.assertEqual(1, len(game.players[0].secrets))
        self.assertEqual("Noble Sacrifice", game.players[0].secrets[0].name)

        game.play_single_turn()
        # Attack with Stonetusk should happen, and the secret should trigger. Both minions should die.
        self.assertEqual(0, len(game.players[0].secrets))
        self.assertEqual(0, len(game.players[0].minions))
        self.assertEqual(0, len(game.players[1].minions))
        self.assertEqual(30, game.players[0].hero.health)

        # Test with 7 minions
        game = playback(Replay("tests/replays/card_tests/NobleSacrifice.hsreplay"))
        game.start()
        self.assertEqual(7, len(game.players[0].minions))
        self.assertEqual(29, game.players[0].hero.health)
        self.assertEqual(1, len(game.players[0].secrets))
        self.assertEqual("Noble Sacrifice", game.players[0].secrets[0].name)
    def test_random_character_saving(self):
        deck1 = hearthbreaker.engine.Deck([RagnarosTheFirelord() for i in range(0, 30)], CHARACTER_CLASS.MAGE)
        deck2 = hearthbreaker.engine.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))
Beispiel #16
0
    def test_Shadowform(self):
        game = generate_game_for(IronfurGrizzly, Shadowform,
                                 OneCardPlayingAgent, PredictableAgent)

        for turn in range(0, 9):
            game.play_single_turn()

        self.assertEqual("Lesser Heal", game.players[1].hero.power.__str__())

        # Shadowform should be played
        game.play_single_turn()
        self.assertEqual("Mind Spike", game.players[1].hero.power.__str__())

        # Nothing special
        game.play_single_turn()

        # Mind Spike should be used, and Shadowform should be played
        game.play_single_turn()
        self.assertEqual(1, game.players[0].minions[0].health)
        self.assertEqual("Mind Shatter", game.players[1].hero.power.__str__())

        # Nothing special
        game.play_single_turn()
        self.assertEqual(5, len(game.players[0].minions))

        # Mind Shatter should be used, and Shadowform should be played
        # (but nothing will happen, we are already at Mind Shatter)
        game.play_single_turn()
        self.assertEqual("Mind Shatter", game.players[1].hero.power.__str__())
        self.assertEqual(4, len(game.players[0].minions))

        # Test using the hero power, then cast Shadowform and use the new power (this is possible)
        game = playback(Replay("tests/replays/card_tests/Shadowform.hsreplay"))
        game.start()
        self.assertEqual(10, game.players[0].max_mana)
        self.assertEqual(3, game.players[0].mana)
        self.assertEqual(28, game.players[1].hero.health)
    def test_Shadowform(self):
        game = generate_game_for(IronfurGrizzly, Shadowform, OneCardPlayingAgent, PredictableAgent)

        for turn in range(0, 9):
            game.play_single_turn()

        self.assertEqual("Lesser Heal", game.players[1].hero.power.__str__())

        # Shadowform should be played
        game.play_single_turn()
        self.assertEqual("Mind Spike", game.players[1].hero.power.__str__())

        # Nothing special
        game.play_single_turn()

        # Mind Spike should be used, and Shadowform should be played
        game.play_single_turn()
        self.assertEqual(1, game.players[0].minions[0].health)
        self.assertEqual("Mind Shatter", game.players[1].hero.power.__str__())

        # Nothing special
        game.play_single_turn()
        self.assertEqual(5, len(game.players[0].minions))

        # Mind Shatter should be used, and Shadowform should be played
        # (but nothing will happen, we are already at Mind Shatter)
        game.play_single_turn()
        self.assertEqual("Mind Shatter", game.players[1].hero.power.__str__())
        self.assertEqual(4, len(game.players[0].minions))

        # Test using the hero power, then cast Shadowform and use the new power (this is possible)
        game = playback(Replay("tests/replays/card_tests/Shadowform.hsreplay"))
        game.start()
        self.assertEqual(10, game.players[0].max_mana)
        self.assertEqual(3, game.players[0].mana)
        self.assertEqual(28, game.players[1].hero.health)