Example #1
0
 def assign_enemy(self, ants):
     "Assign enemy ants as location"
     # l.log_on = True
     a = []
     if len(self.enemy_ants) > 0 and self.num_ants_without_assignment() > 0:
         guide, run_status = pathfind.create_guide(self.enemy_ants, self.level_array, ants, depth=self.view_radius)
         # l.log("Enemy: ", run_status)
         if run_status == "stop":
             return ["stop"]
         rankings = self.rank_ants_proximity(guide)
         for ant in rankings:
             if self.ant_lookup[ant] == None:
                 self.ant_lookup[ant] = guide
                 a.append(ant)
             # l.log("Attack Ants: ", str(len(a)) + ' ' + str(a))
             # l.log("Attack Guide: \n", util.array_to_string(guide, True))
     return a
Example #2
0
    def assign_hills(self):
      "Assign all regions that have not been seen as destination"
      #l.log_on = True
      a = []
      if len(self.enemy_hills) > 0:
	hills_guide = pathfind.create_guide(self.enemy_hills, self.level_array)
	rankings = self.rank_ants_proximity(hills_guide)
	ant_num = self.total_ants / 2
	for ant in rankings:
	  if self.ant_lookup[ant] == None:
	    self.ant_lookup[ant] = hills_guide
	    a.append(ant)
	  if len(a) >= ant_num:
	    #l.log("Hill Ants: ", str(len(a)) + ' ' + str(a))
	    #l.log("Hill Guide: \n", util.array_to_string(hills_guide, True))
	    return a
	#l.log("Hill Ants: ", str(len(a)) + ' ' + str(a))
	#l.log("Hill Guide: \n", util.array_to_string(hills_guide, True))
      return a
Example #3
0
    def assign_food(self):
      "Assign all food locations as destination"
      #l.log_on = True
      a = []
      if len(self.food) > 0:
	food_guide = pathfind.create_guide(self.food, self.level_array, depth=self.view_radius)
	rankings = self.rank_ants_proximity(food_guide)
	ant_num = len(self.food)
	for ant in rankings:
	  if self.ant_lookup[ant] == None:
	    self.ant_lookup[ant] = food_guide
	    a.append(ant)
	  if len(a) >= ant_num:
	    #l.log("Food Ants: ", str(len(a)) + ' ' + str(a))
	    ##l.log("Food Guide: \n", util.array_to_string(food_guide, True))
	    return a
	#l.log("Food Ants: ", str(len(a)) + ' ' + str(a))
	##l.log("Food Guide: \n", util.array_to_string(food_guide, True))
      return a
Example #4
0
    def assign_outposts(self, ants):
      "Places grid on map and sets points as destinations"
      #l.log_on = True
      a = []
      ant_num = self.num_ants_without_assignment()
      if ant_num > 0:
	destinations = self.get_all_outposts(int(self.view_radius - 1), self.level_tiles_seen, ants)[0:ant_num]
	outpost_guide = pathfind.create_guide(destinations, self.level_array)
	rankings = self.rank_ants_proximity(outpost_guide)
	for ant in rankings:
	  if self.ant_lookup[ant] == None:
	    self.ant_lookup[ant] = outpost_guide
	    a.append(ant)
	  if len(a) >= ant_num:
	    #l.log("Out Ants: ", str(len(a)) + ' ' + str(a))
	    #l.log("Out Guide: \n", util.array_to_string(outpost_guide, True))
	    return a
	#l.log("Out Ants: ", str(len(a)) + ' ' + str(a))
	#l.log("Out Guide: \n", util.array_to_string(outpost_guide, True))
      return a
Example #5
0
    def assign_unseen(self):
      "Assign all regions that have not been seen as destination"
      #l.log_on = True
      a = []
      num_ants_no_guide = self.num_ants_without_assignment()
      if num_ants_no_guide > 0 and self.outskirts > 0:
	unseen_guide = pathfind.create_guide(self.outskirts, self.level_tiles_seen)
	ant_num = int(num_ants_no_guide * min(self.percentage_unseen + .4, 1))
	rankings = self.rank_ants_proximity(unseen_guide)
	for ant in rankings:
	  if self.ant_lookup[ant] == None:
	    self.ant_lookup[ant] = unseen_guide
	    a.append(ant)
	  if len(a) >= ant_num:
	    #l.log("Unseen Ants: ", str(len(a)) + ' ' + str(a))
	    #l.log("Unseen Guide: \n", util.array_to_string(unseen_guide, True))
	    return a
	#l.log("Unseen Ants: ", str(len(a)) + ' ' + str(a))
	#l.log("Unseen Guide: \n", util.array_to_string(unseen_guide, True))
      return a
Example #6
0
    def assign_hills(self, ants):
      "Assign all enemy hills as destination"
      l.log_on = True
      a = []
      if len(self.enemy_hills) > 0:
	hills_guide, run_status = pathfind.create_guide(self.enemy_hills, self.level_tiles_seen, ants)
	if run_status == "stop":
	  return ["stop"]
	rankings = self.rank_ants_proximity(hills_guide)
	ant_num = self.total_ants / 2
	for ant in rankings:
	  if self.ant_lookup[ant] == None:
	    self.ant_lookup[ant] = hills_guide
	    a.append(ant)
	  if len(a) >= ant_num:
	    l.log("Hill Ants: ", str(len(a)) + ' ' + str(a))
	    l.log("Hill Guide: \n", util.array_to_string(hills_guide, True))
	    return a
	l.log("Hill Ants: ", str(len(a)) + ' ' + str(a))
	l.log("Hill Guide: \n", util.array_to_string(hills_guide, True))
      return a
Example #7
0
    def assign_food(self, ants):
      "Assign all food locations as destination"
      l.log_on = True
      a = []
      if len(self.food) > 0:
	food_guide, run_status = pathfind.create_guide(self.food, self.level_tiles_seen, ants, depth=self.view_radius + 5)
	#l.log("food: ", run_status)
	if run_status == "stop":
	  return ["stop"]
	rankings = self.rank_ants_proximity(food_guide)
	ant_num = len(self.food)
	for ant in rankings:
	  if self.ant_lookup[ant] == None:
	    self.ant_lookup[ant] = food_guide
	    a.append(ant)
	  if len(a) >= ant_num:
	    l.log("Food Ants: ", str(len(a)) + ' ' + str(a))
	    l.log("Food Guide: \n", util.array_to_string(food_guide, True))
	    return a
	l.log("Food Ants: ", str(len(a)) + ' ' + str(a))
	l.log("Food Guide: \n", util.array_to_string(food_guide, True))
      return a
Example #8
0
def test_create_guide():
  return pathfind.create_guide([(10, 10), (0, 0), (20, 20)], world_array)