當前位置: 首頁>>代碼示例>>Python>>正文


Python Game.pre_game方法代碼示例

本文整理匯總了Python中hearthbreaker.engine.Game.pre_game方法的典型用法代碼示例。如果您正苦於以下問題:Python Game.pre_game方法的具體用法?Python Game.pre_game怎麽用?Python Game.pre_game使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在hearthbreaker.engine.Game的用法示例。


在下文中一共展示了Game.pre_game方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_ManaWyrm

# 需要導入模塊: from hearthbreaker.engine import Game [as 別名]
# 或者: from hearthbreaker.engine.Game import pre_game [as 別名]
    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())
開發者ID:5alamander,項目名稱:hearthbreaker,代碼行數:36,代碼來源:mage_tests.py

示例2: generate_game_for

# 需要導入模塊: from hearthbreaker.engine import Game [as 別名]
# 或者: from hearthbreaker.engine.Game import pre_game [as 別名]
def generate_game_for(card1, card2, first_agent_type, second_agent_type, run_pre_game=True):
    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]
    if run_pre_game:
        game.pre_game()
    return game
開發者ID:5alamander,項目名稱:hearthbreaker,代碼行數:32,代碼來源:testing_utils.py

示例3: start_state

# 需要導入模塊: from hearthbreaker.engine import Game [as 別名]
# 或者: from hearthbreaker.engine.Game import pre_game [as 別名]
	def start_state(self):
		generator = RandomDeckGenerator()
		deck1 = generator.generate()
		deck2 = deck1.copy()

		game = Game([deck1, deck2], [RandomAgent(), RandomAgent()])
		game.pre_game()
		return game
開發者ID:jirenz,項目名稱:CS229_Project,代碼行數:10,代碼來源:model.py

示例4: test_create_game

# 需要導入模塊: from hearthbreaker.engine import Game [as 別名]
# 或者: from hearthbreaker.engine.Game import pre_game [as 別名]
    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, Malfurion())
        deck2 = Deck(card_set2, Jaina())
        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[1:2], "Cards not retained after request")
開發者ID:5alamander,項目名稱:hearthbreaker,代碼行數:49,代碼來源:game_object_tests.py

示例5: test_CircleOfHealing

# 需要導入模塊: from hearthbreaker.engine import Game [as 別名]
# 或者: from hearthbreaker.engine.Game import pre_game [as 別名]
    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], [CardTestingAgent(), OneCardPlayingAgent()])
        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)
開發者ID:smallsweet,項目名稱:hearthbreaker,代碼行數:19,代碼來源:priest_tests.py

示例6: test_strategy

# 需要導入模塊: from hearthbreaker.engine import Game [as 別名]
# 或者: from hearthbreaker.engine.Game import pre_game [as 別名]
def test_strategy():
    generator = RandomDeckGenerator()
    deck1 = generator.generate()
    deck2 = deck1.copy()
    game = Game([deck1, deck2], [TradeAgent(), TradeAgent()])
    game.pre_game()
    game.current_player = game.players[1]
    while not game.game_ended:
        manager = StrategyManager(StatePairLinearModel(RelativeResourceExtractor()))
        manager.think(game)
        outcomes = manager.get_outcomes()
        print("Number of outcomes: " + str(len(outcomes)) + '\n')
        # for situation in outcomes:
        #     print("See: " + str(situation.other_player.hero.__to_json__()) + '\n')
        # input("Presss enter to continue:")

        game.play_single_turn()
開發者ID:jirenz,項目名稱:CS229_Project,代碼行數:19,代碼來源:strategy_test.py

示例7: test_HolyNova

# 需要導入模塊: from hearthbreaker.engine import Game [as 別名]
# 或者: from hearthbreaker.engine.Game import pre_game [as 別名]
    def test_HolyNova(self):
        deck1 = StackedDeck([MogushanWarden(), HolyNova()], CHARACTER_CLASS.PRIEST)
        deck2 = StackedDeck([MogushanWarden()], CHARACTER_CLASS.PALADIN)
        game = Game([deck1, deck2], [CardTestingAgent(), OneCardPlayingAgent()])
        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)
