def initialize(self): """Use this function to setup your bot before the game starts.""" #Initialized a graphical representation of work and the graph. #Makes 88x50 graph with adjacent squares having edges. #CALLS regressions2.makeGraph to do this. regressions2.initialize_graphics(self) regressions2.update_graph(self) #@test #Calculate initial probability distribution for location of enemies. enemy_belief.update_enemy_graph(self) self.verbose = True self.counter = 0 #Used to store bots current command. self.bots = {} for bot in self.game.team.members: self.bots[bot.name] = {} self.bots[bot.name]["command"] = None # Classifier: Structured as {commands.Attack : (regression0, coefficient0), (regression1, coefficient1}... commands.Defend : (regression0.....)} self.classifier = self.classifierGenerator() ## self.issue_initial() print 'DONE initializing'
def initialize(self): """Use this function to setup your bot before the game starts.""" self.GRAPHICS = True #Initialized a graphical representation of work and the graph. #Makes 88x50 graph with adjacent squares having edges. #CALLS regressions2.make_graph to do this. regressions2.make_graph(self) regressions2.update_graph(self) if self.GRAPHICS: regressions2.initialize_graphics(self) #Calculate initial probability distribution for location of enemies. #Show initial gui graphics. regressions2.update_graphics_probability(self, mode = "p_enemy") self.visualizer.tick() self.verbose = True self.counter = 0 #Used to store bots current command. self.bots = {} for bot in self.game.team.members: self.bots[bot.name] = {} self.bots[bot.name]["command"] = None # Classifier: Structured as {commands.Attack : (regression0, coefficient0), (regression1, coefficient1}... commands.Defend : (regression0.....)} self.classifier = self.classifierGenerator() print 'DONE initializing'
def initialize(self): """Use this function to setup your bot before the game starts.""" # Initialized a graphical representation of work and the graph. # Makes 88x50 graph with adjacent squares having edges. # CALLS regressions2.makeGraph to do this. regressions2.initialize_graphics(self) regressions2.update_graph(self) # @test # Calculate initial probability distribution for location of enemies. enemy_belief.update_enemy_graph(self) self.verbose = True self.counter = 0 # Used to store bots current command. self.bots = {} for bot in self.game.team.members: self.bots[bot.name] = {} self.bots[bot.name]["command"] = None # Classifier: Structured as {commands.Attack : (regression0, coefficient0), (regression1, coefficient1}... commands.Defend : (regression0.....)} self.classifier = self.classifierGenerator() ## self.issue_initial() print "DONE initializing"
def tick(self): """Routine to deal with new information every interval of about .1s""" self.counter += 1 #Don't act if we are still in the process of issuing commands from a previous tick. ## if self.computing == False: self.HOLD_RATE = 7 self.COMMAND_RATE = 35 self.AVAIL_RATE = 8 self.SUICIDE_CHECK_RATE = 15 #Number of ticks between storage of enemy position for extrapolation. self.EXTRAP_STORE_RATE = 10 if self.counter % self.COMMAND_RATE != 0.0 and self.counter % self.EXTRAP_STORE_RATE == 0: #Keep track of where enemies are this tick so we can extrapolate later. enemy_belief.store_enemy_positions(self) #Ensure our info doesn't get too outdated. Every half cycle update for benefit of hold/ avail commands. if (self.counter + int(self.COMMAND_RATE) / 4) % self.COMMAND_RATE == 0: regressions2.update_graph(self) if self.counter == 1: #We do this twice even though we plan to override it. We want a point to spread our targets from. self.command_routine(self.game.team.members) self.graphics_tick() if self.counter % self.SUICIDE_CHECK_RATE == 0: print "AVOIDING DEATH" self.avoid_suicide_and_trades() if self.counter % self.AVAIL_RATE == 0: if self.counter % self.COMMAND_RATE != 0 and self.counter % self.HOLD_RATE != 0 and self.SUICIDE_CHECK_RATE != 0: for bot in self.game.bots_available: #Updates graph knowledge about game state. #Update graphics to show probability distribution of enemies' as we assess it. #Optionally we can pass any of the probabilities weighted on the graph : p_enemy, p_enemy_fire, p_enemy_sight. self.command_routine([bot]) self.graphics_tick() if self.counter % self.HOLD_RATE == 0: if len( self.game.bots_holding ) > 0 and self.counter % self.COMMAND_RATE != 0 and self.counter % self.AVAIL_RATE != 0 and self.SUICIDE_CHECK_RATE != 0: #Updates graph knowledge about game state. #Update graphics to show probability distribution of enemies' as we assess it. #Optionally we can pass any of the probabilities weighted on the graph : p_enemy, p_enemy_fire, p_enemy_sight. self.command_routine(self.game.bots_holding) self.graphics_tick() if self.counter % self.COMMAND_RATE == 0 and self.SUICIDE_CHECK_RATE != 0 and self.counter % self.AVAIL_RATE != 0: #Updates graph knowledge about game state. regressions2.update_graph(self) #Update graphics to show probability distribution of enemies' as we assess it. #Optionally we can pass any of the probabilities weighted on the graph : p_enemy, p_enemy_fire, p_enemy_sight. self.command_routine(self.game.team.members) self.graphics_tick()
def tick(self): """Routine to deal with new information every interval of about .1s""" self.counter += 1 #Don't act if we are still in the process of issuing commands from a previous tick. ## if self.computing == False: self.HOLD_RATE = 7 self.COMMAND_RATE = 35 self.AVAIL_RATE = 8 self.SUICIDE_CHECK_RATE = 15 #Number of ticks between storage of enemy position for extrapolation. self.EXTRAP_STORE_RATE = 10 if self.counter%self.COMMAND_RATE != 0.0 and self.counter%self.EXTRAP_STORE_RATE == 0: #Keep track of where enemies are this tick so we can extrapolate later. enemy_belief.store_enemy_positions(self) #Ensure our info doesn't get too outdated. Every half cycle update for benefit of hold/ avail commands. if (self.counter + int(self.COMMAND_RATE)/4)% self.COMMAND_RATE == 0: regressions2.update_graph(self) if self.counter == 1: #We do this twice even though we plan to override it. We want a point to spread our targets from. self.command_routine(self.game.team.members) self.graphics_tick() if self.counter%self.SUICIDE_CHECK_RATE == 0: print "AVOIDING DEATH" self.avoid_suicide_and_trades() if self.counter%self.AVAIL_RATE == 0: if self.counter%self.COMMAND_RATE != 0 and self.counter%self.HOLD_RATE != 0 and self.SUICIDE_CHECK_RATE != 0: for bot in self.game.bots_available: #Updates graph knowledge about game state. #Update graphics to show probability distribution of enemies' as we assess it. #Optionally we can pass any of the probabilities weighted on the graph : p_enemy, p_enemy_fire, p_enemy_sight. self.command_routine([bot]) self.graphics_tick() if self.counter%self.HOLD_RATE == 0: if len(self.game.bots_holding) > 0 and self.counter%self.COMMAND_RATE != 0 and self.counter%self.AVAIL_RATE !=0 and self.SUICIDE_CHECK_RATE != 0: #Updates graph knowledge about game state. #Update graphics to show probability distribution of enemies' as we assess it. #Optionally we can pass any of the probabilities weighted on the graph : p_enemy, p_enemy_fire, p_enemy_sight. self.command_routine(self.game.bots_holding) self.graphics_tick() if self.counter % self.COMMAND_RATE == 0 and self.SUICIDE_CHECK_RATE != 0 and self.counter%self.AVAIL_RATE !=0: #Updates graph knowledge about game state. regressions2.update_graph(self) #Update graphics to show probability distribution of enemies' as we assess it. #Optionally we can pass any of the probabilities weighted on the graph : p_enemy, p_enemy_fire, p_enemy_sight. self.command_routine(self.game.team.members) self.graphics_tick()
def tick(self): """Routine to deal with new information every interval of about .1s""" self.counter += 1 if self.counter == 1: regressions2.update_graph(self) self.graphics_tick() self.command_routine() if self.counter % 20 == 0: #Updates graph knowledge about game state. regressions2.update_graph(self) #Update graphics to show probability distribution of enemies' as we assess it. #Optionally we can pass any of the probabilities weighted on the graph : p_enemy, p_enemy_fire, p_enemy_sight. self.command_routine() self.graphics_tick()
def tick(self): """Routine to deal with new information every interval of about .1s""" self.counter += 1 # Refreshes visuals if self.counter % 15 == 0: ## regressions2.update_graphics(self) enemy_belief.update_enemy_graph(self) self.visualizer.tick() # Updates graph info regressions2.update_graph(self) test_enemy = self.game.enemyTeam.members[0] if self.counter % 20 == 0: pass ## print "health: " , test_enemy.health ## print "state: ", test_enemy.state ## print "position: ", test_enemy.position ## print "facingDirection: ", test_enemy.facingDirection for bot in self.game.team.members: # If it makes sense to move, evaluate actions and take the best. Otherwise don't waste processing power calculating an action. can_shoot_enemy, no_enemy_sighted = self.check_to_see_if_no_command(bot) if ( self.counter % 15 == 0 and can_shoot_enemy == False and bot.health > 0 or bot in self.game.bots_available ): legalActions = self.get_p_actions(bot) command, value = self.get_action(bot, legalActions) # Consider whether the strength of continuing the current command and hence having no command wait is superior. # If it isn't, issue the command, otherwise, continue the present command. # Resets bots' stored commands to None who are dead or have finished a task. self.refresh_bot_commands() if self.bots[bot.name]["command"] != None: continue_value = regressions2.evaluate_continue_present_command(self, bot, command) if continue_value > value: # TODO calibrate skipping continue self.issueCMD(command)
def tick(self): """Routine to deal with new information every interval of about .1s""" self.counter += 1 #Refreshes visuals if self.counter % 15 == 0: ## regressions2.update_graphics(self) enemy_belief.update_enemy_graph(self) self.visualizer.tick() #Updates graph info regressions2.update_graph(self) test_enemy = self.game.enemyTeam.members[0] if self.counter % 20 == 0: pass ## print "health: " , test_enemy.health ## print "state: ", test_enemy.state ## print "position: ", test_enemy.position ## print "facingDirection: ", test_enemy.facingDirection for bot in self.game.team.members: #If it makes sense to move, evaluate actions and take the best. Otherwise don't waste processing power calculating an action. can_shoot_enemy, no_enemy_sighted = self.check_to_see_if_no_command( bot) if self.counter % 15 == 0 and can_shoot_enemy == False and bot.health > 0 or bot in self.game.bots_available: legalActions = self.get_p_actions(bot) command, value = self.get_action(bot, legalActions) #Consider whether the strength of continuing the current command and hence having no command wait is superior. #If it isn't, issue the command, otherwise, continue the present command. #Resets bots' stored commands to None who are dead or have finished a task. self.refresh_bot_commands() if self.bots[bot.name]["command"] != None: continue_value = regressions2.evaluate_continue_present_command( self, bot, command) if continue_value > value: #TODO calibrate skipping continue self.issueCMD(command)
def initialize(self): """Use this function to setup your bot before the game starts.""" self.points = [] self.verbose = True self.counter = 0 self.enemies = {} self.botID = None self.HOLD_RATE = 10 self.COMMAND_RATE = 35 self.AVAIL_RATE = 3 self.SUICIDE_CHECK_RATE = 4 #Number of ticks between storage of enemy position for extrapolation. self.EXTRAP_STORE_RATE = 15 #Used to tell whether the bot is calculating actions. self.computing = False #Used to store bots current command. self.bots = {} for bot in self.game.team.members: self.bots[bot.name] = {} self.bots[bot.name]["command"] = None self.bots[bot.name]["last_command_time"] = -5.0 self.bots[bot.name]["visibility"] = set() # Classifier: Structured as {commands.Attack : (regression0, coefficient0), (regression1, coefficient1}... commands.Defend : (regression0.....)} self.classifier = self.classifierGenerator() #GRAPHICS LOGIC #Toggles graphics to desired display. Must be off to submit!!! ## self.GRAPHICS = "p_enemy" ## self.GRAPHICS = "p_enemy_sight" ## self.GRAPHICS = "p_enemy_fire" ## self.GRAPHICS = "ambush" ## self.GRAPHICS = "pheremone" ## self.GRAPHICS = "exit_path" ## self.GRAPHICS = "camp_target" ## self.GRAPHICS = "choke_covered" ## self.GRAPHICS = "camp_location" self.GRAPHICS = False #Toggles drawing helper points. ## self.DRAW_POINTS = "extrap" self.DRAW_POINTS = "flanking" ## self.DRAW_POINTS = "camp" ## self.DRAW_POINTS = False #Refactoring functional self variables here for easy tweaking. #At what distance do we cut off speculation on an enemy's location? self.MAX_ENEMY_DISTANCE = 25 #Variable used in enemy_belief to determine how many points to do sight calcs on. self.TOTAL_FS_NODES = 13 #Determines minimum probability of an enemy being in a node for it to be evaluated. self.MINIMUM_ENEMY_PROB = 0.01 #Initialized a graphical representation of work and the graph. #Makes 88x50 graph with adjacent squares having edges. #CALLS regressions2.make_graph to do this. regressions2.make_graph(self) ## regressions2.calculate_control_main_route2(self) self.camp_positions = spawn_camp.calculate_spawn_camp(self) regressions2.update_graph(self) if self.GRAPHICS or self.DRAW_POINTS: regressions2.initialize_graphics(self) #Calculate initial probability distribution for location of enemies. #Show initial gui graphics. regressions2.update_graphics_probability(self, mode=self.GRAPHICS) self.visualizer.tick() print 'DONE initializing'
def get_p_actions( self, bot ): #TODO, random map filter, generate new points about best N commands, pick best from secondary filter. command_list = [] #If our bot has the flag... don't run toward the enemy, go score! if bot.flag: #Score location destination = self.game.team.flagScoreLocation regressions2.update_score_graph(self) waypoints = regressions2.get_path(self, bot.position, destination) waypoints = self.prune_waypoints(waypoints) command_list.append( commands.Move(bot.name, waypoints, description="Moving toward the flag score.")) regressions2.update_graph(self) return command_list #Random target = self.level.findRandomFreePositionInBox(self.level.area) waypoints = regressions2.get_path(self, bot.position, target) command_list.append( commands.Attack(bot.name, waypoints, description="Attacking to random position")) potential_flanking_positions = self.get_flanking_positions(bot, actions=6) potential_charge_flank = potential_flanking_positions[ len(potential_flanking_positions) / 2:-1] if self.DRAW_POINTS == "flanking": regressions2.draw_points(self, potential_flanking_positions) #Defend redundancy = 0 friendlies = regressions2.get_friendlies_in_range( self, bot.position, 2) campers = 0 for friendly in friendlies: if friendly.state == 2: redundancy += 1 if redundancy < 3 and len(friendlies) <= 3: defend_command = commands.Defend(bot.name) command_list.append(defend_command) living_enemies = 0 for enemy in self.game.enemyTeam.members: if enemy.health > 0: living_enemies += 1 if len(self.game.bots_alive) / (living_enemies + 1) > 1.3 or ( bot.position - self.game.enemyTeam.flag.position).length() < 30: #Enemy Flag - ATTACK AND CHARGE destination = self.game.enemyTeam.flag.position direction = self.level.findRandomFreePositionInBox(self.level.area) waypoints = regressions2.get_path(self, bot.position, destination) waypoints = self.prune_waypoints(waypoints) command_list.append( commands.Attack(bot.name, waypoints, description="Attacking toward enemy flag.")) if len(self.game.bots_alive) / (living_enemies + 1) > 1.5 or ( bot.position - self.game.enemyTeam.flag.position).length() < 25: command_list.append( commands.Charge(bot.name, waypoints, description="Charging toward the enemy flag.")) for position in potential_flanking_positions: destination = position waypoints = regressions2.get_path(self, bot.position, destination) #Shorten waypoint list to speed up calculations. waypoints = self.prune_waypoints(waypoints) command_list.append( commands.Attack( bot.name, waypoints, description="Flanking toward the enemy at %s." % waypoints[-1])) for position in potential_charge_flank: destination = position waypoints = regressions2.get_path(self, bot.position, destination) waypoints = self.prune_waypoints(waypoints) command_list.append( commands.Charge( bot.name, waypoints, description="Charging toward the enemy at %s." % waypoints[-1])) if bot.position.distance( self.level.botSpawnAreas[self.game.enemyTeam.name][0]) < 15: potential_camp_positions = self.get_potential_camp_positions( bot, actions=10) for destination in potential_camp_positions: skip_tail = False for bot_name in self.bots.keys(): #TODO fix based on distance. #No duplicate destinations. command = self.bots[bot_name]["command"] if command != None: friendly = self.get_bot_from_command(command) if friendly == bot: skip_tail = True break if type( command ) == commands.Defend and friendly.position.distance( destination) < 1.0: skip_tail = True break if type(command) != commands.Defend: if self.bots[bot_name]["command"].target[ -1].distance(destination) < 1.0: skil_tail = True break if not skip_tail: command = self.build_command(bot, destination, commands.Attack) command_list.append(command) command = self.build_command(bot, destination, commands.Charge) command_list.append(command) return command_list
def initialize(self): """Use this function to setup your bot before the game starts.""" self.points = [] self.verbose = True self.counter = 0 self.enemies = {} self.botID = None self.HOLD_RATE = 10 self.COMMAND_RATE = 35 self.AVAIL_RATE = 3 self.SUICIDE_CHECK_RATE = 4 #Number of ticks between storage of enemy position for extrapolation. self.EXTRAP_STORE_RATE = 15 #Used to tell whether the bot is calculating actions. self.computing = False #Used to store bots current command. self.bots = {} for bot in self.game.team.members: self.bots[bot.name] = {} self.bots[bot.name]["command"] = None self.bots[bot.name]["last_command_time"] = -5.0 self.bots[bot.name]["visibility"] = set() # Classifier: Structured as {commands.Attack : (regression0, coefficient0), (regression1, coefficient1}... commands.Defend : (regression0.....)} self.classifier = self.classifierGenerator() #GRAPHICS LOGIC #Toggles graphics to desired display. Must be off to submit!!! ## self.GRAPHICS = "p_enemy" ## self.GRAPHICS = "p_enemy_sight" ## self.GRAPHICS = "p_enemy_fire" ## self.GRAPHICS = "ambush" ## self.GRAPHICS = "pheremone" ## self.GRAPHICS = "exit_path" ## self.GRAPHICS = "camp_target" ## self.GRAPHICS = "choke_covered" ## self.GRAPHICS = "camp_location" self.GRAPHICS = False #Toggles drawing helper points. ## self.DRAW_POINTS = "extrap" self.DRAW_POINTS = "flanking" ## self.DRAW_POINTS = "camp" ## self.DRAW_POINTS = False #Refactoring functional self variables here for easy tweaking. #At what distance do we cut off speculation on an enemy's location? self.MAX_ENEMY_DISTANCE = 25 #Variable used in enemy_belief to determine how many points to do sight calcs on. self.TOTAL_FS_NODES = 13 #Determines minimum probability of an enemy being in a node for it to be evaluated. self.MINIMUM_ENEMY_PROB = 0.01 #Initialized a graphical representation of work and the graph. #Makes 88x50 graph with adjacent squares having edges. #CALLS regressions2.make_graph to do this. regressions2.make_graph(self) ## regressions2.calculate_control_main_route2(self) self.camp_positions = spawn_camp.calculate_spawn_camp(self) regressions2.update_graph(self) if self.GRAPHICS or self.DRAW_POINTS: regressions2.initialize_graphics(self) #Calculate initial probability distribution for location of enemies. #Show initial gui graphics. regressions2.update_graphics_probability(self, mode = self.GRAPHICS) self.visualizer.tick() print 'DONE initializing'
def get_p_actions(self, bot): #TODO, random map filter, generate new points about best N commands, pick best from secondary filter. command_list = [] #If our bot has the flag... don't run toward the enemy, go score! if bot.flag: #Score location destination = self.game.team.flagScoreLocation regressions2.update_score_graph(self) waypoints = regressions2.get_path(self, bot.position, destination) waypoints = self.prune_waypoints(waypoints) command_list.append(commands.Move(bot.name, waypoints, description = "Moving toward the flag score.")) regressions2.update_graph(self) return command_list #Random target = self.level.findRandomFreePositionInBox(self.level.area) waypoints = regressions2.get_path(self, bot.position, target) command_list.append(commands.Attack(bot.name, waypoints, description = "Attacking to random position")) potential_flanking_positions = self.get_flanking_positions(bot, actions = 6) potential_charge_flank = potential_flanking_positions[len(potential_flanking_positions)/2:-1] if self.DRAW_POINTS == "flanking": regressions2.draw_points(self, potential_flanking_positions) #Defend redundancy = 0 friendlies = regressions2.get_friendlies_in_range(self, bot.position, 2) campers = 0 for friendly in friendlies: if friendly.state == 2: redundancy += 1 if redundancy < 3 and len(friendlies) <= 3: defend_command = commands.Defend(bot.name) command_list.append(defend_command) living_enemies = 0 for enemy in self.game.enemyTeam.members: if enemy.health > 0: living_enemies += 1 if len(self.game.bots_alive)/(living_enemies+1) > 1.3 or (bot.position - self.game.enemyTeam.flag.position).length() < 30: #Enemy Flag - ATTACK AND CHARGE destination = self.game.enemyTeam.flag.position direction = self.level.findRandomFreePositionInBox(self.level.area) waypoints = regressions2.get_path(self, bot.position, destination) waypoints = self.prune_waypoints(waypoints) command_list.append(commands.Attack(bot.name, waypoints, description = "Attacking toward enemy flag.")) if len(self.game.bots_alive)/(living_enemies+1) > 1.5 or (bot.position - self.game.enemyTeam.flag.position).length() < 25: command_list.append(commands.Charge(bot.name, waypoints, description = "Charging toward the enemy flag.")) for position in potential_flanking_positions: destination = position waypoints = regressions2.get_path(self, bot.position, destination) #Shorten waypoint list to speed up calculations. waypoints = self.prune_waypoints(waypoints) command_list.append(commands.Attack(bot.name, waypoints, description = "Flanking toward the enemy at %s." % waypoints[-1])) for position in potential_charge_flank: destination = position waypoints = regressions2.get_path(self, bot.position, destination) waypoints = self.prune_waypoints(waypoints) command_list.append(commands.Charge(bot.name, waypoints, description = "Charging toward the enemy at %s." % waypoints[-1])) if bot.position.distance(self.level.botSpawnAreas[self.game.enemyTeam.name][0]) < 15: potential_camp_positions = self.get_potential_camp_positions(bot, actions = 10) for destination in potential_camp_positions: skip_tail = False for bot_name in self.bots.keys(): #TODO fix based on distance. #No duplicate destinations. command = self.bots[bot_name]["command"] if command != None: friendly = self.get_bot_from_command(command) if friendly == bot: skip_tail = True break if type(command) == commands.Defend and friendly.position.distance(destination) < 1.0: skip_tail = True break if type(command) != commands.Defend: if self.bots[bot_name]["command"].target[-1].distance(destination) < 1.0: skil_tail = True break if not skip_tail: command = self.build_command(bot, destination, commands.Attack) command_list.append(command) command = self.build_command(bot, destination, commands.Charge) command_list.append(command) return command_list