Пример #1
0
    def get_moves(self):

        coords = self.owner_view.coords
        # items_at = self.view[coords]

        # is_es_at = 'EnergySource' in items_at
        is_first = self.owner_view.sight == 1

        #Get all this info up front
        adj = bg.coords_within_distance(coords, 1, include_center=False)

        moves = dict()

        if is_first:
            build_coords = choice(adj)

            #Always build
            build_move = builds.BuildMove(
                build_coords,
                max_hp=1,
                power=1,
                attack_range=0,
                speed=0,  #self.next_speed.val,
                sight=0,
                energy=0,
                movement=0,
                message=self.message_to_give,
                spread=64,
                absorb=3)
            #absorb=40)

            moves[bg.MoveType.BUILD] = [build_move]

            return moves
        else:
            #Always attack
            # attack_coords = choice(adj)
            attack_coords = self.owner_view.coords

            attack_move = bg.Move(move_type=bg.MoveType.ATTACK,
                                  target_coords=attack_coords)

            moves[bg.MoveType.ATTACK] = [attack_move]

            #go the to center
            t_coords = (32, 32)
            movement = get_approach_moves(self.owner_view.coords, t_coords)
            moves[bg.MoveType.MOVE] = movement

            return moves
Пример #2
0
    def get_moves(self):
        coords = self.owner_view.coords
        items_at = self.view[coords]

        is_es_at = 'EnergySource' in items_at

        #Get all this info up front
        adj = bg.coords_within_distance(coords, 1, include_center=False)

        #Only deal with visible coords
        adj = [c for c in adj if c in self.view]

        adj_wo_bot = [c for c in adj if not 'Bot' in self.view[c]]
        adj_w_bot = [c for c in adj if not c in adj_wo_bot]
        adj_w_ally = [c for c in adj_w_bot if\
                      self.view[c]['Bot'].player == self.owner_view.player]
        # adj_w_enemy = [b for b in adj_w_bot if not b in adj_w_ally]

        moves = dict()

        attack_range = 3
        spread = 2

        #Of all the squares to attack,
        #choose the one that hits the most enemies
        #of the ones that don't hit any allies
        in_range = bg.coords_within_distance(coords, attack_range)
        in_range = list([c for c in in_range if c in self.view])

        num_enemy_hit_from_c = dict()
        for c in in_range:
            hit_coords = bg.coords_within_distance(c, spread)
            allies_hit = get(self.view, hit_coords, player=self.player)
            if allies_hit:
                continue

            num_enemies_hit = len(get(self.view, hit_coords, item_type='Bot'))
            #Don't attack
            #You might just hit an ally anyways
            if not num_enemies_hit:
                continue

            num_enemy_hit_from_c[c] = num_enemies_hit

        attack_candidates = list(num_enemy_hit_from_c)

        #There's a good place to attack, so attack there
        if attack_candidates:
            # print(self.coords)
            # print('')
            attack_candidates.sort(key=lambda c: num_enemy_hit_from_c[c])
            attack_coords = attack_candidates[-1]

            attack_move = bg.Move(move_type=bg.MoveType.ATTACK,
                                  target_coords=attack_coords)

            moves[bg.MoveType.ATTACK] = [attack_move]

        if is_es_at:
            #Either build or give energy
            adj = bg.coords_within_distance(coords, 1, include_center=False)
            # print('adj_wo_bot: {}'.format(adj_wo_bot))

            #Build in one of the empty spots
            building = False
            if adj_wo_bot:
                building = True
                build_coords = choice(adj_wo_bot)

                build_move = builds.BuildMove(
                    build_coords,
                    max_hp=3,
                    power=2,
                    attack_range=attack_range,
                    speed=0,
                    sight=4,
                    energy=0,
                    movement=1,
                    message=self.message_to_give,
                    poison=1,  #Testing poison
                    spread=spread,
                    absorb=4)

                moves[bg.MoveType.BUILD] = [build_move]

            #There's a bot in one of the empty spots

            if adj_w_ally and not building:
                give_en_coords = choice(adj_w_ally)

                give_energy_move = bg.Move(move_type=bg.MoveType.GIVE_ENERGY,
                                           target_coords=give_en_coords,
                                           amount=self.owner_view.energy)
                #Add amount later
                moves[bg.MoveType.GIVE_ENERGY] = [give_energy_move]

            return moves
        else:
            #Not on an energy source
            #Either look for an energy source or look for an enemy

            #Look for an energy source
            energy_sources = list()

            for _, items in self.view.items():
                if 'EnergySource' in items and not 'Bot' in items:
                    energy_sources.append(items['EnergySource'])

            if energy_sources:
                target_coords = choice(energy_sources).coords

                approach_moves = get_approach_moves(self.coords, target_coords)
                moves[bg.MoveType.MOVE] = approach_moves
            else:
                #Look for an enemy instead
                enemies = list()
                for _, items in self.view.items():
                    if 'Bot' in items and items['Bot'].player != self.player:
                        enemies.append(items['Bot'])

                if enemies:
                    target_coords = choice(enemies).coords

                    approach_moves = get_approach_moves(
                        self.coords, target_coords)
                    moves[bg.MoveType.MOVE] = approach_moves
                elif self.directions:
                    #There's nothing in sight, so just wander
                    d = choice(self.directions)
                    move = bg.Move(bg.MoveType.MOVE, direction=d)
                    moves[bg.MoveType.MOVE] = [move]
                else:
                    #We don't have any directions
                    #So just go up
                    print('no directions, going up')
                    move = bg.Move(bg.MoveType.MOVE, direction=bg.Direction.UP)
                    moves[bg.MoveType.MOVE] = [move]

        return moves
