Example #1
0
def init_game(hero1=None, hero2=None, exclude=(), game_class=BaseTestGame):
	log.info("Initializing a new game")
	heroes = _select_heroes(hero1, hero2)
	player1 = Player("Player1", *_draft(hero=heroes[0], exclude=exclude))
	player2 = Player("Player2", *_draft(hero=heroes[1], exclude=exclude))
	game = game_class(players=(player1, player2))
	return game
Example #2
0
def main():
	deck1 = random_draft(hero=MAGE)
	deck2 = random_draft(hero=WARRIOR)
	player1 = Player(name="Player1")
	player1.prepare_deck(deck1, MAGE)
	player2 = Player(name="Player2")
	player2.prepare_deck(deck2, WARRIOR)

	game = Game(players=(player1, player2))
	game.start()

	while True:
		heropower = game.current_player.hero.power
		# always play the hero power, just for kicks
		if heropower.is_playable():
			if heropower.has_target():
				heropower.play(target=random.choice(heropower.targets))
			else:
				heropower.play()
		# iterate over our hand and play whatever is playable
		for card in game.current_player.hand:
			if card.is_playable():
				if card.has_target():
					card.play(target=random.choice(card.targets))
				else:
					card.play()
			else:
				print("Not playing", card)

		# Randomly attack with whatever can attack
		for character in game.current_player.characters:
			if character.can_attack():
				character.attack(random.choice(character.targets))

		game.end_turn()
Example #3
0
    def getInitGame(self):
        """
        Returns:
            startBoard: a representation of the board (ideally this is the form
                        that will be the input to your neural network)
        """
        if self.isolate:
            self.isolateSet()

        cards.db.initialize()
        if self.is_basic:  #create quick simple game
            with open('notbasic.data', 'rb') as f:
                extra_set = pickle.load(f)
            p1 = 6  #priest
            p2 = 7  #rogue
            deck1 = random_draft(CardClass(p1), exclude=extra_set)
            deck2 = random_draft(CardClass(p2), exclude=extra_set)
        else:
            p1 = random.randint(1, 9)
            p2 = random.randint(1, 9)
            deck1 = random_draft(CardClass(p1))
            deck2 = random_draft(CardClass(p2))
        self.players[0] = Player("Player1", deck1, CardClass(p1).default_hero)
        self.players[1] = Player("Player2", deck2, CardClass(p2).default_hero)
        game = Game(players=self.players)
        game.start()

        # Skip mulligan for now
        for player in game.players:
            cards_to_mulligan = random.sample(player.choice.cards, 0)
            player.choice.choose(*cards_to_mulligan)

        game.player_to_start = game.current_player
        self.game = game
        return game
def PresetGame(pp, testNr=1):
    from fireplace import cards
    cards.db.initialize()
    for test in range(testNr):
        class1 = pp.class1
        class2 = pp.class2
        Dummy1 = DummyAgent("Dummy1", DummyAgent.DummyAI, myClass=class1)
        Dummy2 = DummyAgent("Dummy2", DummyAgent.DummyAI, myClass=class2)
        deck1 = random_draft(Dummy1.myClass, [])  #random deck wrt its class
        deck2 = random_draft(Dummy2.myClass, [])  #random deck wrt its class
        player1 = Player(Dummy1.name, deck1, Dummy1.myClass.default_hero)
        player2 = Player(Dummy2.name, deck2, Dummy2.myClass.default_hero)
        game = Game(players=(player1, player2))
        # Configurations
        player1._start_hand_size = 3  ## this line must be before 'start()'
        player2._start_hand_size = 3  ##
        player1.max_mana = 9  ## this line must be before 'start()'
        player2.max_mana = 9  ##
        game.start()
        player1.hero.max_health = 30  ## this line must be below 'start()'
        player2.hero.max_health = 30  ##
        cards_to_mulligan = []
        player1.choice.choose(*cards_to_mulligan)
        player2.choice.choose(*cards_to_mulligan)
        player1._targetedaction_log = []
        player2._targetedaction_log = []
        pp(game.current_player).execute(test)
    pass
