Esempio n. 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))
Esempio n. 2
0
    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)