Пример #3
0
    def get_moves(self):
        self.update()

        coords = self.owner_view.coords
        items_at = self.view[coords]

        is_es_at = 'EnergySource' in items_at

        #Get all this info up front
        adj = bg.coords_within_distance(coords, 1, include_center=False)

        #Only deal with visible coords
        adj = [c for c in adj if c in self.view]

        adj_wo_bot = [c for c in adj if not 'Bot' in self.view[c]]
        adj_w_bot = [c for c in adj if not c in adj_wo_bot]
        adj_w_ally = [c for c in adj_w_bot if\
                      self.view[c]['Bot'].player == self.owner_view.player]
        adj_w_enemy = [b for b in adj_w_bot if not b in adj_w_ally]

        moves = dict()

        #Always attack if there's an enemy adjacent
        if adj_w_enemy:
            attack_coords = choice(adj_w_enemy)

            attack_move = bg.Move(move_type=bg.MoveType.ATTACK,
                                  target_coords=attack_coords)

            moves[bg.MoveType.ATTACK] = [attack_move]

        if is_es_at:
            #Either build or give energy
            es_at = self.view[self.coords]['EnergySource']
            es_amount = es_at.amount

            #Find if there's a better EnergySource to move to
            adj_w_es = [c for c in adj if 'EnergySource' in self.view[c]]
            adj_w_es = [c for c in adj_w_es if c in adj_wo_bot]

            if adj_w_es:
                best_adj_es_coords = adj_w_es[0]
                best_adj_es = self.view[best_adj_es_coords]['EnergySource']
                highest_adj_es_amount = best_adj_es.amount

                for es_coords in adj_w_es[1:]:
                    amount_there = self.view[es_coords]['EnergySource'].amount

                    if amount_there > highest_adj_es_amount:
                        highest_adj_es_amount = amount_there
                        best_adj_es_coords = es_coords

                #There's a better ES to move to
                if highest_adj_es_amount > es_amount:
                    movement = get_approach_moves(self.coords,
                                                  best_adj_es_coords)
                    moves[bg.MoveType.MOVE] = movement
                    return moves

            #Build in one of the empty spots
            building = False
            if adj_wo_bot:
                building = True
                build_coords = choice(adj_wo_bot)

                build_move = builds.BuildMove(
                    build_coords,
                    max_hp=1,
                    power=1,
                    attack_range=1,
                    speed=0,  #self.next_speed.val,
                    sight=1,
                    energy=0,
                    movement=1,
                    message=self.message_to_give,
                    #spread=70,
                    absorb=15,
                    tall=1)
                #absorb=40)

                moves[bg.MoveType.BUILD] = [build_move]

            #There's a bot in one of the empty spots

            if adj_w_ally and not building:
                give_en_coords = choice(adj_w_ally)

                give_energy_move = bg.Move(move_type=bg.MoveType.GIVE_ENERGY,
                                           target_coords=give_en_coords,
                                           amount=self.owner_view.energy)
                #Add amount later
                moves[bg.MoveType.GIVE_ENERGY] = [give_energy_move]

            return moves
        else:
            #Not on an energy source
            #Either look for an energy source or look for an enemy

            #Look for an energy source
            energy_sources = list()

            for _, items in self.view.items():
                if 'EnergySource' in items and not 'Bot' in items:
                    energy_sources.append(items['EnergySource'])

            if energy_sources:
                target_coords = choice(energy_sources).coords

                approach_moves = get_approach_moves(self.coords, target_coords)
                moves[bg.MoveType.MOVE] = approach_moves
            else:
                #Look for an enemy instead
                enemies = list()
                for _, items in self.view.items():
                    if 'Bot' in items and items['Bot'].player != self.player:
                        enemies.append(items['Bot'])

                if enemies:
                    target_coords = choice(enemies).coords

                    approach_moves = get_approach_moves(
                        self.coords, target_coords)
                    moves[bg.MoveType.MOVE] = approach_moves
                elif self.directions:
                    #There's nothing in sight, so just wander
                    d = choice(self.directions)
                    move = bg.Move(bg.MoveType.MOVE, direction=d)
                    moves[bg.MoveType.MOVE] = [move]
                else:
                    #We don't have any directions
                    #So just go up
                    print('no directions, going up')
                    move = bg.Move(bg.MoveType.MOVE, direction=bg.Direction.UP)
                    moves[bg.MoveType.MOVE] = [move]

        return moves
