Coder Social home page Coder Social logo

darsausalo / rts-path-finding Goto Github PK

View Code? Open in Web Editor NEW

This project forked from guinzoo/rts-path-finding

0.0 1.0 0.0 29 KB

Path finding algorithms for RTS-games implemented with C++ (A*, JPS, Wall-tracing)

License: MIT License

C++ 100.00%

rts-path-finding's Introduction

rts-path-finding

C++ implementation of path finding algorithms for RTS-games with grid map.

How to use

This code is used in my RTS-like game with custom in-house engine. I copied it as is, without implementation of many classes, like vec2, Array, MemoryManager etc. So if somebody wants to use it, he needs to replace them.

Algorithms work on grid map with maximum side size 2^16. If cell is not walkable there is a wall. Also there is a possibility to add round obstacles with arbitrary radius. Borders of the input map must be unwalkable because of there is no check if coordinates are out of borders for optimization reasons.

There are 2 phases of finding path:

  1. Rough - position of joints restricted to center of cells. Path can be found using one of 3 algorithms: A*, JPS or JSP+. Obstables have no influence on resulting path.
  2. Precise - works in continuous space using "Wall Tracing"

That scheme was gotten from game "Dota 2". First you search rough path to destination point, then precise path from current position to some point on rough path. After a while when distance to that point become short enough, you search precise path to another point on rough path.

Unlike many other implementations of A* and JPS, that can find closest path to some unreachable location. JPS uses improved algorithm that doesn't cut edges and was published in 2012 (http://harabor.net/data/papers/harabor-grastien-socs12.pdf). JPS+ cache distances to jump points.

Search time to unreachable locations with grid size 256x256 and low number of walls:

Name Time
A* ~26 ms
JSP ~7.5 ms
JPS+ ~0.5 ms

Wall Tracing

The most hard part is "Wall Tracing" algorithm. I was impressed with "Dota 2" path finding system and started to search how to realize it. But everything I found was only 1 mention here without any explanation. So I started to invent it myself.

This implementation doesn't use trigonometric functions and works very fast for short distances (< 0.2 ms). Found paths are not guaranteed to be shortest, but in most cases looks good.

rts-path-finding's People

Contributors

guinzoo avatar

Watchers

Denis Potapov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.