示例#1
0
 def update_level(self, ants):
     "Updates class variables for string and array levels"
     new_s = util.strip_string(ants.render_text_map())
     s = ""
     pos = 0
     for char in self.level_string:
         if char != "%":
             s = s + new_s[pos]
         else:
             s = s + "%"
         pos += 1
     self.level_string = s
     self.level_array = util.string_to_array(self.level_string)
     ###Update unseen list and level fog
     self.outskirts = []
     count_unseen = 0
     for y in range(0, self.level_size[1]):
         for x in range(0, self.level_size[0]):
             point = (y, x)
             if ants.visible(point):
                 self.level_tiles_seen[y][x] = self.level_array[y][x]
             if self.level_tiles_seen[y][x] != "X" and "X" in pathfind.extended_surroundings(
                 1, point, self.level_tiles_seen
             ):
                 self.outskirts.append((y, x))
             if self.level_tiles_seen[y][x] == "X":
                 count_unseen += 1
     self.percentage_unseen = float(count_unseen) / float(self.total_tiles)
示例#2
0
    def will_live(self, dest):
      "Determines if ant will die at destination"
      surrroundings = pathfind.extended_surroundings(int(self.attack_radius + 1), dest, self.level_array)
      my_ants = 0
      enemy_ants = 0
      for s in surrroundings: 
	if s == 'a':
	  my_ants += 1
	elif s in ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']:
	  enemy_ants += 1
      if my_ants > enemy_ants:
	return True
      else: return False
示例#3
0
 def will_live(self, dest, check):
     "Determines if ant will die at destination"
     if check:
         surrroundings = pathfind.extended_surroundings(int(self.attack_radius + 1), dest, self.level_array)
         my_ants = 0
         enemy_ants = 0
         for s in surrroundings:
             if s == "a":
                 my_ants += 1
             elif s in ["b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]:
                 enemy_ants += 1
         if my_ants > enemy_ants:
             return True
         else:
             return False
     else:
         return True
示例#4
0
    def update(self, ants):
      "Updates class variables"
      ###Updates Food
      self.food = ants.food()
      ###Updates hills
      self.my_hills = ants.my_hills()
      ###Updates hill attack locations
      hills = ants.enemy_hills_locs()
      for h in hills:
	if h not in self.enemy_hills:
	  self.enemy_hills.append(h)
      razed = []
      for h in self.enemy_hills:
	if ants.visible(h) and h not in hills:
	  razed.append(h)
      for h in razed:
	self.enemy_hills.remove(h)
      ###Update unseen list and level_fog
      self.outskirts = []
      count_unseen = 0
      for y in range(0, self.level_size[1]):
	for x in range(0, self.level_size[0]):
	  point = (y, x)
	  if ants.visible(point):
	    self.level_tiles_seen[y][x] = self.level_array[y][x]
	  if self.level_tiles_seen[y][x] != 'X' and 'X' in pathfind.extended_surroundings(1, point, self.level_tiles_seen):
	    self.outskirts.append((y, x))    
	  if self.level_tiles_seen[y][x] == 'X':
	    count_unseen += 1
      self.percentage_unseen = float(count_unseen) / float(self.total_tiles)
      ###Calibrates ant lookup and resets value to None
      a = ants.my_ants()
      dead = []
      for ant in self.ant_lookup:
	if ant not in a:
	  dead.append(ant)
      for ant in dead:
	del self.ant_lookup[ant]
      ###Resets all ant guides to None
      for ant in a:
	self.ant_lookup[ant] = None
      self.total_ants = len(self.ant_lookup)
      ###Resets destintion points
      self.destinations = []
示例#5
0
def test_extended_surroundings():
  return pathfind.extended_surroundings(4, (5, 5), world_array)