I have already implemented A star path-finding in C# language via grid based system. But I am trying to make a system which will use a ladder to move to a shortest distance if there is any ladder available in that shortest. But i am without any clue how to do that , i have searched online and read a lot of posts still i am confused how to do that , so it will be much helpful to me how to add the ladder feature in a A star path-finding algorithm.
Image
Thanks.
Think of your ladders as vertices in your graph. Then you just need to apply A*, which is a best-first search. This is a well-documented algorithm. For example:
A* is an informed search algorithm, or a best-first search, meaning
that it solves problems by searching among all possible paths to the
solution (goal) for the one that incurs the smallest cost (least
distance travelled, shortest time, etc.), and among these paths it
first considers the ones that appear to lead most quickly to the
solution. It is formulated in terms of weighted graphs: starting from
a specific node of a graph, it constructs a tree of paths starting
from that node, expanding paths one step at a time, until one of its
paths ends at the predetermined goal node.
Related
I have a 3D voxel game and I'm trying to find best fitting pathfinding algorithm to use. I've been wondering if the A* algorithm is capable of handling multiple levels, for example a multi-story building and find routes through staircases or ladders.
Is this possible with A* or should I use something else?
Thanks in advance.
Any path-finding algorithms(uniform or non-uniform) can be used as long as you use them right. You have to decide first on what kind of path-finding you want to use depending on what you want to achieve.
Uniform or graph algorithms can have a lot of overhead for a multi-story building due to excessive nodes. (assuming that you are building the whole building all at once)
Non-uniforms are way slower than graph algorithms but doesn't have much of a overhead.
It really depends on what you want your characters to do, and how you will optimize it.
A* is fast, but you might want to check out some iterations of A* like jump point system.
Try using the NavMesh component based workflow first. If there is a nice staircase behaviour that can be efficiently and automatically used, NavMesh will find it.
Otherwise, you will need to use something called hierarchical search. Read an example here.
TL;DR
Given a 2-dimensional plane (say, 800x600 pixels or even 4000x4000) that can contain obstacles (static objects) or entities (like tanks, or vehicles), how can computer-controlled tanks navigate the map without colliding with static objects while pursuing other tanks? Please note that every static object or entity has the ability to freely rotate at 360 degrees and has an arbitrary size.
Context
What I am really trying to do is to develop a game with tanks. It initially started as a modern alternative to an old arcade game called "Battle City". At first, it might have been easy to develop an AI, considering the 13x13 grid, fixed sizes and no rotation. But now, with free rotation and arbitrary sizes, I am unable to find a way of replicating such behavior in these circumstances.
The computer-controlled tanks must be able to navigate a map full of obstacles and pursue the player. I think that the main problem is generating all the possibilities for a tank to go to; the collision system is already implemented and awaiting to be used. For example, tanks might be able to fit through tight spaces (which can be diagonal, for instance) just by adjusting its angle of rotation.
Although I have quite some experience in programming, this is way beyond my reach. Even though I would prefer a broader answer regarding the implementationn of tank's artificial intelligence, a method for generating the said paths might suffice.
I initially though about using graphs, but I do not know how to apply them considering different tanks have different sizes and the rotation thing gives me a headache. Then again, if I would be using graphs, what will a node represent? A pixel? 16,000,000 nodes would be quite a large number.
What I am using
C# as the main programming language;
MonoGame (XNA Framework alternative) for rendering;
RotatedRectangle class (http://www.xnadevelopment.com/tutorials/rotatedrectanglecollisions/rotatedrectanglecollisions.shtml).
I am looking forward for your guidelines. Thank you for your time!
I've been working on a project of crowd simulation that included path finding and obstacles/other people avoidance.
We've used the Recast Navigation, a all-in-one library which implements state-of-the-art navigation mesh algorithms.
You can get more info here : https://github.com/memononen/recastnavigation
In our project, it has proven to be reliable and very configurable. Even if it's written in C++, you can easily find/make a wrapper (in our case, we've been using it wrapped in Javascript on a Nodejs server!)
If you don't want to use this library, you can still take a look at Navigation Meshes, which is the underlying theory behind Recast.
I hope it will help!
Navigation Mesh, that's what ur looking for. To explain a bit, it's in theory really easy. U build ur World (2D/3D) and after creation u generate a new mesh, that tells entities where they are allowed to move, without colliding with the surroundings. They then move on this mesh. Next is the path generation algorithm which is basically nothing else then checking in any mathematically form how to get on this mesh to it's target. On an actual navigation mesh, this get's rather complicated but easy if u think of a grid where u check which fields to move to get the shortest way.
So short answered, u need any type of additional layer of ur world, that tells the AI where it is allowed to move, and any kind of algorithm that fits ur type of layer to calculate the path.
As a hint, for unity as an example, there are many free good build solutions. Also u will find a bunch of good libraries to achieve this without a game engine like unity.
I am working on a little computational geometry library that uses Mathematica's NETLink to allow polytopes to be modeled in C# and controlled viewed via Mathematica. I hope to allow easy and exact manipulation of geometry, with a focus on geometry unfolding problems.
Currently I am looking to implement an exact shortest path's algorithm on a convex polyhedron. It's been suggested to me that I use Chen and Han's algorithm to do this, and specifically that I look at O'Rourke's implementation. However, this is a pretty big task. Given that I'm starting with quick-and-dirty techniques for the rest of the functions, I'm looking for something simpler, even if it has significantly worse performance.
There is an algorithm by Sharir and Schorr that gets the shortest path in O(n^3) time (with n I assume being the number of vertices), but I can't seem to find the paper anywhere. I'm wondering if this algorithm is indeed simpler, if any implementations of it already exists, and just if anyone has some general advice.
I have a set of points, the coordinates are not predetermined and I can set them when I create them, but their links are predetermined. A point can have one or more links, but not zero.
I want to be able to generate a visual representation of these points at positions where these link lines between them will not intersect. From what I've learned in researching so far, I believe this will be somewhat similar to a planar graph, however there will be points with only one link, and I'm not sure planar graphs are able to represent these.
I'm not sure if there is a good way of doing what I am trying to do or not, but I'll admit that maths is not my strong suite. My 'best' idea so far is to somehow detect these intersections and then move points in a direction that somehow takes the intersection location into account to reposition them so that that particular intersection does not occur....and to loop and do this for every point until no more intersections are detected. However there could well be some sort of more efficient mathematical algorithm that I could use instead that I am simply unaware of.
I'm interested in all advice here, whether it is efficient or not.
This is not an easy problem. Here are the Google search results for “algorithm to draw a planar graph”. The Boost C++ Library has some support for drawing planar embeddings including an example. These of course use C++, not the C# you tagged the problem with.
I know my question seems pretty vague, but I can't think of a better way to put it, so I'll start off by explaining what I'm trying to do.
I'm currently working on a project whereby I've been given a map and I'm coding a 'Critter' that should be able to navigate its way around the map; the critter has various other functions, but those are not relevant to the current question. The whole program and solution is being written in C#.
I can control the speed of the critter, and retrieve its current location on the map by returning its current X and Y position, I can also set its direction when it collides with the terrain that blocks it.
The only problem I have is that I can't think of a way to intelligently navigate my way around the map; so far I've been basing it on what direction the critter is facing when it collides with the terrain, and this is in no way a good way of moving around the map!
I'm not a games programmer, and this is for a software assignment, so I have no clue on AI techniques.
Here's a link to an image of what the maps and critters look like:
Map and Critter image
I'm in no way looking for anyone to give me a full solution, just a push in the general direction on map navigation.
If the only knowledge of the environment that you have is the position of your critter and its velocity the best you can do is a wall following algorithm I think. If you can detect some of the other things in your environment you have many more options.
Some of the more popular algorithm types are...
A* Search (The classic)
Visibility Graphs
Voronoi Diagrams (similar to the above)
Potential Fields
Potential Fields is a fancy way of saying every obstacle or wall has a "repulsive force" while every goal has an "attractive force". The strength of the force is based on the distance from the object and the "severity" of the object. (A pit of lava is much more severe to travel through than a bumpy road) After constructing the force fields the naive algorithm boils down to following the path of least resistance. Better versions can detect local minima and maxima and escape those wells.
Critter
-----\ /-------\
\ / \
\/ \
Local Minima Trap \
\
\
Goal
A* Search
Take a look at the A* pathfinding algorithm. It's essentially the standard approach for stuff like this.
Amit Patel's write up on pathfinding for games has a pretty good introduction to A* as well as popular variants of the algorithm.
You'll find a C# implementation here, and here
Dynamic A*
Let's say the terrain you'll be searching is not known ahead of time, but rather is discovered as the agent explores its environment. If your agent comes across a previously unknown obstacle, you could just update the agent's map of the terrain and then re-run A* to find a new path to the goal that routes around the obstruction.
While a workable solution, rerunning the planning algorithm from scratch every time you find a new obstacle results in a sizable amount of redundant computation. For example, once you're around the obstacle, it might be that the most efficient route to the goal follows the one you were planning on taking before you discovered the obstacle. By just rerunning A*, you'll need to recompute this section of the previous path.
You can avoid this by using Dynamic A* (D*). Since it keeps track of previously computed paths, when the agent finds a new obstacle, the system only needs to compute new routes in the area around the obstacle. After that, it can just reuse existing paths.
I would use a goal-oriented approach. Your question states the goal is than explore the map and avoid obstacles, so that's what we make our goal. But how do we explore the whole map? We explore what is unexplored.
From the outset you have only one unexplored area, the square you are on. The rest of the map is marked as unexplored. You choose an unexplored location, and make it your goal to explore it. But how do you get there? You create a subgoal to explore the location next to it. And how do you do that - explore the square next to that, and so on, until your original goal is broken down into a sequence of explorations, starting from your current square and navigating to the target square.
As you hit obstacles and discover features of the map, some of the subgoals may need to be changed. E.g. when you hit a wall, the subgoal to explore that square has to be scrubbed and you create a new plan to find an alternate route. This is known as backtracking.
That's basically it for the high level description. I hope it helps!
I seem to be late at the party. If your critter have a GPS and the full map at hand, the right thing to do is definitely A*, and if the map is small enough a simple BFS would do as well if you don't feel like coding up A* (A* has quite a few corner cases you want to handle right).
However a different question is what if your critter only knows the direction of the goal and can only observe locally what is around it? What if your critter does not know the full map?
In this case you would want to implement the "bug algorithm" for navigation. Link: http://www.cs.cmu.edu/~./motionplanning/lecture/Chap2-Bug-Alg_howie.pdf
It's a cute piece of algorithm that works for all unknown maps, you would have a blast coding it I'm sure.