Example #5
0
def setup_game():
    """
    initializes a game between two players
    Returns:
        game: A game entity representing the start of the game after the mulligan phase
    """

    #choose classes (priest, rogue, shaman, warlock)
    p1 = random.randint(6, 9)
    p2 = random.randint(6, 9)
    #initialize players and randomly draft decks
    #pdb.set_trace()
    deck1 = random_draft(CardClass(p1))
    deck2 = random_draft(CardClass(p2))
    player1 = Player("Player1", deck1, CardClass(p1).default_hero)
    player2 = Player("Player2", deck2, CardClass(p2).default_hero)
    #begin the game
    game = Game(players=(player1, player2))
    game.start()

    #Skip mulligan for now
    for player in game.players:
        cards_to_mulligan = random.sample(player.choice.cards, 0)
        player.choice.choose(*cards_to_mulligan)

    return game
Example #6
0
    def initGame(self):
        cards.db.initialize()
        if self.is_basic: #create quick simple game
            with open('notbasic.data', 'rb') as f:
                extra_set = pickle.load(f)
            p1 = 6 #priest
            p2 = 7 #rogue
            deck1 = random_draft(CardClass(p1), exclude=extra_set)
            deck2 = random_draft(CardClass(p2), exclude=extra_set)
        else:
            p1 = random.randint(1, 9)
            p2 = random.randint(1, 9)
            deck1 = random_draft(CardClass(p1))
            deck2 = random_draft(CardClass(p2))
        Board.players[0] = Player("Player1", deck1, CardClass(p1).default_hero)
        Board.players[1] = Player("Player2", deck2, CardClass(p2).default_hero)
        game = Game(players=self.players)
        game.start()

        # Skip mulligan for now
        for player in game.players:
            cards_to_mulligan = random.sample(player.choice.cards, 0)
            player.choice.choose(*cards_to_mulligan)

        # self.start_player = game.current_player
        game.player_to_start = game.current_player
        Board.game = game
        return game
Example #7
0
    def DoMove(self, move):
        """ Update a state by carrying out the given move.
        """
        if self.game is not None:
            assert self.game.current_player.playstate == PlayState.PLAYING

            if self.game.current_player is not None:
                if self.game.current_player.name == "one":
                    self.playerJustMoved = 1
                else:
                    self.playerJustMoved = 2

        try:
            if move[0] == MOVE.PRE_GAME:
                self.player1 = Player("one", self.deck1, self.hero1)
                self.player2 = Player("two", self.deck2, self.hero2)
                self.game = Game(players=(self.player1, self.player2))
                self.game.start()

                # TODO: Mulligan
                for player in self.game.players:
                    if player.choice:
                        player.choice.choose()
            elif move[0] == MOVE.PICK_CLASS:
                self.hero2 = move[1]
            elif move[0] == MOVE.PICK_CARD:
                if len(self.deck1) < 30:
                    self.deck1.append(move[1].id)
                else:
                    self.deck2.append(move[1].id)
            elif move[0] == MOVE.MULLIGAN:
                self.game.current_player.choice.choose(*move[1])
            elif move[0] == MOVE.END_TURN:
                self.game.end_turn()
            elif move[0] == MOVE.HERO_POWER:
                heropower = self.game.current_player.hero.power
                if move[3] is None:
                    heropower.use()
                else:
                    heropower.use(target=heropower.targets[move[3]])
            elif move[0] == MOVE.PLAY_CARD:
                card = self.game.current_player.hand[move[2]]
                if move[3] is None:
                    card.play()
                else:
                    card.play(target=card.targets[move[3]])
            elif move[0] == MOVE.MINION_ATTACK:
                minion = self.game.current_player.field[move[2]]
                minion.attack(minion.targets[move[3]])
            elif move[0] == MOVE.HERO_ATTACK:
                hero = self.game.current_player.hero
                hero.attack(hero.targets[move[3]])
            elif move[0] == MOVE.CHOICE:
                self.game.current_player.choice.choose(move[1])
            else:
                raise NameError("DoMove ran into unclassified card", move)
        except:
            return
