Exemple #1
0
    def assign_defense(self, ants):
      "Assign defensive perimeter based on attack radius"
      l.log_on = True
      a = []
      num_hills = max(len(self.my_hills), 1)
      ant_hill_ratio = self.total_ants / num_hills
      defense_guide, num_dest, run_status = pathfind.create_defensive_guide(self.attack_radius - 1, self.my_hills ,self.level_tiles_seen, ants)
      #l.log("defense: ", run_status)
      if run_status == "stop":
	  return ["stop"]
      if ant_hill_ratio >=4 and ant_hill_ratio <= 7:
	ant_num = 1 * num_hills
      elif ant_hill_ratio > 7:
	ant_num = min(self.total_ants / 7, num_dest) * num_hills
      else: ant_num = 0
      if ant_num > 0:
	rankings = self.rank_ants_proximity(defense_guide)
	#l.log("Rankings: ", rankings)
	for ant in rankings:
	  if self.ant_lookup[ant] == None:
	    self.ant_lookup[ant] = defense_guide
	    a.append(ant)
	  if len(a) >= ant_num:
	    l.log("Defense Ants: ", str(len(a)) + ' ' + str(a))
	    l.log("Defense Guide: \n", util.array_to_string(defense_guide, True)) 
	    return a
	l.log("Defense Ants: ", str(len(a)) + ' ' + str(a))
	l.log("Defense Guide: \n", util.array_to_string(defense_guide, True)) 
      return a 
    def __repr__(self):
        return (
            """states = %s
observations = %s
%s
""" %
            (
                " ".join(
                    array_to_string(
                        self.states
                        )
                    ),
                " ".join(
                    array_to_string(
                        self.outputs
                        )
                    ),
                string_of_model(
                    (
                        self.initial,
                        self.transition,
                        self.observation
                        ),
                    "")
                )
            )
    def create_guide(self):
      self.level_guide = copy.copy(self.level_fog)
      for y in range(0, self.level_size[1]):
	for x in range(0, self.level_size[0]):
	  if self.level_fog[y][x] == '*':
	    diffusion.diffuse_point(self.level_guide, (y, x), 10)
      l.log("Guide:\n", util.array_to_string(self.level_guide, True))
Exemple #4
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
Exemple #5
0
    def assign_unseen(self, ants):
      "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, run_status = pathfind.create_guide(self.outskirts, self.level_tiles_seen, ants)
	if run_status == "stop":
	  return ["stop"]
	ant_num = int(num_ants_no_guide * min(self.percentage_unseen + .3, 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
Exemple #6
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
Exemple #7
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
Exemple #8
0
#print util.array_to_string(world_array)
#print test_move_direction()
#print test_ant_distance()
#print "Destinations: ", perimeter[1]
#print util.array_to_string(world_array, True)
#print "Changed Tiles: ", perimeter[0]
#guide = test_create_defensive_guide()
#print util.array_to_string(guide[0], True)
#print "Destinations: ", guide[1]
#print util.array_to_string(world_array, True)
#print test_four_corner_defense()
#test_get_all_outposts()
for p in test_get_all_outposts()[0]:
  y, x = p
  world_array[y][x] = 'D'
print util.array_to_string(world_array, True)
#print util.array_to_string(pathfind.create_guide(test_get_all_outposts(), world_array), True)
#print util.array_to_string(pathfind.create_guide([(1, 1)], world_array), True)
#perimeter = test_set_defensive_perimeter()
##print "Changed: ", perimeter[0]

def profile_place_numbers():
  for n in range(0 ,800000):
    l, p = create_random_list()
    #print "Starting:\n", util.array_to_string(l)
    #print "Changed point:", p
    pathfind.place_numbers(p, l, ['.', '*', '!', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'], None)
    
    #print "Ending:\n", util.array_to_string(l)

def profile_surroundings():
Exemple #9
0

print(question_to_vec_tests())

import nltk

nltk.download('stopwords')
from util import array_to_string

question2vec_result = []
for question in open('data/test_embeddings.tsv'):
    question = question.strip()
    answer = question_to_vec(question, wv_embeddings)
    question2vec_result = np.append(question2vec_result, answer)

grader.submit_tag('Question2Vec', array_to_string(question2vec_result))


def hits_count(dup_ranks, k):
    """
        dup_ranks: list of duplicates' ranks; one rank per question;
                   length is a number of questions which we are looking for duplicates;
                   rank is a number from 1 to len(candidates of the question);
                   e.g. [2, 3] means that the first duplicate has the rank 2, the second one — 3.
        k: number of top-ranked elements (k in Hits@k metric)

        result: return Hits@k value for current ranking
    """
    count = 0
    for i in dup_ranks:
        if i <= k: