当前位置: 首页>>代码示例>>Python>>正文


Python engine.Game类代码示例

本文整理汇总了Python中hearthbreaker.engine.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())
开发者ID:5alamander,项目名称:hearthbreaker,代码行数:34,代码来源:mage_tests.py

示例2: enshelf_one

def enshelf_one(index):
    loader = DeckLoader()
    generator = RandomDeckGenerator()
    # deck1 = loader.load_deck("zoo.hsdeck")
    # deck2 = loader.load_deck("zoo.hsdeck")
    deck1 = generator.generate()
    deck2 = generator.generate()
    game = Game([deck1, deck2], [TradeAgent(), TradeAgent()])
    new_game = game.copy()
    game_log = Hearthlogger()
    game_log.attach(new_game)
    try:
        new_game.start()
    except Exception as e:
       #print(json.dumps(new_game.__to_json__(), default=lambda o: o.__to_json__(), indent=1))
       #print(new_game._all_cards_played)
       del new_game
       del game_log
       print(e)
       return False
    # print("winning agent: " + new_game.winner.agent.__class__.__name__)
    game_log.shelf(index)
    del new_game
    del game_log
    return True
开发者ID:jirenz,项目名称:CS229_Project,代码行数:25,代码来源:boardstate_test.py

示例3: test_agent_once

def test_agent_once(one, other = None):
	#print("game_started")
	generator = RandomDeckGenerator()
	deck1 = generator.generate()
	deck2 = deck1.copy()

	if other is None:
		other = TradeAgent()
		#other = RandomAgent()
	game = Game([deck1, deck2], [one, other])
	new_game = game.copy()
	try:
		new_game.start()
		# new_data = GameHistoryGenerator.process_history(history, new_game)
		# Data = open("data.txt", "a")
		# for i in new_data:
			# tmp = i[0]
			# tmp.append(i[1])
			# for j in range(len(tmp)):
				# tmp[j] = str(tmp[j])
			# Data.write(" ".join(tmp))
			# Data.write("\n")
		# Data.close()
		print("Game lasted: " + str(new_game._turns_passed))
		print("winning agent: " + new_game.winner.agent.name)
	except Exception as e:
		print("Game error: " + str(e))
		# raise e
		return False
	
	# spark_weights(ql.weights)
	return new_game.winner.agent.name
开发者ID:jirenz,项目名称:CS229_Project,代码行数:32,代码来源:agent_test.py

示例4: generate_game_for

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,代码行数:30,代码来源:testing_utils.py

示例5: start_state

	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,代码行数:8,代码来源:model.py

示例6: generate_one

	def generate_one(agent1, agent2, extractor):
		generator = RandomDeckGenerator()
		deck1 = generator.generate()
		deck2 = deck1.copy()
		game = Game([deck1, deck2], [agent1, agent2])
		try:
			history = game.start_with_history()
		except Exception as e:
			return None
		if not game.game_ended:
			return None
		return GameHistoryGenerator.process_history(history, game, extractor)
开发者ID:jirenz,项目名称:CS229_Project,代码行数:12,代码来源:game_history_generator.py

示例7: 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())
开发者ID:Kogorushi,项目名称:hearthbreaker,代码行数:32,代码来源:druid_tests.py

示例8: 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())
开发者ID:jademcgough,项目名称:hearthstone-simulator,代码行数:14,代码来源:replay_tests.py

示例9: run_game

 def run_game(self, other):
     mydeck = self.breakerdeck()
     game = Game([mydeck, other.breakerdeck()], [RandomAgent(), RandomAgent()])
     tries = 0
     while tries < 10:
         try:
             game.start()
             result = game.players[0].hero.dead and game.players[0].deck == mydeck
             if result:
                 database.create_game('mutational', self.id, other.id, self.id)
             else:
                 database.create_game('mutational', self.id, other.id, other.id)
             return
         except:
             tries += 1
     return True
开发者ID:slaymaker1907,项目名称:hearthbreaker,代码行数:16,代码来源:util.py

示例10: 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, Malfurion())
        deck2 = Deck(card_set2, Jaina())

        agent1 = mock.Mock(spec=DoNothingAgent(), wraps=DoNothingAgent())
        agent2 = mock.Mock(spec=DoNothingAgent(), wraps=DoNothingAgent())
        game = Game([deck1, deck2], [agent1, agent2])

        game.start()
开发者ID:5alamander,项目名称:hearthbreaker,代码行数:16,代码来源:game_object_tests.py

示例11: 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, 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,代码行数:47,代码来源:game_object_tests.py

示例12: test_recording_game

    def test_recording_game(self):
        self.maxDiff = None
        random.seed(9876)
        deck1 = hearthbreaker.engine.Deck([StonetuskBoar() for i in range(0, 30)], CHARACTER_CLASS.MAGE)
        deck2 = hearthbreaker.engine.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()
开发者ID:jademcgough,项目名称:hearthstone-simulator,代码行数:17,代码来源:replay_tests.py

示例13: generate_replays

def generate_replays():
    loader = DeckLoader()
    deck1 = loader.load_deck("patron.hsdeck")
    deck2 = loader.load_deck("patron.hsdeck")
    game = Game([deck1, deck2], [RandomAgent(), RandomAgent()])
    new_game = game.copy()
    replay = record(new_game)
    try:
        new_game.start()
    except Exception as e:
        print(json.dumps(new_game.__to_json__(), default=lambda o: o.__to_json__(), indent=1))
        print(new_game._all_cards_played)
        raise e

    replay.write_json("replay_text.hsreplay")
    del new_game
    print("done!")
开发者ID:jirenz,项目名称:CS229_Project,代码行数:17,代码来源:Replay_generator.py

示例14: 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.engine.Game`
    """
    d = json.loads(json_string)
    return Game.__from_json__(d, agents)
开发者ID:5alamander,项目名称:hearthbreaker,代码行数:9,代码来源:serialization.py

示例15: test_json_saving

    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,代码行数:22,代码来源:replay_tests.py


注:本文中的hearthbreaker.engine.Game类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。