Example #8
0
def play_full_game():
        deck1 = random_draft(hero=MAGE)
        deck2 = random_draft(hero=WARRIOR)
        player1 = Player("Player1", deck1, MAGE)
        player2 = Player("Player2", deck2, WARRIOR)

        game = Game(players=(player1, player2))
        game.start()

        for player in game.players:
                # print("Can mulligan %r" % (player.choice.cards))
                mull_count = random.randint(0, len(player.choice.cards))
                cards_to_mulligan = random.sample(player.choice.cards, mull_count)
                player.choice.choose(*cards_to_mulligan)

        try:
                while True:
                        player = game.current_player

                        heropower = player.hero.power
                        if heropower.is_usable() and random.random() < 0.1:
                                if heropower.has_target():
                                        heropower.use(target=random.choice(heropower.targets))
                                else:
                                        heropower.use()
                                continue

                        # iterate over our hand and play whatever is playable
                        for card in player.hand:
                                if card.is_playable() and random.random() < 0.5:
                                        target = None
                                        if card.choose_cards:
                                                card = random.choice(card.choose_cards)
                                        if card.has_target():
                                                target = random.choice(card.targets)
                                        # print("Playing %r on %r" % (card, target))
                                        card.play(target=target)

                                        if player.choice:
                                                choice = random.choice(player.choice.cards)
                                                # print("Choosing card %r" % (choice))
                                                player.choice.choose(choice)

                                        continue

                        # Randomly attack with whatever can attack
                        for character in player.characters:
                                if character.can_attack():
                                        character.attack(random.choice(character.targets))
                                continue

                        game.end_turn()

        except GameOver:
                return game
                # print("Game completed normally in " + str(game.turn) + " turns.")

        return game
Example #9
0
    def getInitGame(self):
        """
        Returns:
            startBoard: a representation of the board (ideally this is the form
                        that will be the input to your neural network)
        """
        if self.isolate:
            self.isolateSet()

        cards.db.initialize()
        if self.is_basic:  #create quick simple game
            # with open('notbasic.data', 'rb') as f:
            #     extra_set = pickle.load(f)

            extra_set = cards.filter(card_set=[
                CardSet.EXPERT1, CardSet.HOF, CardSet.NAXX, CardSet.GVG,
                CardSet.BRM, CardSet.TGT, CardSet.LOE, CardSet.OG, CardSet.
                KARA, CardSet.GANGS, CardSet.UNGORO, CardSet.ICECROWN, CardSet.
                LOOTAPALOOZA, CardSet.GILNEAS, CardSet.BOOMSDAY, CardSet.TROLL
            ])
            # LOOTAPALOOZA = Kobolds and Catacombs # GILNEAS = Witchwood # TROLL = Rasthakan's Rumble

            # p1 = 6 #priest
            p1 = 7  #rogue
            p2 = 7  #rogue
            # p1 = 4 # mage
            # p2 = 4 # mage
            # deck1 = random_draft(CardClass(p1), exclude=extra_set)
            # deck2 = random_draft(CardClass(p2), exclude=extra_set)
            deck1 = self.roguebasic_draft(
            )  # use same shuffled rogue AI basic decks for now
            deck2 = self.roguebasic_draft()
        else:
            p1 = random.randint(1, 9)
            p2 = random.randint(1, 9)
            deck1 = random_draft(CardClass(p1))
            deck2 = random_draft(CardClass(p2))
        self.players[0] = Player("Player1", deck1, CardClass(p1).default_hero)
        self.players[1] = Player("Player2", deck2, CardClass(p2).default_hero)
        game = Game(players=self.players)
        game.start()

        # Skip mulligan for now (only mulligan expensive cards)
        for player in game.players:
            # if player.name == 'Player1':
            # cards_to_mulligan = [c for c in player.choice.cards if c.cost > 3]
            # else:
            cards_to_mulligan = random.sample(player.choice.cards, 0)
            player.choice.choose(*cards_to_mulligan)

        # track played card list
        self.players[0].playedcards = []
        self.players[1].playedcards = []

        #game.player_to_start = game.current_player      # obsolete?
        self.game = game
        return game
Example #10
0
def init_game(class1=None, class2=None, exclude=(), game_class=BaseTestGame):
    log.info("Initializing a new game")
    if class1 is None:
        class1 = _random_class()
    if class2 is None:
        class2 = _random_class()
    player1 = Player("Player1", *_draft(class1, exclude))
    player2 = Player("Player2", *_draft(class2, exclude))
    game = game_class(players=(player1, player2))
    return game
	def start(self):
		self.hero1 = CardClass.HUNTER.default_hero
		self.hero2 = CardClass.HUNTER.default_hero
		self.deck1 = list(hunter_simple_deck)
		self.deck2 = list(hunter_simple_deck)
		self.player1 = Player(PLAYER_1_NAME, self.deck1, self.hero1)
		self.player2 = Player(PLAYER_2_NAME, self.deck2, self.hero2)
		self.game = Game(players=(self.player1, self.player2))
		self.game.start()
		self.skipMulligan()
Example #12
0
def prepare_empty_game(game_class=BaseTestGame):
    player1 = Player(name="Player1")
    player1.prepare_deck([], random.choice(_heroes))
    player1.cant_fatigue = True
    player2 = Player(name="Player2")
    player2.prepare_deck([], random.choice(_heroes))
    player2.cant_fatigue = True
    game = game_class(players=(player1, player2))
    game.start()

    return game
Example #13
0
def play_full_game():
    deck1 = random_draft(hero=MAGE)
    deck2 = random_draft(hero=WARRIOR)
    player1 = Player(name="Player1")
    player1.prepare_deck(deck1, MAGE)
    player2 = Player(name="Player2")
    player2.prepare_deck(deck2, WARRIOR)

    game = Game(players=(player1, player2))
    game.start()

    for player in game.players:
        print("Can mulligan %r" % (player.choice.cards))
        mull_count = random.randint(0, len(player.choice.cards))
        cards_to_mulligan = random.sample(player.choice.cards, mull_count)
        player.choice.choose(*cards_to_mulligan)

    while True:
        player = game.current_player

        heropower = player.hero.power
        if heropower.is_usable() and percent_chance(10):
            if heropower.has_target():
                heropower.use(target=random.choice(heropower.targets))
            else:
                heropower.use()
            continue

        # iterate over our hand and play whatever is playable
        for card in player.hand:
            if card.is_playable() and percent_chance(50):
                target = None
                if card.choose_cards:
                    card = random.choice(card.choose_cards)
                if card.has_target():
                    target = random.choice(card.targets)
                print("Playing %r on %r" % (card, target))
                card.play(target=target)
                continue

        # Randomly attack with whatever can attack
        for character in player.characters:
            if character.can_attack():
                character.attack(random.choice(character.targets))
            continue

        if player.choice:
            choice = random.choice(player.choice.cards)
            print("Choosing card %r" % (choice))
            player.choice.choose(choice)
            continue

        game.end_turn()
Example #14
0
def prepare_empty_game(hero1=None, hero2=None, game_class=BaseTestGame):
	log.info("Initializing a new game with empty decks")
	heroes = _select_heroes(hero1, hero2)
	player1 = Player("Player1", [], heroes[0])
	player1.cant_fatigue = True
	player2 = Player("Player2", [], heroes[1])
	player2.cant_fatigue = True
	game = game_class(players=(player1, player2))
	game.start()
	_empty_mulligan(game)

	return game
Example #15
0
def test_full_game():
    global __last_turn__
    __last_turn__ = [None, None, None]
    try:
        json = []

        deck1 = get_face_hunter_deck()
        deck2 = random_draft(hero=WARRIOR)
        player1 = Player("Player1", deck1, HUNTER)
        player2 = Player("Player2", deck2, WARRIOR)

        game = Game(players=(player1, player2))
        game.start()
        play_full_game(json, game, player1, player2)
    except GameOver:
        #LAST TURN
        if (__last_turn__[1] != None):
            hashmap = get_hash_map(game, player1, player2, __last_turn__[2],
                                   __last_turn__[0].entity_id,
                                   __last_turn__[0].entity_id,
                                   __last_turn__[1].entity_id,
                                   __last_turn__[0])
            json.append(hashmap)
        else:
            hashmap = get_hash_map(game, player1, player2, __last_turn__[2],
                                   __last_turn__[0].entity_id,
                                   __last_turn__[0].entity_id, None,
                                   __last_turn__[0])
            json.append(hashmap)

        #RESULT
        if (game.current_player.hero.health < 1):
            hashmap = get_hash_map(game, player1, player2, 21,
                                   game.current_player.hero.entity_id, None,
                                   None, None)
            json.append(hashmap)
        else:
            hashmap = get_hash_map(game, player1, player2, 20,
                                   game.current_player.hero.entity_id, None,
                                   None, None)
            json.append(hashmap)

        f = open(REPLAY_JSON_PATH, 'w')
        write_line_to_file(f, json.__str__())
        my_datetime = datetime.now()
        path_to_zip = "C:\\Users\\Lubko\\OneDrive\\Documents\\matfyz\\bakalarka\\Hearthstone-Deck-Tracker-master\\Hearthstone Deck Tracker\\obj\\Debug\\Replay\\Replays\\" + my_datetime.strftime(
            "%d_%B_%Y__%H_%M.hdtreplay")
        my_zip_file = zipfile.ZipFile(path_to_zip, mode='w')
        my_zip_file.write(REPLAY_JSON_PATH)
        f.close()
        my_zip_file.close()
