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
def get_moves(self): coords = self.owner_view.coords # print('energy: {}'.format(self.owner_view.energy)) #Seek energy if not self.target_coords: energy_sources = list() for _, items in self.view.items(): sources_at = [s for s in items if s.type == 'EnergySource'] bots_at = [s for s in items if s.type == 'Bot'] #Don't go to occupied places if not bots_at: energy_sources.extend(sources_at) if energy_sources: self.target_coords = choice(energy_sources).coords else: return dict() approach_moves = get_approach_moves(coords, self.target_coords) moves = {bg.MoveType.MOVE: approach_moves} #Make more bots #don't check for energy because the game manager already does directions = list() for direction in bg.Direction: t_coords = bg.coords_in_direction(coords, direction) items_at = self.view[t_coords] bots_at = [b for b in items_at if b.type == 'Bot'] if not bots_at: directions.append(direction) if directions: direction = choice(directions) build_move = builds.BuildMove(direction, max_hp=10, power=10, attack_range=1, speed=0, sight=10, energy=0, movement=1, message='') moves[bg.MoveType.BUILD] = [build_move] return moves
def get_moves(self): if not self.direction: message = self.owner_view.message self.direction = bg.Direction.__dict__.get(message, None) if not self.direction: return coords = self.owner_view.coords target_coords = bg.coords_in_direction(coords, self.direction) items_at = self.view.get(target_coords, list()) bots_at = [b for b in items_at if b.type == 'Bot'] moves = dict() #If there's a bot there, give it energy #otherwise try to build a bot if bots_at: give_energy_move = bg.Move(bg.MoveType.GIVE_ENERGY, direction=self.direction, amount=self.owner_view.energy) moves[bg.MoveType.GIVE_ENERGY] = [give_energy_move] # print('giving energy') else: build_move = builds.BuildMove(self.direction, max_hp=10, power=10, attack_range=1, speed=0, sight=5, energy=0, movement=1, message=self.owner_view.message) moves[bg.MoveType.BUILD] = [build_move] # print('building') return moves
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
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
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