示例#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 do_setup(self, ants):
      self.level_string = util.strip_string(ants.render_text_map())
      self.level_array = util.string_to_array(self.level_string)
      self.level_size = (ants.cols, ants.rows)
      for y in range(0, self.level_size[1]):
	row = []
	for x in range(0, self.level_size[0]):
	  row.append(False)
	self.outskirts.append(row)
示例#3
0
 def do_setup(self, ants):
     self.level_string = util.strip_string(ants.render_text_map())
     self.level_array = util.string_to_array(self.level_string)
     self.level_size = (ants.cols, ants.rows)
     self.total_tiles = self.level_size[0] * self.level_size[1]
     self.view_radius = math.ceil(ants.viewradius2 ** 0.5)
     self.attack_radius = math.ceil(ants.attackradius2 ** 0.5)
     for y in range(0, self.level_size[1]):
         row = []
         for x in range(0, self.level_size[0]):
             row.append("X")
         self.level_tiles_seen.append(row)
示例#4
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)
示例#5
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 level fog
      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_fog[y][x] = self.level_array[y][x]
      ###Reset destinations
      self.destinations = []
示例#6
0
# ..%%%.............%%%.a................
# ...%%..................................
# ..................%%%..................
# .................%...%.................
# ......*.........a...%...*........*.....
# ...................%.%.................
# ....................%..................
# ............b........b.................
# ...%%...........!......................
# ...%%...................*..............
# ...%%....*......!......................
# ..%%%..............a...................
# ..%%%..................................
# ..%%%...........%%%%%%%................"""
###Util Tests
world_string = util.strip_string(world)
print world_string
world_array = util.string_to_array(world_string)
#print util.array_to_string(world_array, True)
#world_array[1][1] = -2
food = []
my_ants = []
enemy_ants = []
for y in range(0, len(world_array)):
  for x in range(0, len(world_array[0])):
    if world_array[y][x] == '*':
      food.append((y, x))
    elif world_array[y][x] == 'a':
      my_ants.append((y, x))
    elif world_array[y][x] == 'b':
      enemy_ants.append((y, x))