Example #16
0
def prepare_empty_game(class1=None, class2=None, game_class=BaseTestGame):
    log.info("Initializing a new game with empty decks")
    if class1 is None:
        class1 = _random_class()
    if class2 is None:
        class2 = _random_class()
    player1 = Player("Player1", [], class1.default_hero)
    player1.cant_fatigue = True
    player2 = Player("Player2", [], class2.default_hero)
    player2.cant_fatigue = True
    game = game_class(players=(player1, player2))
    game.start()
    _empty_mulligan(game)

    return game
Example #17
0
    def reset(self):
        from fireplace.game import Game
        from fireplace.player import Player

        deck1 = self.draft_mage()
        deck2 = self.draft_mage()
        player1 = Player("Player1", deck1, CardClass.MAGE.default_hero)
        player2 = Player("Player2", deck2, CardClass.MAGE.default_hero)

        self.game = Game(players=(player1, player2))
        self.start_game()

        self.new_game = True

        return self.create_board_state()
Example #18
0
def prepare_game(hero1=None, hero2=None, exclude=(), game_class=BaseTestGame):
    print("Initializing a new game")
    if hero1 is None:
        hero1 = random.choice(_heroes)
    if hero2 is None:
        hero2 = random.choice(_heroes)
    deck1 = _draft(hero=hero1, exclude=exclude)
    deck2 = _draft(hero=hero2, exclude=exclude)
    player1 = Player(name="Player1")
    player1.prepare_deck(deck1, hero1)
    player2 = Player(name="Player2")
    player2.prepare_deck(deck2, hero2)
    game = game_class(players=(player1, player2))
    game.start()

    return game
Example #19
0
def setup_basic_game():
    p1 = 6 #priest
    p2 = 7 #rogue

    deck1 = random_draft(CardClass(p1))
    deck2 = random_draft(CardClass(p2))
    player1 = Player("Player1", deck1, CardClass(p1).default_hero)
    player2 = Player("Player2", deck2, CardClass(p2).default_hero)
    game = Game(players=(player1, player2))
    game.start()

    #Skip mulligan
    for player in game.players:
        cards_to_mulligan = random.sample(player.choice.cards, 0)
        player.choice.choose(*cards_to_mulligan)

    return game
Example #20
0
    def init_game(self):
        """
        initializes a game between two players
        Returns:
            game: A game entity representing the start of the game after the mulligan phase
        """
        if self.is_basic:  #create quick simple game
            p1 = 6  #priest
            p2 = 7  #rogue
            deck1 = random_draft(CardClass(p1))
            deck2 = random_draft(CardClass(p2))
            self.players[0] = Player("Player1", deck1,
                                     CardClass(p1).default_hero)
            self.players[1] = Player("Player2", deck2,
                                     CardClass(p2).default_hero)
            self.game = Game(players=self.players)
            self.game.start()

            #Skip mulligan
            for player in self.game.players:
                cards_to_mulligan = random.sample(player.choice.cards, 0)
                player.choice.choose(*cards_to_mulligan)

            return self.game

        else:
            p1 = random.randint(1, 9)
            p2 = random.randint(1, 9)
            #initialize players and randomly draft decks
            #pdb.set_trace()
            deck1 = random_draft(CardClass(p1))
            deck2 = random_draft(CardClass(p2))
            self.players[0] = Player("Player1", deck1,
                                     CardClass(p1).default_hero)
            self.players[1] = Player("Player2", deck2,
                                     CardClass(p2).default_hero)
            #begin the game
            self.game = Game(players=self.players)
            self.game.start()

            #Skip mulligan for now
            for player in self.game.players:
                cards_to_mulligan = random.sample(player.choice.cards, 0)
                player.choice.choose(*cards_to_mulligan)

            return self.game
