def __init__(self): root = Tk() canvas_height = 700 canvas_width = 720 canvas = Canvas(root, width=canvas_width, height=canvas_height) self.map = Map() self.map.draw_map(canvas) self.hero = Hero(canvas) self.hero.draw_hero(0, 0) self.hero.update_entity(self.hero.hero_down) self.skeleton = Skeleton(canvas) self.boss = Boss(canvas) self.skel_num = 3 self.coordinates = self.map.create_random_coordinates(self.skel_num + 1) self.skeleton.draw_skeleton(self.coordinates[:-1]) self.boss.draw_boss(self.coordinates[-1]) self.hud = Hud() self.hud.draw_hud(canvas, 0, 650) root.bind("<KeyPress>", self.on_key_press) canvas.pack() root.mainloop()
for json_ped in json_data: ped_list.append(Pedestrian(json_ped)) return ped_list def isAllReachTarget(ped_list, target_area): for ped in ped_list: if not ped.pos in target_area: return False return True def savePed(ped_list, time): log_msg = "Time " + str(time) + "----\n" for ped in ped_list: log_msg = log_msg + str(ped) + "\n" log.info(log_msg) if __name__ == "__main__": map_info = Map("data/large_basic_map.txt") ped_list = loadPedestrians("data/three_ped.json") time_tick = config.default_time_tick tick_count = 0 experiment = Experiment(map_info) while not isAllReachTarget(ped_list, map_info.getTargetArea()): if tick_count % 1 == 0: print("Tick", tick_count) savePed(ped_list, experiment.time) experiment.tick(ped_list, time_tick) tick_count = tick_count + 1 savePed(ped_list, experiment.time)
def draw_path(pos): pygame.time.delay(100) rect.x = pos[0] * 50 rect.y = pos[1] * 50 screen.fill((0, 0, 255), rect) pygame.display.update() pygame.event.pump() def reset(): screen.blit(mapsurf, (0, 0)) global map, screen, rect, surf, mapsurf, closedsurf map = Map() screen = pygame.display.set_mode((500, 500)) rect = pygame.Rect(0, 0, 50, 50) surf = pygame.Surface((50, 50)) surf.fill((0, 0, 255)) closedsurf = pygame.Surface((50, 50)) closedsurf.fill((255, 0, 0)) for x in range(20): pygame.draw.line(closedsurf, (0, 0, 0), (5 * x, 0), (0, 5 * x)) pygame.draw.line(closedsurf, (0, 0, 0), (50 - 5 * x, 0), (50, 5 * x)) pygame.draw.rect(closedsurf, (0, 0, 0), (0, 0, 50, 50), 1) mapsurf = pygame.Surface((500, 500)) mapsurf.fill((255, 255, 255)) for y, row in enumerate(map.map): for x, value in enumerate(row):
else: open_list.append(neigh) self.G_tab[neigh[0]][neigh[1]] = neigh_G self.father_tab[neigh[0]][neigh[1]] = pos if neigh in self.to_area: not_found = False end_pos = neigh break # for neigh in around_list: # while not_found: if not_found: return None route = [end_pos] now_pos = end_pos while now_pos != from_pos: now_pos = self.father_tab[now_pos[0]][now_pos[1]] route.append(now_pos) route.reverse() return route if __name__ == "__main__": map_info = Map("data/basic_map.txt") solver = AStarSolver(map_info, map_info.getTargetArea()) one = (3, 1) one_res = solver.solve(one) print(one, ": ", one_res)
from mymap import Map map1 = Map() print('map1 = ') print(map1) print() print('add (\'a\',1), (\'b\',2), (\'c\',3), (\'d\',4) to map1') map1.add('a', 1) map1.add('b', 2) map1.add('c', 3) map1.add('d', 4) print('map1 = ') print(map1) print() print('add (\'b\',10)') map1.add('b', 10) print(map1) print() print('remove (\'c\',3) from map1') map1.remove('c') print(map1) print() print('get the value corresponding to \'b\'') print(map1.valueOf('b')) print()