Пример #1
0
            def deathrattle(self, position):
                summoned = []
                if not board.full():
                    token = Minion('Big Bad Wolf', 3, 2, 1, type='Beast')
                    board.put(token, position)
                    summoned.append(token)

                return summoned
Пример #2
0
            def battlecry(self):
                summoned = []
                if len(board.minions) < 7:
                    token = Minion('Cat', 1, 1, 1, type='Beast', summoned=True)
                    board.put(token, instance.get_position() + 1)
                    summoned.append(token)

                return summoned
Пример #3
0
 def __init__(self,
              battleground,
              side,
              x=-1,
              y=-1,
              name="Flappy",
              color=libtcod.dark_green):
     super(Flappy, self).__init__(battleground, side, x, y, name, color)
     self.death_quote = "I'll be back, like a boo... me..."
     self.minion = Minion(self.bg, self.side, name="goblin")
Пример #4
0
 def create_enemies():
     for row in range(bd.rows):
         for col in range(bd.columns):
             if bd.canvas[row, col] == 4:
                 if bd.level == 1:
                     bd.enemies.append(Enemy(row, col))
                 elif bd.level == 2:
                     rand = np.random.random_sample()
                     if rand < 0.4:
                         bd.enemies.append(Enemy(row, col))
                     else:
                         bd.enemies.append(Minion(row, col))
                 elif bd.level == 3:
                     rand = np.random.random_sample()
                     if rand < 0.2:
                         bd.enemies.append(Enemy(row, col))
                     elif rand < 0.5:
                         bd.enemies.append(Minion(row, col))
                     else:
                         bd.enemies.append(Boss(row, col))
Пример #5
0
    def test_game_result_2x2_win_and_tie_sampling(self):
        minion1 = Minion(2, 1)
        minion2 = Minion(1, 1)
        board_one = [minion1, minion2]
        minion3 = Minion(2, 2)
        minion4 = Minion(1, 1)
        board_two = [minion3, minion4]

        scenario = Scenario()
        scenario.set_board(board_one, board_two)
        args = {'sampling_amount': 20000}
        result = Oracle().calculate_game_result_density(scenario,
                                                        method='sampling',
                                                        args=args)

        print('error: ', abs(50 - result.player_two_win_percentage))
        self.assertEqual(result.player_one_win_percentage, 0)
        self.assertGreater(5, abs(50 - result.player_two_win_percentage))
        self.assertEqual(result.lethal_one, 0)
        self.assertEqual(result.lethal_two, 0)
        self.assertGreater(5, abs(50 - result.draw))
Пример #6
0
    def test_game_result_7x7_sampling(self):
        board_one = []
        board_two = []
        for i in range(7):
            board_one.append(Minion(10, 10))
        for i in range(7):
            board_two.append(Minion(1, 1))

        scenario = Scenario()
        scenario.set_board(board_one, board_two)
        args = {'sampling_amount': 2000}
        result = Oracle().calculate_game_result_density(scenario,
                                                        method='sampling',
                                                        args=args)

        print('error: ', abs(100 - result.player_one_win_percentage))
        self.assertGreater(5, abs(100 - result.player_one_win_percentage))
        self.assertGreater(5, abs(0 - result.player_two_win_percentage))
        self.assertEqual(result.lethal_one, 0)
        self.assertEqual(result.lethal_two, 0)
        self.assertEqual(result.draw, 0)
Пример #7
0
            def battlecry(self):
                summoned = []
                if not board.full():
                    token = Minion('Murloc',
                                   1,
                                   1,
                                   1,
                                   type='Murloc',
                                   summoned=True)
                    board.put(token, instance.get_position() + 1)
                    summoned.append(token)

                return summoned