Example #21
0
def play_full_game(hero1, deck1, hero2, deck2):
    log.info('{} vs {}'.format(hero1, hero2))
    player1 = Player("Player1", deck1, hero1)
    player2 = Player("Player2", deck2, hero2)

    game = Game(players=(player1, player2))
    game.start()

    # Random mulligan for now
    for player in game.players:
        if player.choice:
            player.choice.choose()

    print(repr(game))
    return

    begin_time = datetime.datetime.utcnow()
    N = 1000
    for i in range(N):
        game2 = copy.deepcopy(game)
    end_time = datetime.datetime.utcnow()
    print((end_time - begin_time))
    return

    try:
        while True:
            state = GameState(game)

            #if state.winner() != None:
            #print("Winner: " + str(state.winner()))
            #break

            mcts = MonteCarlo(state, 1)
            play = mcts.get_play()

            log.info("GOT A MOVE!!!! %r", play)
            break

            fireplace.logging.log.setLevel(logging.DEBUG)
            play.play(game)
            fireplace.logging.log.setLevel(logging.WARN)
    except GameOver:
        state = GameState(game)
        if state.winner() != None:
            log.info("Winner: " + str(state.winner()))
Example #22
0
def main():
	deck1 = random_draft(hero=MAGE)
	deck2 = random_draft(hero=WARRIOR)
	player1 = Player(name="Player1")
	player1.prepare_deck(deck1, MAGE)
	player2 = Player(name="Player2")
	player2.prepare_deck(deck2, WARRIOR)

	game = Game(players=(player1, player2))
	game.start()

	for player in game.players:
		print("Can mulligan %r" % (player.choice.cards))
		mull_count = random.randint(0, len(player.choice.cards))
		cards_to_mulligan = random.sample(player.choice.cards, mull_count)
		player.choice.choose(*cards_to_mulligan)

	while True:
		heropower = game.current_player.hero.power
		# always play the hero power, just for kicks
		if heropower.is_usable():
			if heropower.has_target():
				heropower.use(target=random.choice(heropower.targets))
			else:
				heropower.use()
		# iterate over our hand and play whatever is playable
		for card in game.current_player.hand:
			if card.is_playable():
				target = None
				if card.choose_cards:
					card = random.choice(card.choose_cards)
				if card.has_target():
					target = random.choice(card.targets)
				print("Playing %r on %r" % (card, target))
				card.play(target=target)
			else:
				print("Not playing", card)

		# Randomly attack with whatever can attack
		for character in game.current_player.characters:
			if character.can_attack():
				character.attack(random.choice(character.targets))

		game.end_turn()
Example #23
0
 def delete_deck(self, name):
     if name not in self.decks:
         raise DeckNotExists
     self.decks.remove(name)
     if self.current_deck_name == name:
         self.player = None
         self.current_deck_name = None
         if len(self.decks) > 0:
             self.current_deck_name = list(self.decks)[0]
             deck = self.decks[self.current_deck_name]
             self.player = Player(self.id, deck.card_list, deck.hero)
Example #24
0
def setup_game():
    from fireplace.game import Game
    from fireplace.player import Player
    fireplace.cards.filter(name="Garrosh")

    player1 = Player("OddWarrior", warrior_deck,
                     CardClass.WARRIOR.default_hero)
    player2 = Player("MurlocPaladin", paladin_deck,
                     CardClass.PALADIN.default_hero)

    game = Game(players=(player1, player2))
    game.start()

    for player in game.players:
        mull_count = 0
        cards_to_mulligan = []
        player.choice.choose(*cards_to_mulligan)

        game.begin_turn(player)

    return game
Example #25
0
def setup_game(deck, player_name, opponents_deck):
	from fireplace.game import Game
	from fireplace.player import Player

	#Some cards from these decks aren't implemented which means that they won't have an effect,
	#if they are a minion then it will have it's stats but not the battlecry effect, spell will just do nothing
	#either implement it or talk about it
	deck1 = deck
	deck2 = opponents_deck

	#global so it can carry over to other functions
	global name
	name = player_name

	#It seems that player classes influence the deck win rate, Hunters win more than Warlocks due to the dumb AI
	player1 = Player(name, deck1, CardClass.WARRIOR.default_hero)
	player2 = Player("Oppenent", deck2, CardClass.MAGE.default_hero)

	game = Game(players=(player1, player2))
	game.start()

	return game