開發者ID:smallsweet,項目名稱:hearthbreaker,代碼行數:20,代碼來源:priest_tests.py

示例8: test_Swipe

# 需要導入模塊: from hearthbreaker.engine import Game [as 別名]
# 或者: from hearthbreaker.engine.Game import pre_game [as 別名]
    def test_Swipe(self):
        deck1 = StackedDeck([BloodfenRaptor(), StonetuskBoar(), StonetuskBoar()], CHARACTER_CLASS.DRUID)
        deck2 = StackedDeck([Swipe()], CHARACTER_CLASS.DRUID, )
        game = Game([deck1, deck2], [OneCardPlayingAgent(), EnemyMinionSpellTestingAgent()])
        game.pre_game()
        game.current_player = game.players[1]
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()

        # The bloodfen raptor should be left, with one hp
        self.assertEqual(1, len(game.other_player.minions))
        self.assertEqual(1, game.other_player.minions[0].health)
        self.assertEqual(29, game.other_player.hero.health)
開發者ID:Kogorushi,項目名稱:hearthbreaker,代碼行數:21,代碼來源:druid_tests.py

示例9: test_json_saving

# 需要導入模塊: from hearthbreaker.engine import Game [as 別名]
# 或者: from hearthbreaker.engine.Game import pre_game [as 別名]
    def test_json_saving(self):
        self.maxDiff = 6000
        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)
        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)
開發者ID:jademcgough,項目名稱:hearthstone-simulator,代碼行數:24,代碼來源:replay_tests.py

示例10: test_random_character_saving

# 需要導入模塊: from hearthbreaker.engine import Game [as 別名]
# 或者: from hearthbreaker.engine.Game import pre_game [as 別名]
    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))
開發者ID:jademcgough,項目名稱:hearthstone-simulator,代碼行數:25,代碼來源:replay_tests.py

示例11: test_Cenarius

# 需要導入模塊: from hearthbreaker.engine import Game [as 別名]
# 或者: from hearthbreaker.engine.Game import pre_game [as 別名]
    def test_Cenarius(self):
        deck1 = StackedDeck([StonetuskBoar()], CHARACTER_CLASS.DRUID)
        deck2 = StackedDeck([WarGolem(), WarGolem(), Cenarius(), Cenarius()], CHARACTER_CLASS.DRUID)
        game = Game([deck1, deck2], [DoNothingAgent(), OneCardPlayingAgent()])
        game.pre_game()

        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        game.play_single_turn()
        self.assertEqual(2, len(game.other_player.minions))
        for minion in game.other_player.minions:
            self.assertEqual(7, minion.calculate_attack())
            self.assertEqual(7, minion.health)
            self.assertEqual(7, minion.calculate_max_health())
        game.play_single_turn()

        self.assertEqual(3, len(game.current_player.minions))

        self.assertEqual(5, game.current_player.minions[0].calculate_attack())
        self.assertEqual(8, game.current_player.minions[0].health)
        self.assertEqual(8, game.current_player.minions[0].calculate_max_health())
        self.assertEqual("Cenarius", game.current_player.minions[0].card.name)

        for minion_index in range(1, 3):
            minion = game.current_player.minions[minion_index]
            self.assertEqual(9, minion.calculate_attack())
            self.assertEqual(9, minion.health)
            self.assertEqual(9, minion.calculate_max_health())

        game.players[1].agent.choose_option = lambda options, player: options[1]

        game.play_single_turn()
        game.play_single_turn()

        self.assertEqual(6, len(game.current_player.minions))

        self.assertEqual(5, game.current_player.minions[1].calculate_attack())
        self.assertEqual(8, game.current_player.minions[1].health)
        self.assertEqual(8, game.current_player.minions[1].calculate_max_health())
        self.assertEqual("Cenarius", game.current_player.minions[1].card.name)

        self.assertEqual(2, game.current_player.minions[0].calculate_attack())
        self.assertEqual(2, game.current_player.minions[0].health)
        self.assertEqual(2, game.current_player.minions[0].calculate_max_health())
        self.assertTrue(game.current_player.minions[0].taunt)
        self.assertEqual("Treant", game.current_player.minions[0].card.name)

        self.assertEqual(2, game.current_player.minions[2].calculate_attack())
        self.assertEqual(2, game.current_player.minions[2].health)
        self.assertEqual(2, game.current_player.minions[2].calculate_max_health())
        self.assertTrue(game.current_player.minions[2].taunt)
        self.assertEqual("Treant", game.current_player.minions[2].card.name)