Пример #8
0
    def stage_boss(self) -> None:
        """
        Sets up stage two
        :return: none
        """
        # transition
        self.transition = arcade.load_texture("images/boss_screen.png")
        # setting up player
        self.player = Player(400, 50)
        # setting up enemies
        self.enemies_engine = []
        self.towers_engine = []
        self.enemies = Sprites()
        self.towers = Sprites()
        self.obstacles = arcade.SpriteList()
        self.enemies.append(Minion(400, 400))
        self.enemies.append(Minion(400, 400))
        self.enemies.append(Minion(400, 400))
        self.enemies.append(Minion(400, 400))
        self.enemies.append(Minion(400, 400))
        self.enemies.append(Minion(400, 400))
        self.enemies.append(Minion(400, 400))
        self.enemies.append(Minion(400, 400))
        self.enemies.append(Boss(400, 400))
        for enemy in self.enemies:
            self.enemies_engine.append(
                CollisionDetection(enemy, self.obstacles))
        self.towers.append(Mage(100, 50, 48, 52))
        self.towers.append(Mage(50, 100, 48, 52))

        self.towers.append(Mage(700, 750, 48, 52))
        self.towers.append(Mage(750, 700, 48, 52))

        self.towers.append(Mage(100, 750, 48, 52))
        self.towers.append(Mage(50, 700, 48, 52))

        self.towers.append(Mage(700, 50, 48, 52))
        self.towers.append(Mage(750, 100, 48, 52))
        for tower in self.towers:
            self.towers_engine.append(
                CollisionDetection(tower.fireball, self.rooms[self.world].wall_list))
            self.enemies.append(tower.fireball)
        for item in self.rooms[self.world].wall_list:
            self.obstacles.append(item)
        for item in self.rooms[self.world].traps_list:
            self.obstacles.append(item)
        # create engines
        self.player_engine = CollisionDetection(self.player, self.rooms[self.world].wall_list,
                                                self.rooms[self.world].traps_list)
Пример #9
0
            def deathrattle(self, position):
                summoned = []
                for _ in range(self.attack):
                    if not board.full():
                        token = Minion(name,
                                       1,
                                       1,
                                       1,
                                       type='Beast',
                                       summoned=True)
                        board.put(token, position)
                        summoned.append(token)

                return summoned
Пример #10
0
            def deathrattle(self, position):
                summoned = []

                if len(board.minions) < 7:
                    token = Minion('Microbot',
                                   1,
                                   1,
                                   1,
                                   type='Mech',
                                   summoned=True)
                    board.put(token, position)
                    summoned.append(token)

                return summoned
Пример #11
0
def run_game():

    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Minion Invasion")

    play_button = Button(ai_settings, screen, "Play")
    stats = Gamestats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    minion = Minion(ai_settings, screen)
    evilminion = Evilminion(ai_settings, screen)
    bullets = Group()
    evilminions = Group()
    gf.create_fleet(ai_settings, screen, minion, evilminions)
    bg_color = (148, 227, 246)
    pygame.mixer.music.load("images/minionsmarch.mp3")
    pygame.mixer.music.play(-1, 0.0)

    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, minion,
                        evilminions, bullets)
        if stats.game_active:
            minion.update()
            gf.update_bullets(ai_settings, screen, stats, sb, minion,
                              evilminions, bullets)
            gf.update_evilminions(ai_settings, screen, stats, sb, minion,
                                  evilminions, bullets)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

        gf.update_screen(ai_settings, screen, stats, sb, minion, evilminions,
                         bullets, play_button)