Пример #4
0
    def get_moves(self):
        coords = self.owner_view.coords
        items_at = self.view[coords]

        is_es_at = 'EnergySource' in items_at

        #Get all this info up front
        adj = bg.coords_within_distance(coords, 1, include_center=False)

        #Only deal with visible coords
        adj = [c for c in adj if c in self.view]

        adj_wo_bot = [c for c in adj if not 'Bot' in self.view[c]]
        adj_w_bot = [c for c in adj if not c in adj_wo_bot]
        adj_w_ally = [c for c in adj_w_bot if\
                      self.view[c]['Bot'].player == self.owner_view.player]
        # adj_w_enemy = [b for b in adj_w_bot if not b in adj_w_ally]

        moves = dict()

        #Always attack if there's an enemy adjacent
        attack_range = 1
        in_range = bg.coords_at_distance(coords, attack_range)
        in_range = [c for c in in_range if c in self.view]
        in_range_w_bot = [c for c in in_range if 'Bot' in self.view[c]]
        in_range_w_enemy = [c for c in in_range_w_bot if\
                            self.view[c]['Bot'].player != self.owner_view.player]
        if in_range_w_enemy:
            attack_coords = choice(in_range_w_enemy)

            attack_move = bg.Move(move_type=bg.MoveType.ATTACK,
                                  target_coords=attack_coords)

            moves[bg.MoveType.ATTACK] = [attack_move]

        if is_es_at:
            #Either build or give energy
            adj = bg.coords_within_distance(coords, 1, include_center=False)
            # print('adj_wo_bot: {}'.format(adj_wo_bot))

            #Build in one of the empty spots
            building = False
            if adj_wo_bot:
                building = True
                build_coords = choice(adj_wo_bot)

                build_move = builds.BuildMove(build_coords,
                                              max_hp=10,
                                              power=10,
                                              attack_range=attack_range,
                                              speed=0,
                                              sight=4,
                                              energy=0,
                                              movement=1,
                                              message=self.message_to_give)

                moves[bg.MoveType.BUILD] = [build_move]

            #There's a bot in one of the empty spots

            if adj_w_ally and not building:
                give_en_coords = choice(adj_w_ally)

                give_energy_move = bg.Move(move_type=bg.MoveType.GIVE_ENERGY,
                                           target_coords=give_en_coords,
                                           amount=self.owner_view.energy)
                #Add amount later
                moves[bg.MoveType.GIVE_ENERGY] = [give_energy_move]

            return moves
        else:
            #Not on an energy source
            #Either look for an energy source or look for an enemy

            #Look for an energy source
            energy_sources = list()

            for _, items in self.view.items():
                if 'EnergySource' in items and not 'Bot' in items:
                    energy_sources.append(items['EnergySource'])

            if energy_sources:
                target_coords = choice(energy_sources).coords

                approach_moves = get_approach_moves(self.coords, target_coords)
                moves[bg.MoveType.MOVE] = approach_moves
            else:
                #Look for an enemy instead
                enemies = list()
                for _, items in self.view.items():
                    if 'Bot' in items and items['Bot'].player != self.player:
                        enemies.append(items['Bot'])

                if enemies:
                    target_coords = choice(enemies).coords

                    approach_moves = get_approach_moves(
                        self.coords, target_coords)
                    moves[bg.MoveType.MOVE] = approach_moves
                elif self.directions:
                    #There's nothing in sight, so just wander
                    d = choice(self.directions)
                    move = bg.Move(bg.MoveType.MOVE, direction=d)
                    moves[bg.MoveType.MOVE] = [move]
                else:
                    #We don't have any directions
                    #So just go up
                    print('no directions, going up')
                    move = bg.Move(bg.MoveType.MOVE, direction=bg.Direction.UP)
                    moves[bg.MoveType.MOVE] = [move]

        return moves