max_distance = max ([zombie_distance[dummy_n[0]][dummy_n[1]] for dummy_n in neighbors]) human_move = [dummy_ne for dummy_ne in neighbors if zombie_distance[dummy_ne[0]][dummy_ne[1]] == max_distance] move_list.append(random.choice(human_move)) #print human_move, random.choice (human_move) self._human_list = move_list def move_zombies(self, human_distance): """ Function that moves zombies towards humans, no diagonal moves are allowed """ #print self._zombie_list move_list = [] if self._zombie_list != []: for zom_cell in self._zombie_list: neighbors = self.four_neighbors(zom_cell[0], zom_cell[1]) neighbors.append (zom_cell) min_distance = min ([human_distance[dummy_n[0]][dummy_n[1]] for dummy_n in neighbors]) zom_move = [dummy_ne for dummy_ne in neighbors if human_distance[dummy_ne[0]][dummy_ne[1]] == min_distance] move_list.append(random.choice(zom_move)) self._zombie_list = move_list # Start up gui for simulation - You will need to write some code above # before this will work without errors poc_zombie_gui.run_gui(Zombie(30, 40)) #import user35_EPZOWWGoUeaEemm as test #test.phase1_test(Zombie) #test.phase2_test(Zombie) #test.phase3_test(Zombie)
new_position = list(neighbor) self._human_list[idx] = tuple(new_position) idx += 1 def move_zombies(self, human_distance_field): """ Function that moves zombies towards humans, no diagonal moves are allowed """ idx = 0 for zombie in list(self._zombie_list): neighbors = self.four_neighbors(zombie[0], zombie[1]) max_distance = 1200 new_position = list(zombie) if human_distance_field[zombie[0]][zombie[1]] == 0: return for neighbor in neighbors: value = human_distance_field[neighbor[0]][neighbor[1]] if max_distance > value and self.is_empty( neighbor[0], neighbor[1]): max_distance = value new_position = list(neighbor) self._zombie_list[idx] = list(new_position) idx += 1 # Start up gui for simulation - You will need to write some code above # before this will work without errors poc_zombie_gui.run_gui(Apocalypse(30, 40, [], [(1, 1)], [(1, 1)]))
def move_zombies(self, human_distance_field): """ Function that moves zombies towards humans, no diagonal moves are allowed """ for indx in xrange(self.num_zombies()): zombie = self._zombie_list[indx] mind = human_distance_field[zombie[0]][zombie[1]] minp = zombie counter = 1 for neighbor in self.four_neighbors(zombie[0], zombie[1]): if self.is_empty(neighbor[0], neighbor[1]): if mind > human_distance_field[neighbor[0]][neighbor[1]]: mind = human_distance_field[neighbor[0]][neighbor[1]] minp = neighbor counter = 1 elif mind == human_distance_field[neighbor[0]][neighbor[1]]: counter += 1 if random.randint(1, counter) == 1: minp = neighbor self._zombie_list[indx] = minp # Start up gui for simulation - You will need to write some code above # before this will work without errors poc_zombie_gui.run_gui(Apocalypse(30, 40))
for move in temp_list: if zombie_distance[move[0]][move[1]] == maxy: listy.append(move) new_human_list.append(listy[-1]) self._human_list = new_human_list def move_zombies(self, human_distance): """ Function that moves zombies towards humans, no diagonal moves are allowed """ new_zombie_list = [] for zombie in self.zombies(): temp_list = [zombie] temp_list_value = [] for neighbor in self.four_neighbors(zombie[0], zombie[1]): temp_list.append(neighbor) for possible_moves in temp_list: temp_list_value.append( human_distance[possible_moves[0]][possible_moves[1]]) miny = min(temp_list_value) listy = [] for move in temp_list: if human_distance[move[0]][move[1]] == miny: listy.append(move) new_zombie_list.append(listy[-1]) self._zombie_list = new_zombie_list poc_zombie_gui.run_gui(Zombie(20, 30))
neighbors = self.four_neighbors(zombie[0], zombie[1]) for neighbor in neighbors: if self.is_empty(neighbor[0], neighbor[1]): if (human_distance_field[neighbor[0]][neighbor[1]] < min_dist_to_hu) and ( human_distance_field[neighbor[0]][neighbor[1]] < human_distance_field[zombie[0]][zombie[1]]): min_dist_to_hu = human_distance_field[neighbor[0]][ neighbor[1]] coord_of_cell = (neighbor[0], neighbor[1]) if (len(coord_of_cell) != 0): zombie = (coord_of_cell[0], coord_of_cell[1]) value = zombie index = zo_idx self._zombie_list[index] = value def __str__(self): ans = "Grid:" + "\n" for row in range(self._grid_height): ans += str(self._cells[row]) ans += "\n" ans += "Humans: " + str(self._human_list) + "\n" ans += "Zombies: " + str(self._zombie_list) + "\n" return ans poc_zombie_gui.run_gui(Apocalypse(25, 25))
neighbors = self.four_neighbors(zombie[0], zombie[1]) for neighbor_cell in neighbors: if self.is_empty(neighbor_cell[0], neighbor_cell[1]): if min_distance > human_distance[neighbor_cell[0]][ neighbor_cell[1]]: min_distance = human_distance[neighbor_cell[0]][ neighbor_cell[1]] min_zombie = (neighbor_cell[0], neighbor_cell[1]) min_zombie_lst = [(neighbor_cell[0], neighbor_cell[1])] elif min_distance == human_distance[neighbor_cell[0]][ neighbor_cell[1]]: min_zombie_lst.append( (neighbor_cell[0], neighbor_cell[1])) if min_distance != 0: # print "min_zombie_lst=", min_zombie_lst update_zombie_lst.append(random.choice(min_zombie_lst)) else: update_zombie_lst.append(min_zombie) # print "update_zombie_lst", update_zombie_lst self._zombie_list = update_zombie_lst # Start up gui for simulation - You will need to write some code above # before this will work without errors #obj = Zombie(3, 3, [(0, 0), (0, 1), (0, 2), (1, 0)], [(2, 1)], [(1, 1)]) #dist = [[9, 9, 9], [9, 1, 2], [1, 0, 1]] #obj.move_humans(dist) #print obj._human_list poc_zombie_gui.run_gui(Zombie(15, 3))
if target_dist == zombie_distance_field[cell[0]][cell[1]] and self._cells[cell[0]][cell[1]] != FULL: target_list.append(cell) target = random.choice(target_list) self._human_list[idx] = (target[0], target[1]) def move_zombies(self, human_distance_field): """ Function that moves zombies towards humans, no diagonal moves are allowed """ for idx in range(len(self._zombie_list)): zombie = self._zombie_list[idx] neighbors = poc_grid.Grid.four_neighbors(self, zombie[0], zombie[1]) target_list = [] target_dist = human_distance_field[zombie[0]][zombie[1]] for cell in neighbors: if human_distance_field[cell[0]][cell[1]] < target_dist: target_dist = human_distance_field[cell[0]][cell[1]] neighbors.append(zombie) for cell in neighbors: if target_dist == human_distance_field[cell[0]][cell[1]] and self._cells[cell[0]][cell[1]] != FULL: target_list.append(cell) target = random.choice(target_list) self._zombie_list[idx] = (target[0], target[1]) # Start up gui for simulation - You will need to write some code above # before this will work without errors poc_zombie_gui.run_gui(Apocalypse(3, 3))
""" Function that moves zombies towards humans, no diagonal moves are allowed """ for index, zombie in enumerate(self._zombie_list): fake_potential_moves_list = self.four_neighbors(zombie[0], zombie[1]) fake_potential_moves_list.append((zombie[0], zombie[1])) potential_moves_list = [] for potential_move in fake_potential_moves_list: if self.is_empty(potential_move[0], potential_move[1]): potential_moves_list.append(potential_move) min_distance = self._grid_width * self._grid_height potential_moves_dict = {} correct_moves_list = [] for potential_move in potential_moves_list: potential_moves_dict[potential_move] = human_distance[potential_move[0]][potential_move[1]] if human_distance[potential_move[0]][potential_move[1]] < min_distance: min_distance = human_distance[potential_move[0]][potential_move[1]] for potential_move in potential_moves_dict: if potential_moves_dict[potential_move] == min_distance: correct_moves_list.append(potential_move) final_move = correct_moves_list[random.randrange(len(correct_moves_list))] self._zombie_list[index] = final_move # Start up gui for simulation - You will need to write some code above # before this will work without errors poc_zombie_gui.run_gui(Zombie(30, 40, None, [(14,15)],[(2,12)]))
zombie_distance_field[neighbor[0], neighbor[1]] for neighbor in self.four_neighbors(zombie[0], zombie[1]) ]) # for zombie in self.zombies(): # for neighbor in self.four_neighbors(zombie[0], zombie[1]): # if human_distance_field[neighbor[0]][neighbor[1]] < best_location and self.is_empty(neighbor[0],neighbor[1]): # best_location = (neighbor[0], neighbor[1]) # move human to neighboring location furthest from any zombies self._zombie_list[self._zombie_list.index(zombie)] = best_location # Start up gui for simulation - You will need to write some code above # before this will work without errors poc_zombie_gui.run_gui(Apocalypse(10, 8)) """ Testing Apparatus for Zombie Apocalypse mini-project """ # import poc_simpletest # import zombie_apocalypse def run_suite(format_function): """ Some informal testing code """ # create a TestSuite object suite = poc_simpletest.TestSuite() # create an instance of the Apocalypse class # obstacle_list = []
'321': (offset[0] - 20, offset[1]), '322': (offset[0] - 21, offset[1]), '323': (offset[0] - 22, offset[1]), '324': (offset[0] - 23, offset[1]), '325': (offset[0] - 24, offset[1]), '326': (offset[0] - 25, offset[1]) } #combine all lists of cabinet coordinates hall_1_cabinet_list.update(row_300) hall_1_cabinet_list.update(row_400) hall_1_cabinet_list.update(row_500) hall_1_cabinet_list.update(row_600) hall_1_cabinet_list.update(row_700) hall_1_cabinet_list.update(row_800) #create the reverse-lookup cabinet list hall1_reverse_cabinet_list = me1.invert_dictionary(hall_1_cabinet_list) #add the hall dictionaries to the 'all' lists me1._all_hall_cabinet_list.append(hall_1_cabinet_list) me1._all_hall_reverse_cabinet_list.append(hall1_reverse_cabinet_list) #Starting points for a + z sides starting_a = [27, 54] starting_z = me1._all_hall_cabinet_list[0][me1._z_side_list[-1]] me1.set_aside(starting_a[0], starting_a[1]) me1.set_zside(starting_z[0], starting_z[1]) poc_zombie_gui.run_gui(me1, tile_size=5, adjustment_speed=1)
start = max((col + length) * direction, 0) end = col for dummy_idx in range(start, end, direction): if dummy_idx < 0 or dummy_idx > width: raise ValueError, "width out of bounds: " + str( dummy_idx) test_site.set_empty(row, dummy_idx) if col + 1 < width: col += 1 if row + 1 < height: row += 1 #random tiles if random.randrange(1000) < 200: test_site.set_empty(row, col) hall_dict = { 1: ((border, border), (height - (2 * border), width - (2 * border))), 2: ((height + border, border), (height - 2 * border, width - 2 * border)) } def print_halls(): for item in hall_dict: print item, ":" print hall_dict[item][0] print hall_dict[item][1] poc_zombie_gui.run_gui(test_site)
hall_1_cabinet_list.update(row_800) #create the reverse-lookup cabinet list hall1_reverse_cabinet_list = simulation.invert_dictionary(hall_1_cabinet_list) #add the hall dictionaries to the 'all' lists simulation._all_hall_cabinet_list.append(hall_1_cabinet_list) simulation._all_hall_reverse_cabinet_list.append(hall1_reverse_cabinet_list) #Starting points for a + z sides starting_a = [27, 54] starting_z = simulation._all_hall_cabinet_list[0][simulation._z_side_list[-1]] simulation.set_aside(starting_a[0], starting_a[1]) simulation.set_zside(starting_z[0], starting_z[1]) poc_zombie_gui.run_gui(simulation) #try: # poc_zombie_gui.run_gui(Apocalypse(30, 40)) #except: # print "gui initialization failed" #test = Apocalypse(30, 40) """ (27, 46) (2, 46) = 801 - 826 (27, 49) (2, 49) = 701 - 726 (27, 54) (2, 54) = 601 - 626 (27, 57) (2, 57) = 501 - 526 (14, 62) (2, 62) = 414 - 426 (14, 65) (2, 65) = 314 - 326 (27, 70) (16, 70) = 201 - 209 (9 cabinets / 12 tiles) (27, 73) (16, 73) = 101 - 109 (9 cabinets / 12 tiles)
'321': (offset[0] - 20, offset[1]), '322': (offset[0] - 21, offset[1]), '323': (offset[0] - 22, offset[1]), '324': (offset[0] - 23, offset[1]), '325': (offset[0] - 24, offset[1]), '326': (offset[0] - 25, offset[1]) } #combine all lists of cabinet coordinates hall_1_cabinet_list.update(row_300) hall_1_cabinet_list.update(row_400) hall_1_cabinet_list.update(row_500) hall_1_cabinet_list.update(row_600) hall_1_cabinet_list.update(row_700) hall_1_cabinet_list.update(row_800) #create the reverse-lookup cabinet list hall1_reverse_cabinet_list = me10101.invert_dictionary(hall_1_cabinet_list) #add the hall dictionaries to the 'all' lists me10101._all_hall_cabinet_list.append(hall_1_cabinet_list) me10101._all_hall_reverse_cabinet_list.append(hall1_reverse_cabinet_list) #Starting points for a + z sides starting_a = [27, 54] starting_z = me10101._all_hall_cabinet_list[0][me10101._z_side_list[-1]] me10101.set_aside(starting_a[0], starting_a[1]) me10101.set_zside(starting_z[0], starting_z[1]) poc_zombie_gui.run_gui(me10101)
if neigh_dis>best_dis and self.is_empty(neighbour[0],neighbour[1]): best_dis = neigh_dis best_pos = neighbour self._human_list[index] = best_pos def move_zombies(self, human_distance_field): """ Function that moves zombies towards humans, no diagonal moves are allowed """ for index in range(len(self._zombie_list)): zombie = self._zombie_list[index] zombie_distance = human_distance_field[zombie[0]][zombie[1]] neighbours=self.four_neighbors(zombie[0],zombie[1]) best_pos = zombie best_dis = zombie_distance for neighbour in neighbours: neigh_dis = human_distance_field[neighbour[0]][neighbour[1]] if neigh_dis<best_dis and self.is_empty(neighbour[0],neighbour[1]): best_dis = neigh_dis best_pos = neighbour self._zombie_list[index] = best_pos # Start up gui for simulation - You will need to write some code above # before this will work without errors poc_zombie_gui.run_gui(Apocalypse(50, 50))
Function that moves zombies towards humans, no diagonal moves are allowed """ for index,zombie in enumerate(self._zombie_list): #find options for zombies to move move_options=list([zombie]) near_cells=self.four_neighbors(zombie[0],zombie[1]) for zomb in near_cells: if self.is_empty(zomb[0],zomb[1]): move_options.append(zomb) #Compare possible moves to nearest human to find best move min_dist = 10000 best_moves=[] for move in move_options: if human_distance[move[0]][move[1]]<min_dist: best_moves=list([move]) min_dist=human_distance[move[0]][move[1]] elif human_distance[move[0]][move[1]]==min_dist: best_moves.append(move) #final move is a random choice between best moves final_move=random.choice(best_moves) #update human position to final move self._zombie_list[index]=final_move # Start up gui for simulation - You will need to write some code above # before this will work without errors poc_zombie_gui.run_gui(Zombie(3, 3, [], [(1, 1)], [(2, 2)]))
hum_max = hum_val max_loc = () for cell in neighbors: if zombie_distance[cell[0]][cell[1]]>hum_max: hum_max = zombie_distance[cell[0]][cell[1]] max_loc = cell if (max_loc not in self._human_list) and (max_loc != () ) and (self.is_empty(max_loc[0], max_loc[1])): self._human_list[self._human_list.index(hum)] = max_loc return self._human_list def move_zombies(self, human_distance): """ Function that moves zombies towards humans, no diagonal moves are allowed """ for zom in self._zombie_list: neighbors = self.four_neighbors(zom[0], zom[1]) zom_val = human_distance[zom[0]][zom[1]] zom_min = zom_val min_loc = () for cell in neighbors: if human_distance[cell[0]][cell[1]]<zom_min: zom_min = human_distance[cell[0]][cell[1]] min_loc = cell if (min_loc not in self._zombie_list) and (min_loc != () ) and (self.is_empty(min_loc[0], min_loc[1])): self._zombie_list[self._zombie_list.index(zom)] = min_loc return self._zombie_list # start up gui for simulation poc_zombie_gui.run_gui(Zombie(20, 30, [(4, 15), (5, 15), (6, 15), (7, 15), (8, 15), (9, 15), (10, 15), (11, 15), (12, 15), (13, 15), (14, 15), (15, 15), (15, 14), (15, 13), (15, 12), (15, 11), (15, 10)], [(12, 12), (7, 12)], []))
distance_field[boundary.__iter__()[0]][boundary.__iter__()[1]] = EMPTY curr_cell = boundary.dequeue() neighbors = poc_grid.Grid.four_neighbors(self, curr_cell[0], curr_cell[1]) for cell in neighbors: if visited[cell[0]][cell[1]] == 0: visited[cell[0]][cell[1]] = FULL boundary.enqueue(cell) distance_field[cell[0]][cell[1]] += 1 return distance_field def move_humans(self, zombie_distance_field): """ Function that moves humans away from zombies, diagonal moves are allowed """ pass def move_zombies(self, human_distance_field): """ Function that moves zombies towards humans, no diagonal moves are allowed """ pass # Start up gui for simulation - You will need to write some code above # before this will work without errors poc_zombie_gui.run_gui(Apocalypse(30, 40))
fake_potential_moves_list = self.four_neighbors( zombie[0], zombie[1]) fake_potential_moves_list.append((zombie[0], zombie[1])) potential_moves_list = [] for potential_move in fake_potential_moves_list: if self.is_empty(potential_move[0], potential_move[1]): potential_moves_list.append(potential_move) min_distance = self._grid_width * self._grid_height potential_moves_dict = {} correct_moves_list = [] for potential_move in potential_moves_list: potential_moves_dict[potential_move] = human_distance[ potential_move[0]][potential_move[1]] if human_distance[potential_move[0]][ potential_move[1]] < min_distance: min_distance = human_distance[potential_move[0]][ potential_move[1]] for potential_move in potential_moves_dict: if potential_moves_dict[potential_move] == min_distance: correct_moves_list.append(potential_move) final_move = correct_moves_list[random.randrange( len(correct_moves_list))] self._zombie_list[index] = final_move # Start up gui for simulation - You will need to write some code above # before this will work without errors poc_zombie_gui.run_gui(Zombie(30, 40, None, [(14, 15)], [(2, 12)]))
neighbors = self.eight_neighbors(human[0], human[1]) for neighbor in neighbors: if zombie_distance[neighbor[0]][neighbor[1]] > maxdist: maxdist = zombie_distance[neighbor[0]][neighbor[1]] bestspot = neighbor self._human_list[idx] = bestspot def move_zombies(self, human_distance): """ Function that moves zombies towards humans, no diagonal moves are allowed """ for idx in range(len(self._zombie_list)): zombie = self._zombie_list[idx] bestspot = zombie bestdist = human_distance[zombie[0]][zombie[1]] neighbors = self.four_neighbors(zombie[0], zombie[1]) for neighbor in neighbors: if human_distance[neighbor[0]][neighbor[1]] < bestdist: bestdist = human_distance[neighbor[0]][neighbor[1]] bestspot = neighbor self._zombie_list[idx] = bestspot # Start up gui for simulation - You will need to write some code above # before this will work without errors poc_zombie_gui.run_gui(Zombie(30, 40)) #obj = Zombie(20, 30, [(4, 15), (5, 15), (6, 15), (7, 15), (8, 15), (9, 15), (10, 15), (11, 15), (12, 15), (13, 15), (14, 15), (15, 15), (15, 14), (15, 13), (15, 12), (15, 11), (15, 10)], [], [(18, 14), (18, 20), (14, 24), (7, 24), (2, 22)]) #obj = Zombie(3,3,[(1,1)],[],[(2,2)]) #print obj.compute_distance_field('human')
points_passable = [point for point in points if self.is_empty(point[0], point[1])] dists = [zombie_distance[point[0]][point[1]] for point in points_passable] dists_max_dist = max(dists) dists_max_points = [point for point in points_passable if zombie_distance[point[0]][point[1]]==dists_max_dist] new_item = random.choice(dists_max_points) self._human_list[item[0]] = new_item def move_zombies(self, human_distance): """ Function that moves zombies towards humans, no diagonal moves are allowed """ b_list = [[i,self._zombie_list[i]] for i in range(len(self._zombie_list))] for item in b_list: points = [] cell = (item[1][0], item[1][1]) points = self.four_neighbors(cell[0], cell[1]) points.append(cell) points_passable = [point for point in points if self.is_empty(point[0], point[1])] dists = [human_distance[point[0]][point[1]] for point in points_passable] dists_min_dist = min(dists) dists_min_points = [point for point in points_passable if human_distance[point[0]][point[1]]==dists_min_dist] new_item = random.choice(dists_min_points) self._zombie_list[item[0]] = new_item # Start up gui for simulation - You will need to write some code above # before this will work without errors poc_zombie_gui.run_gui(Zombie(40, 30))