• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
markypooch

A* Pathfinding

6 posts in this topic

Hello all,

 

I recently undertook an ambitious goal of implementing A* pathfinding in my aliens AI

 

While the result in my opinion for a first attempt has been relatively successful, I still have questions that need to be answered. 

 

Thats why I'm here to talk to the best ;) 

 

My aliens traverse a level consisting of tiles that carry a hurestic, gCost, and a final FCost given by 

 

fCost = hurestic + gCost;

 

My aliens will choose the 8 nodes around their position and choose the one with the lowest fCost.

 

Notes

----------------------------

I am using the manhattan method for the gCost and hurestic.

 

the hurestic is given by 

 

diffTileX = StartTileX - TargetTileX

diffTileY = StartTileY - TargetTileY

 

huresticMulitplier = abs(diffTileX) + abs(diffTileY);

 

hurestic  = 10 * huresticMultiplier;

 

the gCost is given by 

 

a orthongonal move is 10 + the accumulative gCost of parent Node

a diagonal       moveis 14 + the accumulative gCost of parent Node

 

--------------------------

 

My alien will pick the node in the list (after a bubble sort) that has the lowest f-Cost, no more, no less.

 

However!

 

My alien DOES find my position, but does not take a direct route AT ALL!

 

Should there be futher testing other then just an f-Cost?

 

If so, then what? Should I check if the path that leads to the target has a incrementally dropping hurestic?

 

I will include a picture to show the aliens path during run-time

 

[attachment=20314:Untitled.jpg]

0

Share this post


Link to post
Share on other sites

This may not have been the correct place to post this topic, ill move it if asked.

 

Also as you can see the Alien will always find the target, but will take a very unconcise path

0

Share this post


Link to post
Share on other sites

I figured it out....sorta.

 

Once all of the nodes have been recorded with the lowest f-Cost, then I trace the path from the target and check the adajecent nodes while tracing and only trace the one with the lowest g-Cost to eliminate redundant moves. However, I feel this is the most brute-force way to approach it. Does anybody know a better one?

 

I mean, I am check against all the nodes in the path to see if there adajecent to that current square (this involves several for-loops that iterate several hundred times). once I get all the squares adajcent to the current square, I then check to see which has the lowest g-Cost. If only one node is adajecent to the current node, then I dont bother doing any testing and add it to the final path.

 

Is there a better way to approach this? Like when I am recording the f-Cost maybe instead of offsetting until after the fact?

 

http://i912.photobucket.com/albums/ac327/markypooch/final_zps31e712dd.png

 

P.S.

   

    For what it's worth the alien does take a now much better path :D

 

 

-Marcus

0

Share this post


Link to post
Share on other sites

In order to find the optimal route, you need to implement A* somewhat differently.

 

First off, your heuristic needs to underestimate the cost after a candidate step - at the moment, I suspect that it doesn't.

 

Secondly, to find the optimal path, the A* algorithm needs to explore completely to the target. You need to keep a heap of <fCost,path> tuples, and iterate popping the least cost path off the heap, enumerating all the valid moves from that point, and pushing updated tuples onto the heap until you reach the goal.

 

You can't make a single iteration of the above loop and then make a movement choice based upon that.

 

A* is essentially a breadth-first search of the tree of moves, with the heuristic serving to delay searching likely unprofitable paths.

 

What it sounds like you're implementing currently (by fixing a move choice at each step) is more like depth-first search.

0

Share this post


Link to post
Share on other sites

The algorithm that I am currently using is as you guessed does indeed overestimate it.

 

I like your suggestion of using the tuples. I feel this is once again a instance where I jumped head first into a concept way over my head without thinking about it enough.

 

My implementation of A* works now and DOES find a concise path, but at the cost of I fear performance, and the creeping suspicion of knowing that Im going about it as you mentioned the least optimal way.

Ill switch my hurestic to underestimate . And eventually revise the entire algorithm to embody a breadth-first search as opposed a depth-first search (which I am going to google after this reply ph34r.png

 

But your completely right, my hurestic overestimates it, and I choose a step every iteration.

 

Thanks a bunch for the reply,

 

-Marcus

0

Share this post


Link to post
Share on other sites

The good thing is that you don't need to recompute paths all that often. You should be able to implement it efficiently enough for realtime use.

 

Definitely you should use a heap rather than bubble sort. Bubble sort is only ever a good idea for almost sorted data. Its average time complexity is O(n^2), which means that it will quickly dominate the pathfinding. A heap, in contrast, can be used to completely sort in O(nlog(n)) time, and incremental operations like adding and removing values, it's O(log(n)).

 

Another useful optimization is to break your map up into convex regions, because the shortest path in a convex region is straightforward. Thus you can take bigger steps (crossing an entire convex space in one move) and potentially reach your goal with less exploration.

0

Share this post


Link to post
Share on other sites

Alright, I think I got it.

 

The alien will always find the shortest path (IF THERE IS ONE (Denoted by no more nodes in the OpenList)) 

 

For the sake of visual representation, I drew on the tiles to show nodes contained in the OpenList, ClosedList, and the FinalPath traced back from the target to 

each parent back to the start node

 

In the last photo you'll see the alien went off the map to find the shortest path, that of course will be reprimanded.

 

I'm glad I got it working correctly, now I can work on aliens decision making and other areas of the AI

 

**Edit

 

Red is the openList, 

Blue is the ClosedList

yellow is the finalPath

Edited by markypooch
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0