def test_astar(map_): astar = libtcodpy.path_new_using_map(map_) assert not libtcodpy.path_compute(astar, *POINTS_AC) assert libtcodpy.path_size(astar) == 0 assert libtcodpy.path_compute(astar, *POINTS_AB) assert libtcodpy.path_get_origin(astar) == POINT_A assert libtcodpy.path_get_destination(astar) == POINT_B libtcodpy.path_reverse(astar) assert libtcodpy.path_get_origin(astar) == POINT_B assert libtcodpy.path_get_destination(astar) == POINT_A assert libtcodpy.path_size(astar) != 0 assert libtcodpy.path_size(astar) > 0 assert not libtcodpy.path_is_empty(astar) for i in range(libtcodpy.path_size(astar)): x, y = libtcodpy.path_get(astar, i) while (x, y) != (None, None): x, y = libtcodpy.path_walk(astar, False) libtcodpy.path_delete(astar)
def create_path(self, gamemap_instance): """Creates the initial path_map, and then on subsequent calls uses that path_map to play.""" mymap = gamemap_instance.level if not self.is_pathmap_created: #Create the path map self.path_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for x in range(1, MAP_WIDTH): for y in range(1, MAP_HEIGHT): libtcod.map_set_properties(self.path_map, x, y, not mymap[x][y].block_sight, not mymap[x][y].blocked) self.is_pathmap_created = True # now use the path map to create the path from the explorer's current position to another spot: self.path = libtcod.path_new_using_map(self.path_map) random_destination_x, random_destination_y = choose_random_unblocked_spot(mymap) libtcod.path_compute(self.path, self.owner.x, self.owner.y, random_destination_x, random_destination_y) originx, originy = libtcod.path_get_origin(self.path) destx, desty = libtcod.path_get_destination(self.path)