Пример #12
0
    def minions(self, target='*', expr_form='glob', **kwargs):
        """
        Creates a list of minions based on target and expr_form.

        @param target: Minion target
        @param expr_form: How to target minions
        @return List of minions

        """
        job = self.prepare_job_minions(target, expr_form)
        resp = self.run_jobs([job], job.kwargs.get('timeout') or 60)
        # Only one job so take the first
        resp = resp.values()[0]

        # Create minion model for all returned grains
        return [Minion(grains) for id_, grains in resp.iteritems()]
 def __init__(self, environment, initial_hyper_parameters):
     self.hyper_parameters = initial_hyper_parameters
     # these are the parameters we want to use with population based training
     self.learning_rate = self.hyper_parameters['learning_rate']
     self.discount_factor = self.hyper_parameters['discount_factor']
     self.unroll_length = self.hyper_parameters['unroll_length']
     # Just using the minions to gather experience from different instances of environment
     self.minions = [
         Minion(self, environment, i)
         for i in range(initial_hyper_parameters['minions_num'])
     ]
     # We're going to use one network for all of our minions
     self.network = ActorCriticNetwork(observation_dims=4, output_dims=2)
     self.network.compile(optimizer=tf.keras.optimizers.Adam(
         learning_rate=self.learning_rate))
     # Since Actor-Critic is an on-policy method, we will not use a replay buffer
     self.states = []
     self.actions = []
     self.discounted_rewards = []
     self.losses = []
Пример #14
0
def thread_task(input_queue, output_queue, result_queue, thread_max):
    for thread_id in range(thread_max):
        minion = Minion(thread_id, input_queue, output_queue, result_queue)
        minion.daemon = True
        minion.start()
    input_queue.join()
Пример #15
0
 def perform_deathrattle(self, scenario, player, position):
     scenario.summon_minion(Minion(1, 1), player, position)
Пример #16
0
import random
import constant
from player import Player
from controllers import EventHandler
from minion import Minion
from hero import Hero, HeroPower

Minion.load_minions()
HeroPower.load_hero_powers()
Hero.load_heros()

print('Input number of players: ')
num_players = int(input())
print('All AI game? y/n: ')
if input() == 'y':
    num_humans = 0
    all_ai = True
else:
    all_ai = False
    print('Input number of human players: ')
    num_humans = int(input())

event_handler = EventHandler()
event_handler.setup_all_players(num_humans, num_players - num_humans)

for player in event_handler.players.values():
    print(player)