Example #26
0
    def initGame(self):
        self.init_envi()

        if self.is_basic:  #create quick simple game
            p1 = 6  #priest
            p2 = 7  #rogue
        else:
            p1 = random.randint(1, 9)
            p2 = random.randint(1, 9)
        deck1 = random_draft(CardClass(p1))
        deck2 = random_draft(CardClass(p2))
        self.players[0] = Player("Player1", deck1, CardClass(p1).default_hero)
        self.players[1] = Player("Player2", deck2, CardClass(p2).default_hero)
        game = Game(players=self.players)
        game.start()

        #Skip mulligan for now
        for player in self.game.players:
            cards_to_mulligan = random.sample(player.choice.cards, 0)
            player.choice.choose(*cards_to_mulligan)

        return game
Example #27
0
 def __init__(self, username, password, decks={}):
     self.id = username
     self._password = self.encode(password)
     self._decks = decks
     self._current_deck_name = None
     self._player = None
     if len(self.decks) > 0:
         self.current_deck_name = list(self.decks)[0]
         deck = self.decks[self.current_deck_name]
         print(deck.card_list)
         print(deck.hero)
         self.player = Player(self.id, deck.card_list, deck.hero)
     self._playing_room = -1
Example #28
0
    def create_game(self, payload):
        # self.game_id = payload["GameID"]
        player_data = payload["Players"]
        players = []
        for player in player_data:
            # Shuffle the cards to prevent information leaking
            cards = player["Cards"]
            random.shuffle(cards)
            p = Player(player["Name"], cards, player["Hero"])
            players.append(p)

        INFO("Initializing a Kettle game with players=%r", players)
        game = Game(players=players)
        manager = KettleManager(game)
        game.manager.register(manager)
        game.current_player = game.players[0]  # Dumb.
        game.start()

        # Skip mulligan
        for player in game.players:
            player.choice = None

        return manager
Example #29
0
def find_card_pair(onlyresult=1):
    card_class = CardClass.MAGE  #カードクラスを設定することは必須
    allCards = get_all_cards(card_class, costMax=2)
    vanillas = get_all_vanillas(allCards)
    nonVanillas = get_all_non_vanillas(allCards)
    spells = get_all_spells(allCards)

    #良いカードペアを漠然と探す旅に出る2枚は呪文カードしばり
    for matchNumber in range(10):
        count1 = 0
        count2 = 0

        #ヒーローパワーを消す、というのもよいかも。
        nonvanillaName1 = random.choice(nonVanillas)
        nonvanilla1 = nonvanillaName1.id
        nonvanillaName2 = random.choice(spells)  #この呪文によって、まえのカードが活かされるかどうか
        nonvanilla2 = nonvanillaName2.id

        print(" specific cards : %r%r" % (nonvanillaName1, nonvanillaName2))
        for repeat in range(25):
            if onlyresult == 0:
                print("    GAME %d" % repeat, end="  -> ")
            #set decks and players
            deck1 = []
            position = random.randint(1, 7)
            for i in range(position):
                deck1.append((random.choice(vanillas)).id)
            deck1.append(nonvanilla1)
            deck1.append(nonvanilla2)
            for i in range(8 - position):  #デッキは10枚
                deck1.append(random.choice(vanillas).id)
            player1 = Player("Player1", deck1, card_class.default_hero)
            deck2 = copy.deepcopy(deck1)
            random.shuffle(deck2)
            player2 = Player("Player2", deck2, card_class.default_hero)
            #set a game
            game = Game(players=(player1, player2))
            game.start()

            for player in game.players:
                #print("Can mulligan %r" % (player.choice.cards))
                mull_count = random.randint(0, len(player.choice.cards))
                cards_to_mulligan = random.sample(player.choice.cards,
                                                  mull_count)
                player.choice.choose(*cards_to_mulligan)
            game.player1.hero.max_health = 10
            game.player2.hero.max_health = 10
            turnNumber = 0
            if onlyresult == 0:
                print("Turn ", end=':')
            while True:
                turnNumber += 1
                if onlyresult == 0:
                    print(turnNumber, end=":")
                #StandardRandom(game)#ここはもう少し賢くする
                weight = [
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                ]
                weight[0] = weight[1] = 5
                weight[26] = 10
                weight[2] = weight[3] = weight[6] = weight[7] = 5
                weight[10] = weight[11] = weight[12] = weight[13] = 5
                StandardStep1(game, debugLog=False)
                if game.state != State.COMPLETE:
                    try:
                        game.end_turn()
                    except GameOver:  #まれにおこる
                        pass
                if game.state == State.COMPLETE:
                    if game.current_player.playstate == PlayState.WON:
                        winner = game.current_player.name
                        break
                    elif game.current_player.playstate == PlayState.LOST:
                        winner = game.current_player.opponent.name
                        break
                    else:
                        winner = "DRAW"
                    break
            if onlyresult == 0:
                print("%s won." % winner)
            if winner == "Player1":
                if onlyresult == 1:
                    print("O", end=".")
                count1 += 1
            elif winner == "Player2":
                if onlyresult == 1:
                    print("X", end=".")
                count2 += 1
        print("(%d : %d)" % (count1, count2), end=" ")  #25戦で10点差があれば有意な差あり
        if count1 - count2 >= 10:
            print("Significant")
        else:
            print("")
    pass