開發者ID:Kogorushi,項目名稱:hearthbreaker,代碼行數:67,代碼來源:druid_tests.py

示例12: test_RandomAgent

# 需要導入模塊: from hearthbreaker.engine import Game [as 別名]
# 或者: from hearthbreaker.engine.Game import pre_game [as 別名]
    def test_RandomAgent(self):
        deck1 = Deck([
            GoldshireFootman(),
            GoldshireFootman(),
            MurlocRaider(),
            MurlocRaider(),
            BloodfenRaptor(),
            BloodfenRaptor(),
            FrostwolfGrunt(),
            FrostwolfGrunt(),
            RiverCrocolisk(),
            RiverCrocolisk(),
            IronfurGrizzly(),
            IronfurGrizzly(),
            MagmaRager(),
            MagmaRager(),
            SilverbackPatriarch(),
            SilverbackPatriarch(),
            ChillwindYeti(),
            ChillwindYeti(),
            KeeperOfTheGrove(),
            KeeperOfTheGrove(),
            SenjinShieldmasta(),
            SenjinShieldmasta(),
            BootyBayBodyguard(),
            BootyBayBodyguard(),
            FenCreeper(),
            FenCreeper(),
            BoulderfistOgre(),
            BoulderfistOgre(),
            WarGolem(),
            WarGolem(),
        ], Malfurion())

        deck2 = Deck([
            Shieldbearer(),
            Shieldbearer(),
            FlameImp(),
            FlameImp(),
            YoungPriestess(),
            YoungPriestess(),
            DarkIronDwarf(),
            DarkIronDwarf(),
            DireWolfAlpha(),
            DireWolfAlpha(),
            Voidwalker(),
            Voidwalker(),
            HarvestGolem(),
            HarvestGolem(),
            KnifeJuggler(),
            KnifeJuggler(),
            ShatteredSunCleric(),
            ShatteredSunCleric(),
            ArgentSquire(),
            ArgentSquire(),
            Doomguard(),
            Doomguard(),
            Soulfire(),
            Soulfire(),
            DefenderOfArgus(),
            DefenderOfArgus(),
            AbusiveSergeant(),
            AbusiveSergeant(),
            NerubianEgg(),
            NerubianEgg(),
        ], Guldan())

        game = Game([deck1, deck2], [RandomAgent(), RandomAgent()])
        game.pre_game()
        game.current_player = game.players[1]

        game.play_single_turn()

        self.assertEqual(0, len(game.current_player.minions))

        game.play_single_turn()
        self.assertEqual(2, len(game.current_player.minions))
        self.assertEqual(3, game.current_player.minions[1].health)
        self.assertEqual("Young Priestess", game.current_player.minions[0].card.name)

        game.play_single_turn()
        self.assertEqual(1, len(game.current_player.minions))
        self.assertEqual("Frostwolf Grunt", game.current_player.minions[0].card.name)

        game.play_single_turn()
        self.assertEqual(0, len(game.other_player.minions))
        self.assertEqual(28, game.other_player.hero.health)
        self.assertEqual(3, len(game.current_player.minions))
        self.assertEqual("Dire Wolf Alpha", game.current_player.minions[2].card.name)

        for turn in range(0, 13):
            game.play_single_turn()
            self.assertFalse(game.game_ended)

        game.play_single_turn()

        self.assertEqual(0, game.current_player.hero.health)
        self.assertEqual(21, game.other_player.hero.health)

        self.assertTrue(game.game_ended)
開發者ID:5alamander,項目名稱:hearthbreaker,代碼行數:102,代碼來源:agent_tests.py


注:本文中的hearthbreaker.engine.Game.pre_game方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。