#kelth = Player('KTPlayer_' + str(Player.p_id), Hero.hero_dict[constant.KELTHUZAD_ID])
kelth_id = -1
Пример #17
0
    def new(player, card=None, name=None):
        board = player.board
        if card is not None:
            name = card.name

        # Tier 1
        if name == 'Alleycat':
            instance = Minion(name, 1, 1, 1, type='Beast')

            def battlecry(self):
                summoned = []
                if len(board.minions) < 7:
                    token = Minion('Cat', 1, 1, 1, type='Beast', summoned=True)
                    board.put(token, instance.get_position() + 1)
                    summoned.append(token)

                return summoned

            instance.battlecry = MethodType(battlecry, instance)
        elif name == 'Mecharoo':
            instance = Minion(name, 1, 1, 1, type='Mech')

            def deathrattle(self, position):
                summoned = []

                if len(board.minions) < 7:
                    token = Minion('Microbot',
                                   1,
                                   1,
                                   1,
                                   type='Mech',
                                   summoned=True)
                    board.put(token, position)
                    summoned.append(token)

                return summoned

            instance.deathrattles.append(MethodType(deathrattle, instance))
        elif name == 'Murloc Tidehunter':
            instance = Minion(name, 2, 1, 1, type='Murloc')

            def battlecry(self):
                summoned = []
                if not board.full():
                    token = Minion('Murloc',
                                   1,
                                   1,
                                   1,
                                   type='Murloc',
                                   summoned=True)
                    board.put(token, instance.get_position() + 1)
                    summoned.append(token)

                return summoned

            instance.battlecry = MethodType(battlecry, instance)
        elif name == 'Selfless Hero':
            instance = Minion(name, 2, 1, 1)

            def deathrattle(self, position):
                non_bubble = filter(lambda x: not x.bubble, board.minions)
                if len(non_bubble) > 0:
                    minion = random.choice(non_bubble)
                    minion.bubble = True

                return []  # no new minions summoned

            instance.deathrattles.append(MethodType(deathrattle, instance))
        elif name == 'Rockpool Hunter':
            instance = Minion(name, 2, 3, 1, type='Murloc')

            def battlecry(self, target):
                target.attack += 1
                target.health += 1

                return []

            instance.valid_targets = board.murlocs
            instance.targeted_battlecry = MethodType(battlecry, instance)
        elif name == 'Vulgar Homunculus':
            instance = Minion(name, 2, 4, 1, type='Demon', taunt=True)

            def battlecry(self):
                player.hero.hp -= 2

                return []

            instance.battlecry = MethodType(battlecry, instance)
        elif name == 'Wrath Weaver':
            instance = Minion(name, 1, 1, 1)

            def trigger(self):
                player.hero.hp -= 1
                self.attack += 2
                self.health += 2

            def on_play(self):
                board.on_demon_played.append(self)

            instance.on_play = MethodType(on_play, instance)
            instance.trigger = MethodType(trigger, instance)
        elif name == 'Micro Machine':
            instance = Minion(name, 1, 2, 1, type='Mech')

            def trigger(self):
                self.attack += 1

            def on_play(self):
                board.on_turn_start.append(self)

            instance.on_play = MethodType(on_play, instance)
            instance.trigger = MethodType(trigger, instance)
        elif name == 'Murloc Tidecaller':
            instance = Minion(name, 1, 2, 1, type='Murloc')

            def trigger(self):
                print('Triggered!')
                self.attack += 1

            def on_play(self):
                board.on_murloc_summoned.append(self)

            instance.on_play = MethodType(on_play, instance)
            instance.trigger = MethodType(trigger, instance)
        elif name == 'Dire Wolf Alpha':
            instance = Minion(name, 2, 2, 1, type='Beast')

            def add_effect(self, target):
                target.effects.append(self)

                target.attack += 1

            def remove_effect(self, target):
                target.effects.remove(self)

                target.attack -= 1

            instance.add_effect = MethodType(add_effect, instance)
            instance.remove_effect = MethodType(remove_effect, instance)
        elif name == 'Righteous Protector':
            instance = Minion(name, 1, 1, 1, taunt=True, bubble=True)
        elif name == 'Voidwalker':
            instance = Minion(name, 1, 3, 1, type='Demon', taunt=True)

        # Tier 2
        elif name == 'Spawn of N\'Zoth':
            instance = Minion(name, 2, 2, 2)

            def deathrattle(self, position):
                for minion in board.minions:
                    minion.attack += 1
                    minion.health += 1

                return []

            instance.deathrattles.append(MethodType(deathrattle, instance))
        elif name == 'Kindly Grandmother':
            instance = Minion(name, 1, 1, 2, type='Beast')

            def deathrattle(self, position):
                summoned = []
                if not board.full():
                    token = Minion('Big Bad Wolf', 3, 2, 1, type='Beast')
                    board.put(token, position)
                    summoned.append(token)

                return summoned

            instance.deathrattles.append(MethodType(deathrattle, instance))
        elif name == 'Mounted Raptor':
            instance = Minion(name, 3, 2, 2, type='Beast')

            def deathrattle(self, position):
                summoned = []
                if not board.full():
                    minion_name = random.choice([
                        'Righteous Protector',
                        'Selfless Hero',
                        'Wrath Weaver',
                        'Alleycat',
                        'Voidwalker',
                        'Mecharoo',
                        'Murloc Tidecaller',
                        # 'Nathrezim Overseer',     # TODO: test if this is possible
                        'Pogo-Hopper',
                        'Shifter Zerus',
                        'Toxfin'
                    ])
                    minion = Minions.new(player=player, name=minion_name)
                    board.put(minion, position)
                    summoned.append(minion)

                return summoned

            instance.deathrattles.append(MethodType(deathrattle, instance))
        elif name == 'Rat Pack':
            instance = Minion(name, 2, 2, 2, type='Beast')

            def deathrattle(self, position):
                summoned = []
                for _ in range(self.attack):
                    if not board.full():
                        token = Minion(name,
                                       1,
                                       1,
                                       1,
                                       type='Beast',
                                       summoned=True)
                        board.put(token, position)
                        summoned.append(token)

                return summoned

            instance.deathrattles.append(MethodType(deathrattle, instance))
        elif name == 'Scavenging Hyena':
            instance = Minion(name, 2, 2, 2, type='Beast')

            def trigger(self):
                self.attack += 2
                self.health += 1

            def on_play(self):
                board.on_beast_died.append(self)

            instance.on_play = MethodType(on_play, instance)
            instance.trigger = MethodType(trigger, instance)
        elif name == 'Nathrezim Overseer':
            instance = Minion(name, 2, 4, 2, type='Demon')

            def battlecry(self, target):
                target.attack += 2
                target.health += 2

                return []

            instance.targeted_battlecry = MethodType(battlecry, instance)
            instance.valid_targets = board.demons
        elif name == 'Annoy-o-Tron':
            instance = Minion(name,
                              1,
                              2,
                              2,
                              type='Mech',
                              taunt=True,
                              bubble=True)
        elif name == 'Harvest Golem':
            instance = Minion(name, 2, 3, 2, type='Mech')

            def deathrattle(self, position):
                summoned = []
                if not board.full():
                    token = Minion(name, 2, 1, 1, type='Mech', summoned=True)
                    board.put(token, position)
                    summoned.append(token)

                return summoned

            instance.deathrattles.append(MethodType(deathrattle, instance))
        elif name == 'Kaboom Bot':
            instance = Minion(name, 2, 2, 2, type='Mech')

            def deathrattle(self, position):
                target = player.current_opponent.board.get_random()
                board.damage(target, 4)

                return []

            instance.deathrattles.append(MethodType(deathrattle, instance))
        elif name == 'Metaltooth Leaper':
            instance = Minion(name, 3, 3, 2, type='Mech')

            def battlecry(self):
                for mech in board.mechs:
                    mech.attack += 2

                return []

            instance.battlecry = MethodType(battlecry, instance)
        elif name == 'Pogo-Hopper':
            instance = Minion(name, 1, 1, 2, type='Mech')

            def battlecry(self):
                self.attack += board.pogos_played * 2
                self.health += board.pogos_played * 2

                return []

            def on_play(self):
                board.pogos_played += 1

            instance.battlecry = MethodType(battlecry, instance)
            instance.on_play = MethodType(on_play, instance)
        elif name == 'Nightmare Amalgam':
            instance = Minion(name, 3, 4, 2, type='All')
        elif name == 'Shielded Minibot':
            instance = Minion(name, 2, 2, 2, type='Mech', bubble=True)
        elif name == 'Murloc Warleader':
            # TODO: fix
            instance = Minion(name, 3, 3, 2, type='Murloc')

            def add_effect(self, target):
                target.attack += 2

            def remove_effect(self, target):
                target.attack -= 2

            def on_play(self):
                pass

            instance.add_effect = MethodType(add_effect, instance)
            instance.remove_effect = MethodType(remove_effect, instance)
            instance.on_play = MethodType(on_play, instance)
        elif name == 'Old Murk-Eye':
            # TODO: fix
            instance = Minion(name, 2, 4, 2, type='Murloc')

            def add_effect(self, target):
                self.attack += 1

            def remove_effect(self, target):
                self.attack -= 1

            def on_play(self):
                pass

            instance.add_effect = MethodType(add_effect, instance)
            instance.remove_effect = MethodType(remove_effect, instance)
            instance.on_play = MethodType(on_play, instance)

        # Tier 3
        elif name == 'Psych-o-Tron':
            instance = Minion(name,
                              3,
                              4,
                              3,
                              type='Mech',
                              taunt=True,
                              bubble=True)

        instance.board = board
        if card is not None:
            instance.attack += card.attack_buff
            instance.health += card.health_buff

        return instance