def exec(self, state): self.game = Game(state) self.pathfinder = Pathfinder(self.game) # Choix d'un nouveau client if self.customer is None: print("Selecting customer") _, self.customer_loc = self.pathfinder.get_closest_customer( get_hero_pos(self.game)) self.customer = get_customer_by_pos(self.customer_loc, self.game) if (self.num_death >= 5) and (self.min_heal <= 45): self.min_heal += 5 self.num_death = 0 destination = self.next_state() self.hero_health = get_hero_life(self.game) self.hero_calories = get_our_hero(self.game).calories # Reset de mort et check de healing if self.hero_health == 0: self.num_death += 1 self.next_state = self.init elif (self.hero_calories > 30) and (self.hero_health < self.min_heal): if self.next_state != self.heal: self.state_before_heal = self.next_state self.next_state = self.heal return destination
def main(): pg.init() resolution = (1200, 900) window = pg.display.set_mode(resolution, pg.DOUBLEBUF | pg.RESIZABLE) pg.display.set_caption("pathfinder") map = Terrain(8, 11, 100) # format (y, x) map.set_target([1, 6]) pawn = Pathfinder([6, 6], map.grid) clock = pg.time.Clock() run_flag = True while run_flag: clock.tick(20) for event in pg.event.get(): if event.type == pg.QUIT: run_flag = False if event.type == pg.KEYDOWN: if event.key == pg.K_w: map.add_block_manually(pg.mouse.get_pos()) if event.key == pg.K_e: map.set_target_manually(pg.mouse.get_pos()) if event.key == pg.K_q: map.free_block_manually(pg.mouse.get_pos()) window.fill((120, 120, 120)) map.draw(window) pg.display.update() pawn.make_move(map.grid, window, map)
def __init__(self, environment=None): """sets up details about the red rectangle as well as variables for A.I. behavior""" super(RedAiPilot, self).__init__("red_ai_pilot", environment) self.bot = Bot() # set the rectangle's color self.bot.image.fill(RED) # set the starting position self.bot.rect.x = RECTANGLE_STARTING_X self.bot.rect.y = RECTANGLE_STARTING_Y # place the coordinates of our rectangle in a tuple to update the game manager self.red_coordinate = (self.bot.rect.x, self.bot.rect.y) self.rect = self.bot.rect # these coordinates tell the agent how far away the blue player is self.blue_coordinate = None self.distance_from_blue_player = 0 self.current_position = 0 self.path_course = [] self.path_found = False self.next_node_coordinates = None # variables for A.I. behavior self.winning = False self.current_behavior = PilotAgentBehavior.FINDING_PATH self.pathfinder = Pathfinder()
def __init__(self, arduino=None, android=None, fakeRun=False, fakeMap=None, stepsPerSec=1, **kwargs): """ Constructor. Accepts attributes as kwargs. Args: fakeRun: set True if running simulation. Remember to give fake map as input. I.e: fakeMap = fakemap fakeMap: set simulation map. If left empty, creates an empty arena. pos: a 15x20 array. Contains None, 0 or 1 as values. orientation: Centre of 3x3 start area. Default = [1,1] map: Map object. Refer to Map.py sensors: Sensors object. Refer to sensors.py coordinator: Coordinator object. Refer to coordinator.py """ if fakeRun: self.fakeRun = True from sensors_fake import Sensors self.sensors = Sensors(self, fakeMap) #fake sensors for simulation self.coordinator.fakeRun = True self.coordinator.stepsPerSec = stepsPerSec self.imagefinder = Imagefinder(fakeRun=True) elif arduino is None: raise Exception("Real run requires arduino to be present") elif android is None: raise Exception("Real run requires arduino to be present") else: from sensors import Sensors self.android = android self.sensors = Sensors(self, arduino) self.coordinator.arduino = arduino self.imagefinder = Imagefinder() #update map self.updatemap() goalTiles = [ #set goal as explored [12, 19], [13, 19], [14, 19], [12, 18], [13, 18], [14, 18], [12, 17], [13, 17], [14, 17], ] valuelist = [0] * len(goalTiles) self.map.setTiles(goalTiles, valuelist) #initialise pathfinder self.pathfinder = Pathfinder(self.map) #initialise explorer self.explorer = Explorer(self)
def __init__(self): super().__init__() # Из cfg.txt считывается рабочая директория, # за пределы которой выйти будет нельзя with open('cfg.txt') as f: root = f.readline() # Создается объект, преобразующий ввод в полноценные пути # Он получает на вход рут, и вернет код ошибки, если его покинуть self.pathfinder = Pathfinder(root)
def __init__(self): bot_name = "Swarming" self.game = hlt.Game(bot_name) logging.info("Starting bot {}".format(bot_name)) self.pathfinder = Pathfinder() self.info = Info() self.ai = AI(self.info, self.pathfinder) self.game_map = None
def find_path(): if request.method == 'POST': pathfinder = Pathfinder(host='localhost', port='5436', database='postgres', user='******', password='******') data = json.loads(request.data.decode('ascii')) start = data['viewparams']['start'] end = data['viewparams']['end'] time_limit = data['time'] # hours distance_limit = data['distance'] # km time_start = time.time() # Uruchomienie procedury podstawowej - procedura RUN pathfinder.run(start, end, distance_limit * 1000, time_limit) time_end = time.time() print('Total time (in minutes): {}'.format((time_end - time_start)/60.0)) print('Number of locations: {}'.format(len(pathfinder.locations))) print('Additional len left: {}'.format(pathfinder.additional_len)) print('Additional time left: {}'.format(pathfinder.additional_time)) # Sprawdzenie, czy zostalo wykorzystane co najmniej 80% dodatkowych kilometrow if pathfinder.additional_len / float(distance_limit * 1000) <= 0.2 or pathfinder.additional_len <= 2000: ret = { 'key_points': pathfinder.locations, 'route': pathfinder.routes } return jsonify(ret) # Let's try again print('Trying one more time') locations_backup = pathfinder.locations routes_backup = pathfinder.routes time_start = time.time() # Uruchomienie procedury wyjatkowej - procedura RUN_WITH_FIRST_RANDOM pathfinder.run_with_first_random(start, end, distance_limit * 1000, time_limit) time_end = time.time() print('Total time (in minutes): {}'.format((time_end - time_start)/60.0)) print('Number of locations: {}'.format(len(pathfinder.locations))) print('Additional len left: {}'.format(pathfinder.additional_len)) print('Additional time left: {}'.format(pathfinder.additional_time)) if len(pathfinder.locations) > len(locations_backup): ret = { 'key_points': pathfinder.locations, 'route': pathfinder.routes } return jsonify(ret) else: ret = { 'key_points': locations_backup, 'route': routes_backup } return jsonify(ret)
def __init__(self, environment=None): """sets up details about the red rectangle as well as variables for A.I. behavior""" super(NEO, self).__init__("neo", environment) # the bot object represents NEO's physical body # it performs the tasks as directed by the body part classes below self.bot = Bot() # set the bot's image and angle self.bot.image = pygame.Surface([16, 16]) self.bot.image = pygame.transform.scale(pygame.image.load('Neo.png'), (25, 25)) self.original_image = self.bot.image.copy() self.angle = 90 # set the starting position self.bot.rect.x = NEO_STARTING_X self.bot.rect.y = NEO_STARTING_Y # place the coordinates of our rectangle in a tuple to update the game manager self.red_coordinate = (self.bot.rect.x, self.bot.rect.y) self.rect = self.bot.rect # these different body part classes help modularize the various functions NEO performs self.eyes = Eyes() self.hands = Hands() self.legs = Legs() self.memory = Memory() self.memory.create_object_memory() # self.mouth = Mouth() # self.ears = Ears() self.wernicke_area = Wernicke_Area() self.current_object = None # these coordinates tell the agent how far away the object is self.object_coordinates = None self.distance_from_object = 0 self.current_position = 0 self.path_course = [] self.path_found = False self.next_node_coordinates = None # variables for A.I. behavior self.inspecting = False self.detected_objects = [] self.uninspected_objects = [] self.current_behavior = BEHAVIOR_STATE.SCANNING self.pathfinder = Pathfinder() self.running_training = True #search variables self.rotating_counter = 0 self.location_coordinates = self.ask("memory", "location_coordinates") self.sql_statement = None
def __init__(self): # INIT PYGAME pygame.init() pygame.display.set_caption("A* demo") pygame.font.init() self.font = pygame.font.SysFont("roboto", 25) self.is_running = False self.started = False self.screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) self.pencil = BlockType.WALL self.board = Board(WINDOW_WIDTH, WINDOW_HEIGHT - 120, BLOCK_SIZE) self.finder = Pathfinder(self.board)
def __init__(self, id, pos, app): Tank.__init__(self, id, pos, app) self.path = None self.dest = (10,10) self.idest = None self.rot_dest = None self.rotation_signum = 0 self.driving_signum = 0 self.previous_state = None self.pathfinder = Pathfinder(self.is_valid_cell) dx, dy = self.dest dcell = self.app.current_map.get_at_pixel(dx, dy) x,y = self.position cell = self.app.current_map.get_at_pixel(x, y) self.pathfinder.setupPath(cell.i, cell.j, dcell.i, dcell.j)
def createboard(self, predefinedboard, uselastdata): """ Create board and prepares paths if not prepared. :param predefinedboard: Array of sprites :param uselastdata: Bool value determining if paths have already been calculated. :return: nothing """ Board(predefinedboard, self.systems, self.elements, self.tile_size) start = int(round(time.time() * 1000)) if not uselastdata: self.last_data = Pathfinder(predefinedboard) self.last_data.prepareallstepsforshortestpaths() print("Pathfinder time: ", int(round(time.time() * 1000)) - start) self.systems[AiMovementSystem.NAME].register(self.last_data) self.elements.append(self.last_data)
def __init__(self, window, algorithm): self.window = window self.score = 0 self.snake = [Snake(window.display, (WIDTH/2, HEIGHT/2))] self.apple = Apple(window.display, self.snake) # make graph self.graph = Environment(self.snake, self.apple) # init search algorithm self.algorithm = Pathfinder( self.snake[0].relative_pos, self.apple.relative_pos, self.graph, algorithm) # Run loop self.loop() self.window.quit()
async def run_async_2(): with timewith("async"): grid = Grid(map) finder = Pathfinder(astar.search, heuristic=cardinal_intercardinal) grid.annotate(walkable) get_path_async = async_wrap(finder.get_path) # Compute all the paths serially computed_paths = [] tasks = [] for start, end in paths: tasks.append( get_path_async(start[0], start[1], end[0], end[1], agent_size)) await aio.gather(*tasks) assert len(computed_paths) == len(paths)
def test_do_a_search_smaller_corridor(self): map = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 1, 0, 0, 0, 0, 0, 0], [0, 2, 1, 0, 0, 0, 0, 0, 2, 0], [0, 2, 1, 1, 1, 0, 0, 2, 0, 0], [0, 2, 0, 1, 1, 0, 2, 0, 0, 2], [0, 2, 0, 0, 1, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ] walkable = lambda v: v != 2 grid = Grid(map).annotate(walkable) finder = Pathfinder(astar.search) startx, starty = 0, 0 endx, endy = 0, 8 agent_characteristics = AgentCharacteristics(walkable=walkable, clearance=2) path = finder.get_path( grid, (startx, starty), (endx, endy), agent_characteristics, heuristic=heuristics.diagonal, ) X = "x" marked_map = [ [X, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, X, 0, 0, 0, 0, 0, 0, 1, 0], [0, 2, X, 0, 0, 0, 0, 0, 0, 0], [0, 2, X, 1, 0, 0, 0, 0, 0, 0], [0, 2, X, 0, 0, 0, 0, 0, 2, 0], [0, 2, X, 1, 1, 0, 0, 2, 0, 0], [0, 2, X, 1, 1, 0, 2, 0, 0, 2], [0, 2, X, 0, 1, 0, 0, 0, 0, 2], [X, X, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ] self._assert_the_resulting_path_nodes_should_be_like(marked_map, path)
def test_astar_intercardinal_search(self): map = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 2, 0], [0, 0, 1, 1, 1, 0, 0, 2, 0, 0], [0, 0, 0, 1, 1, 0, 2, 0, 0, 2], [0, 0, 0, 0, 1, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ] # Make it walkable only on tiles with a 2 walkable = lambda v: v != 2 # We need to annotate the clearance on the grid for later use in our pathfindings grid = Grid(map).annotate(walkable) finder = Pathfinder(astar.search) agent_characteristics = AgentCharacteristics(walkable=walkable, clearance=2) path = finder.get_path( grid, (0, 0), (8, 8), agent_characteristics=agent_characteristics, heuristic=cardinal_intercardinal, ) X = "x" marked_map = [ [X, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, X, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, X, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, X, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, X, 0, 0, 0, 2, 0], [0, 0, 1, 1, X, 0, 0, 2, 0, 0], [0, 0, 0, 1, 1, X, 2, 0, 0, 2], [0, 0, 0, 0, 1, 0, X, X, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0, X, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ] self._assert_the_resulting_path_nodes_should_be_like(marked_map, path)
def test_paths(self): """ Confirms each waypoint is reachable """ for z in range(self.dim_z + 1): # Create the graph, impediments are walls(0) and locked doors(L) imp = [] this_floor = [None for y in range(self.dim_y)] for y in range(self.dim_y): this_floor[y] = [None for x in range(self.dim_x)] for x in range(self.dim_x): this_floor[y][x] = self.grid[x, y, z][0] graph = GraphGrid(this_floor) # Default impediments are wall(0) and locked doors(L) imp = [(a, b) for a, b, c in self.grid if self.grid[a, b, z][0] in [0, '0', 'L']] # Set the list of impassable points graph.impassable = imp # Set the floor start and end points start, end = self.find_path_ends(z) self.logger.info('[*] Testing the path from {} to {}'.format( start, end)) # Initialize the path tester, as a_star for best path path_tester = Pathfinder(Pathfinder.gb_first) path_tester.g = graph path_tester.start = start[:2] path_tester.dest = end[:2] path = path_tester.execute() if not path: self.logger.error("Invalid pathfinding algorithm") else: for (x, y) in path: val = path[x, y] if val is not None: if self.grid[x, y, z][0] not in ['U', 'D', 'S', 'E']: self.grid[val[0], val[1], z][1] = [color.WHITE_ON_BLUE]
def test_astar_large_map(self, datadir): # Make it walkable only if walkable = lambda v: v != 2 map = (datadir / "large_map_hard.map").read_text() map = map.replace("@", "2").replace("T", "1").replace(".", "0") grid = Grid(map).annotate(walkable) finder = Pathfinder(astar.search) agent_characteristics = AgentCharacteristics(walkable=walkable, clearance=2) finder.get_path( grid, (0, 0), (8, 8), agent_characteristics, heuristic=cardinal_intercardinal, )
def __init__(self, game_map, ships): self.game_map = game_map self.id = min(ships) self.ships = ships self.vel_x = 0 self.vel_y = 0 self.magnitude = 0 self.angle = 0 self.target = None self.formation = 'ender' self.focus = None self.radius = None self.pathfinder = Pathfinder() self.position_modifier = [] if self.formation == 'ender': self.inner_ring_distance = 0.5 * 2 + SQUADRON_SPREAD self.outer_ring_distance = 0.5 * 4 + SQUADRON_SPREAD * 2 self.position_modifier.append((0, 0)) for angle in range(0, 360, 60): self.position_modifier.append( (self.inner_ring_distance, angle)) for angle in range(0, 360, 30): self.position_modifier.append( (self.outer_ring_distance, angle)) self.max_size = 19 if self.formation == '3': self.distance_between_ships = 0.5 * 2 + SQUADRON_SPREAD self.max_size = 3 for ship in self.ships: self.game_map.get_me().get_ship(ship).in_squadron = True self.distance_between_ships = 0.5 * 2 + SQUADRON_SPREAD self.update_position() self.x, self.y = self.get_center_point(self.ships)
def test_astar_all_heuristics_should_return_a_similar_path(self, all_heuristics): map = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 2, 0], [0, 0, 1, 1, 1, 0, 0, 2, 0, 0], [0, 0, 0, 1, 1, 0, 2, 0, 0, 2], [0, 0, 0, 0, 1, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ] walkable = lambda v: v != 2 grid = Grid(map).annotate(walkable) finder = Pathfinder(astar.search) startx, starty = 0, 0 endx, endy = 8, 8 paths = [] agent_characteristics = AgentCharacteristics(walkable=walkable, clearance=2) for heuristic in all_heuristics: paths.append( finder.get_path( grid, (startx, starty), (endx, endy), agent_characteristics, heuristic=heuristic, ) ) num_nodes = len(paths[0].nodes) assert all(len(path.nodes) == num_nodes for path in paths)
def __init__(self, width, height, tile_side_length): self.start_tile = None self.finish_tile = None self.width = width self.height = height self.tiles = [height * [0] for _ in range(width)] self.tiles_unordered = [] self.tile_images = pygame.sprite.Group() for x in range(width): for y in range(height): self.tiles[x][y] = Tile(x * tile_side_length, y * tile_side_length, tile_side_length) for col in self.tiles: for tile in col: self.tile_images.add(tile.sprite) self.tiles_unordered += [tile] self.establish_connections() self.pathfinder = Pathfinder(self.tiles_unordered, self.start_tile, self.finish_tile)
def main() -> None: drawing = """ ##### #..E# #...# #...# #S#.# #.#.# ##### """.strip() maze = Maze(drawing) # pf = Pathfinder(maze) # pf.show() start = Point(x=1, y=4) end = Point(x=3, y=1) pf.set_start_point(start) pf.set_end_point(end) # pf.show_maze_with_distance_values() pf.start_bfs_discovery() pf.show_maze_with_distance_values() path = pf.find_shortest_path() print(path)
import pygame import sys import random from map import Map from visualiser import Visualiser from pathfinder import Pathfinder map = Map() map.loadData() visualiser = Visualiser("Inlupp 2 - Visualiser", map.getWidth(), map.getHeight()) visualiser.setMap(map) pathfinder = Pathfinder(visualiser, map) pathfinder.findCheapestPath() visualiser.runLoop()
def __init__(self): print("Initializing local") local_grid = Grid(map) local_grid.annotate(walkable) self.finder = Pathfinder(astar.search, heuristic=cardinal_intercardinal)
def run_async(): map = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 2, 0], [0, 0, 1, 1, 1, 0, 0, 2, 0, 0], [0, 0, 0, 1, 1, 0, 2, 0, 0, 2], [0, 0, 0, 0, 1, 0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ] walkable = lambda v: v != 2 paths = [ ((0, 0), (8, 8)), ((0, 0), (3, 5)), ((1, 0), (1, 8)), ((0, 0), (8, 8)), ((0, 0), (8, 8)), ((0, 0), (8, 8)), ((0, 0), (8, 8)), ((0, 0), (8, 8)), ((0, 0), (8, 8)), ((0, 0), (8, 8)), ((0, 0), (8, 8)), ((0, 0), (8, 8)), ((0, 0), (8, 8)), ((0, 0), (8, 8)), ] * 100 agent_size = 2 with timewith(): grid = Grid(map) finder = Pathfinder(astar.search, heuristic=cardinal_intercardinal) grid.annotate(walkable) # Compute all the paths serially computed_paths = [] for start, end in paths: computed_paths.append( finder.get_path(start[0], start[1], end[0], end[1], agent_size)) assert len(computed_paths) == len(paths) # Multithreaded version. It should take almost the same as the previous one (or more due to overhead of threads) # since computing the path is a purely CPU bound operation. # Node: The options IS NOT threadsafe class PathFinderLocal(threading.local): def __init__(self): print("Initializing local") local_grid = Grid(map) local_grid.annotate(walkable) self.finder = Pathfinder(astar.search, heuristic=cardinal_intercardinal) local_finder = PathFinderLocal() with timewith(): with ThreadPoolExecutor(max_workers=5) as executor: def _(path_to_do): return local_finder.finder.get_path( path_to_do[0][0], path_to_do[0][1], path_to_do[1][0], path_to_do[1][1], agent_size, ) computed_paths = executor.map(_, paths) assert len(list(computed_paths)) == len(paths)
import_location() # import NWK records into memory import_network_links() # PATH = Pathfinder("CREWE", "EUSTON", ['ALSAGER', 'KIDSGRV', 'STAFFRD', 'NNTN', 'RUGBY']) # PATH = Pathfinder("CREWE", "CREWE", ['WEAVERJ', 'WIGANNW', 'LVRPLSH']) # PATH = Pathfinder("CREWE", "WEAVERJ") # PATH = Pathfinder("CREWE", "ACBG") # PATH = Pathfinder("CREWE", "WEAVERJ") # PATH = Pathfinder("CREWE", "WEAVERJ", ['CREWECY', 'WNSFD', 'HARTFD', 'ACBG']) # PATH = Pathfinder("CREWE", "CREWE", ['CREWECY', 'WNSFD', # 'HARTFD', 'ACBG', 'WIGANNW', 'LVRPLSH']) # PATH = Pathfinder("CREWE", "CREWE", ['CREWECY', 'WNSFD', # 'HARTFD', 'HARTFDJ', 'ACBG', 'WEAVERJ', 'WIGANNW', 'LVRPLSH']) # PATH = Pathfinder("CREWE", "BHAMNWS", ['ALSAGER', 'KIDSGRV', # 'LNGP', 'STOKEOT', 'STONE', 'STAFFRD', 'PNKRDG', 'WVRMPTN']) # PATH.search() # PATH = Pathfinder("CREWE", "CHST", avoid=['CREWESW']) # # PATH.search() PATH = Pathfinder("CREWBHJ", "ALSAGER") PATH.search() # # PATH = Pathfinder("CREWE", "DRBY") # # PATH.search()
# This sets the WIDTH and HEIGHT of each grid location WIDTH = 20 HEIGHT = 20 # HOW MANY NODES WE WANT ROWS = 30 COLUMNS = 30 # This sets the margin between each cell MARGIN = 5 # Create a 2 dimensional array. A two dimensional # array is simply a list of lists. grid = [] map_generator = Map_generator() pathfinder = Pathfinder() def init_map(): del grid[:] for row in range(ROWS): # Add an empty array that will hold each node # in this row grid.append([]) for column in range(COLUMNS): node = Node() node.x = row node.y = column node.color = "white" node.name = "My name is: ", node.x, node.y grid[row].append(node) # Append a cell pathfinder.update_neighbors(grid)
import socket import json from pathfinder import Pathfinder import time server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(("172.16.17.26", 8090)) server.listen(1) robot = Pathfinder() client, addr = server.accept() client.settimeout(2) try: while True: msg = client.recv(1024) if msg == "quit": break else: try: msg = json.loads(msg) robot.move(msg['x'], msg['y'], msg['w'],) except ValueError: pass except socket.timeout: print("timeout error") robot.move(0,0,0) except socket.error: print("socket error occured: ") robot.move(0,0,0) server.close()
from map import Map, load_map from pathfinder import Pathfinder map_40 = load_map() start = 8 goal = 27 pathfinder = Pathfinder(map_40, start, goal) path = pathfinder.path map_40.draw(path)