Example #30
0
def investigate_card_pair(onlyresult=0):
    card_class = CardClass.HUNTER
    allCards = get_all_cards(card_class)
    vanillas = get_all_vanillas(allCards)
    nonVanillas = get_all_non_vanillas(allCards)

    count1 = 0
    count2 = 0

    #ヒーローパワーを消す、というのもよいかも。
    #良いカードペアを漠然と探す旅に出る?
    nonvanilla1 = 'EX1_045'  #random.choice(nonVanillas).id#自分で指定してもよい
    nonvanilla2 = 'EX1_332'  #random.choice(nonVanillas).id#
    #古代の番人:EX1_045:攻撃できない。
    #沈黙:EX1_332:ミニオン1体を沈黙させる

    print(" specific cards : %r%r" % (nonvanilla1, nonvanilla2))
    for repeat in range(50):
        print("    GAME %d" % repeat, end="  -> ")
        #set decks and players
        deck1 = []
        position = random.randint(1, 7)
        for i in range(position):
            deck1.append((random.choice(vanillas)).id)
        deck1.append(nonvanilla1)
        deck1.append(nonvanilla2)
        for i in range(8 - position):  #デッキは10枚
            deck1.append(random.choice(vanillas).id)
        player1 = Player("AAAA", deck1, card_class.default_hero)
        deck2 = copy.deepcopy(deck1)
        random.shuffle(deck2)
        player2 = Player("BBBB", deck2, card_class.default_hero)
        #set a game
        game = Game(players=(player1, player2))
        game.start()

        for player in game.players:
            #print("Can mulligan %r" % (player.choice.cards))
            mull_count = random.randint(0, len(player.choice.cards))
            cards_to_mulligan = random.sample(player.choice.cards, mull_count)
            player.choice.choose(*cards_to_mulligan)
        game.player1.hero.max_health = 10  # ヒーローのHPは10
        game.player2.hero.max_health = 10

        turnNumber = 0
        print("Turn ", end=':')
        while True:
            turnNumber += 1
            print(turnNumber, end=":")
            weight = [
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            ]
            weight[0] = weight[1] = 5
            weight[26] = 10
            weight[2] = weight[3] = weight[6] = weight[7] = 5
            weight[10] = weight[11] = weight[12] = weight[13] = 5
            StandardStep1(game, debugLog=False)
            #StandardRandom(game,debugLog=True)
            #ここはもう少し賢い人にやってほしい
            if game.state != State.COMPLETE:
                try:
                    game.end_turn()
                except GameOver:  #まれにおこる
                    pass
            else:
                if game.current_player.playstate == PlayState.WON:
                    winner = game.current_player.name
                    break
                elif game.current_player.playstate == PlayState.LOST:
                    winner = game.current_player.opponent.name
                    break
                else:
                    winner = "DRAW"
                    break
        print("%s won." % winner)
        if winner == "AAAA":
            count1 += 1
        elif winner == "BBBB":
            count2 += 1
    print("%d : %d" % (count1, count2))