Thread: A* pathfinding

Page 4 of 8 FirstFirst ... 23456 ... LastLast
Results 31 to 40 of 73
  1. #31  
    Professional Upsetter


    Join Date
    Jul 2006
    Posts
    5,392
    Thanks given
    163
    Thanks received
    447
    Rep Power
    2040
    A* Pathfinding? How efficient is it lol.




    Looks like Greedy alg here. I'm surprised you got it working in realtime though, nice job either way. A* perfected doesn't have much of a place in games, unless you've optimized the shit out of it.


    Quote Originally Posted by netherfoam View Post
    Rather, less efficient. I want it to "try harder" to reach the goal, before quitting.
    You can't make more of your processing power distributed towards this, you'll just have to have delays before users actually move. (calc times)
    Ex-super moderator of Rune-Server.org and RSBot.org
    Reply With Quote  
     

  2. #32  
    Banned
    Join Date
    May 2014
    Posts
    32
    Thanks given
    6
    Thanks received
    14
    Rep Power
    0
    I have a few questions..

    1. Is this meant to go in a server
    2. What are you using this for? The client already calculates walking paths
    3. How are you dealing with the 50000MS cycle times caused by 100 players using this method at the same time?
    Reply With Quote  
     

  3. #33  
    Respected Member

    Join Date
    Jan 2009
    Posts
    5,682
    Thanks given
    1,093
    Thanks received
    3,494
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by phuckrunescape View Post
    I have a few questions..

    1. Is this meant to go in a server
    2. What are you using this for? The client already calculates walking paths
    3. How are you dealing with the 50000MS cycle times caused by 100 players using this method at the same time?
    1) yes
    2) npcs and players, the client path should be ignored for regular walking also.
    3) not sure where you got that crazy number but its actually rather fast.
    Reply With Quote  
     

  4. #34  
    Banned
    Join Date
    May 2014
    Posts
    32
    Thanks given
    6
    Thanks received
    14
    Rep Power
    0
    Quote Originally Posted by Stuart View Post
    the client path should be ignored for regular walking also
    Why would you ignore the client path? It generates it for you and you don't have to generate it on the server side. If you do want to implement your own path finding you should do it in the client, and have it send it to the server. You can simply check if the walking is valid from tile to tile on the server which takes nanoseconds instead of microseconds. You sure don't want 50% of your CPU to go to calculating walking tiles..

    Quote Originally Posted by Stuart View Post
    npcs
    In what case would you need an NPC to walk a path that isn't pre-generated? (Wondering what kind of custom content you're implementing)

    Quote Originally Posted by Stuart View Post
    not sure where you got that crazy number but its actually rather fast.
    But its not fast enough. Even 1MS is MUCH too long to spend calculating walking.. That's why RS doesn't have any pathfinding in the server, it would be almost impossible to host 2k players without spending ten times as much on hardware. You can see this in the fact that NPCs just walk in straight lines toward you.
    Reply With Quote  
     

  5. #35  
    Respected Member

    Join Date
    Jan 2009
    Posts
    5,682
    Thanks given
    1,093
    Thanks received
    3,494
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by phuckrunescape View Post
    Why would you ignore the client path? It generates it for you and you don't have to generate it on the server side. If you do want to implement your own path finding you should do it in the client, and have it send it to the server. You can simply check if the walking is valid from tile to tile on the server which takes nanoseconds instead of microseconds. You sure don't want 50% of your CPU to go to calculating walking tiles..
    To generate a valid walking queue, you can however just validate the received walking queue. RuneScape in later revisions do the walking completely server side.

    Quote Originally Posted by phuckrunescape View Post
    In what case would you need an NPC to walk a path that isn't pre-generated? (Wondering what kind of custom content you're implementing)
    Following other players and walking randomly

    Quote Originally Posted by phuckrunescape View Post
    But its not fast enough. Even 1MS is MUCH too long to spend calculating walking.. That's why RS doesn't have any pathfinding in the server, it would be almost impossible to host 2k players without spending ten times as much on hardware. You can see this in the fact that NPCs just walk in straight lines toward you.
    RuneScape do generate all walking server side and it is fast enough and if it isn't concurrency can be made use of.
    Reply With Quote  
     

  6. #36  
    Registered Member
    AkZu's Avatar
    Join Date
    Jan 2008
    Age
    26
    Posts
    393
    Thanks given
    249
    Thanks received
    162
    Rep Power
    343
    Err Jagex did move all pathfinding to server in 538ish ? Just to fix the damn wander around huge npcs because of server - client delay? I think. But your path generation client side gave me huge idea thanks
    Spoiler for OSRS in #414:
    Reply With Quote  
     

  7. #37  
    Banned
    Join Date
    May 2014
    Posts
    32
    Thanks given
    6
    Thanks received
    14
    Rep Power
    0
    Quote Originally Posted by AkZu View Post
    Err Jagex did move all pathfinding to server in 538ish ? Just to fix the damn wander around huge npcs because of server - client delay? I think. But your path generation client side gave me huge idea thanks
    They do now, which is due to the fact that they make 10m a month and have supercomputer dedis.. So they really don't give a **** about proper client server paradigms anymore as they did back in they day before it was a corporation. You can see this in the fact that the 317 client can just about run off of a toaster oven.. The new clients are sloppy and lack this sophistication and efficiency.

    An idea would be to create a packet where you send off the work of NPC path finding to multiple random clients, have them process the information, and then check for consistency and send back a valid walking queue. Then check tile to tile validity. You would need to configure something like that if you wanted to add path finding for thousands of NPCs as well as players. Honestly there should not be path finding server sided. The CPU cost is just not worth it, you could be spending that extra money you need for a better dedi on advertising.
    Reply With Quote  
     

  8. #38  
    REGISTERED MEMBER RAT DONOR MORE COMING

    Major's Avatar
    Join Date
    Jan 2011
    Posts
    3,002
    Thanks given
    1,295
    Thanks received
    3,549
    Rep Power
    5000
    Quote Originally Posted by phuckrunescape View Post
    In what case would you need an NPC to walk a path that isn't pre-generated? (Wondering what kind of custom content you're implementing)
    You want to hard-code every possible path an npc could take..?


    Quote Originally Posted by phuckrunescape View Post
    But its not fast enough. Even 1MS is MUCH too long to spend calculating walking.. That's why RS doesn't have any pathfinding in the server, it would be almost impossible to host 2k players without spending ten times as much on hardware. You can see this in the fact that NPCs just walk in straight lines toward you.
    1. 1ms is not "much too long", you've got 599 left (unless you meant 1ms per character, in which case this doesn't happen).
    2. Runescape has calculated the path on the server for the last ~300 revisions. It's likely the only reason it wasn't done initially was to reduce the server processing time (hardware in 2001-2006 wasn't as good as it is now, surprisingly). It's not as expensive as you think.
    3. NPCs use a dumb path-finder yes, but that's because they always have and such a change would be a huge overhall. Also some current NPCs (e.g. Nex) use the A* algorithm to find a path instead.

    Quote Originally Posted by phuckrunescape View Post
    They do now, which is due to the fact that they make 10m a month and have supercomputer dedis..
    Yeah these are expensive and idk if you've heard of capitalism but traditionally it makes companies avoid expense.

    Quote Originally Posted by phuckrunescape View Post
    You can see this in the fact that the 317 client can just about run off of a toaster oven.. The new clients are sloppy and lack this sophistication and efficiency.
    Yeah I'm glad you noticed how the client has gotten slower but the graphics are identical to 8 years ago - if it wasn't for that, you'd think the additional complexity would be the problem!

    Quote Originally Posted by phuckrunescape View Post
    An idea would be to create a packet where you send off the work of NPC path finding to multiple random clients, have them process the information, and then check for consistency and send back a valid walking queue.
    Not only is this possibly illegal, it's also a stupid idea. Even if you pick the clients with the lowest latency, it's almost certainly going to take longer than however long you have left this cycle at some point or another (making the pathfinding take 1.2 seconds... not very realtime).
    Reply With Quote  
     

  9. #39  
    Banned
    Join Date
    May 2014
    Posts
    27
    Thanks given
    6
    Thanks received
    3
    Rep Power
    0
    Quote Originally Posted by phuckrunescape View Post
    They do now, which is due to the fact that they make 10m a month and have supercomputer dedis.. So they really don't give a **** about proper client server paradigms anymore as they did back in they day before it was a corporation. You can see this in the fact that the 317 client can just about run off of a toaster oven.. The new clients are sloppy and lack this sophistication and efficiency.

    An idea would be to create a packet where you send off the work of NPC path finding to multiple random clients, have them process the information, and then check for consistency and send back a valid walking queue. Then check tile to tile validity. You would need to configure something like that if you wanted to add path finding for thousands of NPCs as well as players. Honestly there should not be path finding server sided. The CPU cost is just not worth it, you could be spending that extra money you need for a better dedi on advertising.
    Well people can use cheat clients to noclip
    Reply With Quote  
     

  10. Thankful users:


  11. #40  
    Banned
    Join Date
    May 2014
    Posts
    32
    Thanks given
    6
    Thanks received
    14
    Rep Power
    0
    Attempted to make a self contained benchmark, and it looks like your code just loops forever..

    Code:
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.LinkedList;
    import java.util.List;
    
    public class AStarPathFinder {
        
        public static void main(String[] args) {
            WorldNode node = new WorldNode(40);
            AStarPathFinder path = new AStarPathFinder(node);
            
            path.getPath(new Position(10, 10), new Position(11, 11));
        }
    
        static class Position {
    
            Position(int x, int y) {
                this.x = x;
                this.y = y;
            }
    
            int x, y;
    
            int getX() {
                return x;
            }
    
            int getY() {
                return y;
            }
        }
    
        private static final class Point implements Comparable<Point> {
    
            private Position end, position;
            private Point parent;
            private int cost;
    
            public Point(Position end, Point parent, Position position, int cost) {
                this.end = end;
                this.parent = parent;
                this.position = position;
                this.cost = cost;
            }
    
            /**
             * Gets the heuristic score for this point.
             *
             * @return the heuristic score
             */
            private int getHeuristicScore() {
                return Math.abs(position.getX() - end.getX())
                        + Math.abs(position.getY() - end.getY());
            }
    
            /**
             * Gets the cost of the path up to this point.
             *
             * @return the path cost
             */
            public int getPathCost() {
                Point current = this;
                int totalCost = 0;
                while (current.parent != null) {
                    totalCost += current.cost;
                    current = current.parent;
                }
                return totalCost;
            }
    
            /**
             * Gets the projected path cost if the point had a given parent and
             * cost.
             *
             * @param projectedParent the parent
             * @param costToParent the cost to the parent
             * @return the projected path cost
             */
            public int getProjectedPathCost(Point projectedParent, int costToParent) {
                Point current = projectedParent;
                int projectedCost = costToParent;
                while (current.parent != null) {
                    projectedCost += current.cost;
                    current = current.parent;
                }
                return projectedCost;
            }
    
            /**
             * Gets the total cost.
             *
             * @return the total cost
             */
            public int getTotalCost() {
                return getPathCost() + getHeuristicScore();
            }
    
            @Override
            public int compareTo(Point other) {
                return getTotalCost() - other.getTotalCost();
            }
    
            @Override
            public boolean equals(Object o) {
                if (this == o) {
                    return true;
                }
                if (o == null || getClass() != o.getClass()) {
                    return false;
                }
                Point point = (Point) o;
                return position.equals(point.position);
            }
    
            @Override
            public int hashCode() {
                return position.hashCode();
            }
    
            public void setParent(Point parent) {
                this.parent = parent;
            }
    
            public void setCost(int cost) {
                this.cost = cost;
            }
        }
    
        static class WorldNode {
    
            WorldNode(int size) {
                tiles = new boolean[size][size];
                for (int x = 0; x < size; x++) {
                    for (int y = 0; y < size; y++) {
                        tiles[x][y] = Math.random() > 0.5D;
                    }
                }
            }
            boolean[][] tiles;
    
            boolean canStep(Position from, Position to) {
                if(to.x < 0 || to.y < 0 || to.x >= tiles.length || to.y >= tiles.length) return false;
                return tiles[to.x][to.y];
            }
        }
    
        private WorldNode world;
    
        public AStarPathFinder(WorldNode world) {
            this.world = world;
        }
    
        public List<Position> getPath(Position start, Position end) {
            List<Point> openTiles = new LinkedList<>();
            List<Position> usedTiles = new LinkedList<>();
            Point current = new Point(end, null, start, 0);
            openTiles.add(current);
            while (!current.position.equals(end)) {
                if (openTiles.isEmpty()) {
                    // no more walkable tiles
                    break;
                }
                openTiles.remove(current);
                usedTiles.add(current.position);
    
                List<Position> adjacentTiles = getAdjacentWalkableTiles(current.position);
                if (usedTiles.containsAll(adjacentTiles)) {
                    // we have tried every walkable tile
                    break;
                }
                for (Position position : adjacentTiles) {
                    if (usedTiles.contains(position)) {
                        continue;
                    }
                    int deltaX = position.getX() - current.position.getX(),
                            deltaY = position.getY() - current.position.getY();
                    int cost = (int) Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
                    Point point = new Point(end, current, position, cost);
                    if (!openTiles.contains(point)) {
                        openTiles.add(point);
                    } else {
                        Point other = openTiles.get(openTiles.indexOf(point));
                        if (other.getProjectedPathCost(point, cost) < other.getPathCost()) {
                            other.setParent(point);
                            other.setCost(cost);
                            Collections.sort(openTiles);
                        }
                    }
                }
                Collections.sort(openTiles);
                current = openTiles.get(0);
            }
            List<Position> path = new LinkedList<>();
            while (current.parent != null) {
                path.add(current.position);
                current = current.parent;
            }
    
            List<Position> rev = new LinkedList<>();
            for (int i = 0; i < path.size(); i++) {
                rev.add(path.remove(path.size() - (i + 1)));
            }
            return rev;
        }
    
        /**
         * Gets the walkable tiles that are adjacent to a position.
         *
         * @param pos the position
         * @return the tiles
         */
        private List<Position> getAdjacentWalkableTiles(Position pos) {
            List<Position> tiles = new ArrayList<>();
            for (int deltaX = -1; deltaX <= 1; deltaX++) {
                for (int deltaY = -1; deltaY <= 1; deltaY++) {
                    Position deltaPosition = new Position(pos.getX() + deltaX,
                            pos.getY() + deltaY);
                    if (world.canStep(pos, deltaPosition)) {
                        tiles.add(deltaPosition);
                    }
                }
            }
            return tiles;
        }
    }
    Quote Originally Posted by Major View Post
    You want to hard-code every possible path an npc could take..?
    No? NPCs just walk toward the target usually, that's how RS workes.


    Quote Originally Posted by Major View Post
    1. 1ms is not "much too long", you've got 599 left (unless you meant 1ms per character, in which case this doesn't happen).
    Yes I meant per player, obviously.. .5ms is too long. .25 ms is too long. .1ms is too long. How quick do you think this algorithm is?


    Quote Originally Posted by Major View Post
    2. Runescape has calculated the path on the server for the last ~300 revisions. It's likely the only reason it wasn't done initially was to reduce the server processing time (hardware in 2001-2006 wasn't as good as it is now, surprisingly). It's not as expensive as you think.
    Thank you for re stating what I said?


    Quote Originally Posted by Major View Post
    3. NPCs use a dumb path-finder yes, but that's because they always have and such a change would be a huge overhall. Also some current NPCs (e.g. Nex) use the A* algorithm to find a path instead.
    I see no problem with using path finding for bosses, as it would be only a few NPCs. Just not every npc.



    Quote Originally Posted by Kale View Post
    Well people can use cheat clients to noclip
    Not if you CHECK TILE CLIPS server sided like I said.. Please learn to read.
    Reply With Quote  
     

Page 4 of 8 FirstFirst ... 23456 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. PathFinding bug.
    By Serenity in forum Help
    Replies: 7
    Last Post: 09-18-2009, 01:05 PM
  2. Pathfinding
    By Aoife in forum Informative Threads
    Replies: 17
    Last Post: 09-06-2009, 05:38 AM
  3. Pathfinding on 508
    By peterbjornx in forum Show-off
    Replies: 12
    Last Post: 06-29-2009, 04:51 PM
  4. 550 pathfinding + cliping
    By Lazaro in forum Show-off
    Replies: 22
    Last Post: 06-27-2009, 09:44 PM
  5. Pathfinding and Clipping library
    By peterbjornx in forum Projects
    Replies: 22
    Last Post: 05-02-2009, 09:04 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •