Exemplo n.º 1
0
    def setUp(self):
        self.ability_1 = {'deal_damage_to_opponent': partial(abilities.deal_damage_to_opposite_player, damage=2)}
        self.ability_2 = {DIVINE_SHIELD: abilities.divine_shield}
        self.ability_charge = {CHARGE: abilities.charge}

        self.card_1 = Minion(name='C1', cost=1, abilities=dict(), attack=1, health=1, minion_type=None)
        self.card_2 = Minion(name='C2', cost=1, abilities=dict(), attack=1, health=1, minion_type=None)

        self.card_3 = Minion(name='C3', cost=1, abilities=dict(), attack=2, health=2, minion_type=None)
        self.card_4 = Minion(name='C4', cost=1, abilities=dict(), attack=2, health=2, minion_type=None)

        self.card_5 = Minion(name='C5', cost=1, abilities=dict(), attack=3, health=3, minion_type=None)
        self.card_6 = Minion(name='C6', cost=1, abilities=dict(), attack=3, health=3, minion_type=None)

        self.card_7 = Minion(name='C7', cost=1, abilities=dict(), attack=4, health=4, minion_type=None)
        self.card_8 = Minion(name='C8', cost=1, abilities=dict(), attack=4, health=4, minion_type=None)

        self.spell_1 = Spell(name='PaSpell', cost=1, abilities={**self.ability_1, **self.ability_2})

        self.hero_1 = Hero(name='Pamisio', cost=0, abilities=dict(), attack=0, health=20, hero_class=None)
        self.hero_2 = Hero(name='Pamewcia', cost=0, abilities=dict(), attack=0, health=20, hero_class=None)

        self.first_player = Player(self.hero_1, [], [], [], [])
        self.second_player = Player(self.hero_2, [], [], [], [])

        self.state = State(self.first_player, self.second_player)
Exemplo n.º 2
0
def play_start_agent_offensive_vs_mcts():
    deck1, deck2 = build_decks()
    hero_1 = Hero(name='Agent',
                  cost=0,
                  abilities=dict(),
                  attack=0,
                  health=20,
                  hero_class=None)
    hero_2 = Hero(name='MCTS',
                  cost=0,
                  abilities=dict(),
                  attack=0,
                  health=20,
                  hero_class=None)

    first_player = Player(hero_1, [], deck1, [], [])
    second_player = Player(hero_2, [], deck2, [], [])
    state = State(first_player, second_player)

    state.draw_card()
    state.draw_card()
    state.switch_players()

    state.draw_card()
    state.draw_card()
    state.draw_card()

    turns = 1
    root_wins = []
    root_loses = []
    best_child_wins = []
    best_child_losses = []
    visited_nodes = []

    while not state.is_terminal:
        state.new_turn_for_one_player()
        # state, path = get_random_state(state)
        state, path = get_new_state(state, evaluation_utils.offensive_strategy)
        #print("\n\nAction taken by {}: {}\n\n".format(state.current_player.name, path))
        #print_state(state.get_player_by_name(hero_1.name), state.get_player_by_name(hero_2.name))
        if state.is_terminal:
            break

        start_node = get_node_from_state(state)
        best_child = perform_mcts(start_node)
        state, path = best_child['state'], best_child['path']
        root_wins.append(start_node['wins'])
        root_loses.append(start_node['losses'])
        best_child_wins.append(best_child['wins'])
        best_child_losses.append(best_child['losses'])
        visited_nodes.append(start_node['wins'] + start_node['losses'])

        #print("\n\nAction taken by {}: {}\n\n".format(state.current_player.name, path))
        #print_state(state.get_player_by_name(hero_1.name), state.get_player_by_name(hero_2.name))
        turns += 1
        visited_nodes.append(start_node['wins'] + start_node['losses'])
    mcts_win = 1 if state.get_player_by_name('Agent').health == 0 else 0
    #print_state(state.get_player_by_name(hero_1.name), state.get_player_by_name(hero_2.name))

    return turns, root_wins, root_loses, best_child_wins, best_child_losses, visited_nodes, mcts_win
Exemplo n.º 3
0
def game():
    deck1, deck2 = build_decks()
    hero_1 = Hero(name='Pamisio',
                  cost=0,
                  abilities=dict(),
                  attack=0,
                  health=20,
                  hero_class=None)
    hero_2 = Hero(name='Pamewcia',
                  cost=0,
                  abilities=dict(),
                  attack=0,
                  health=20,
                  hero_class=None)

    first_player = Player(hero_1, [], deck1, [], [])
    second_player = Player(hero_2, [], deck2, [], [])
    state = State(first_player, second_player)

    for i in range(2):
        state.draw_card()

    state.switch_players()

    for i in range(3):
        state.draw_card()

    state.switch_players()

    for mana in range(1, 10):
        state.draw_card()
        print("Player {}".format(1))
        print("Hand: {}".format([(minion.name, minion.cost)
                                 for minion in state.current_player.hand]))
        for card in state.current_player.board:
            card.summoning_sickness = False
        state = get_new_state(state, mana, evaluation_utils.offensive_strategy)
        print("Player 1 health = {} \nPlayer 2 health = {}".format(
            state.current_player.hero.health,
            state.opposite_player.hero.health))
        state.switch_players()

        state.draw_card()
        print("\nPlayer {}".format(2))
        print("Hand: {}".format([(minion.name, minion.cost)
                                 for minion in state.current_player.hand]))
        for card in state.current_player.board:
            card.summoning_sickness = False
        state = get_new_state(state, mana, evaluation_utils.offensive_strategy)
        print("Player 1 health = {} \nPlayer 2 health = {}".format(
            state.current_player.hero.health,
            state.opposite_player.hero.health))
        state.switch_players()

        print("\n----------------\n")

        if state.is_terminal:
            break
Exemplo n.º 4
0
    def setUp(self):
        with open(CARDS_FILE) as json_file:
            data = json.load(json_file)
            self.abusive_sergeant = card_from_json(data[0])
            self.agent_squire = card_from_json(data[1])
            self.divine_strength = card_from_json(data[2])
            self.selfless_hero = card_from_json(data[3])
            self.divine_favor = card_from_json(data[4])
            self.seal_of_champions = card_from_json(data[5])
            self.steward_of_darshire = card_from_json(data[6])
            self.wolfrider = card_from_json(data[7])
            self.blessing_of_kings = card_from_json(data[8])
            self.defender_of_argus = card_from_json(data[9])

        self.hero_1 = Hero(name='Pamisio', cost=0, abilities=dict(), attack=0, health=20, hero_class=None)
        self.hero_2 = Hero(name='Pamewcia', cost=0, abilities=dict(), attack=0, health=20, hero_class=None)

        self.first_player = Player(self.hero_1, [], [], [], [])
        self.second_player = Player(self.hero_2, [], [], [], [])

        self.state = State(self.first_player, self.second_player)