Code Monkey home page Code Monkey logo

rts-pathfinding's Introduction

In this project, I worked with S3, a simple RTS game designed to test AI techniques. S3 looks very simple and has pretty basic graphics, but it features most of the characteristics of more complex RTS games such as Starcraft. The goal of this project is to learn how to implement pathfinding methods, which are the most common technique in computer games of all genres. Specifically, I implemented an A* approach to path finding.

One thing to note is that I implemented a Node class for creating and using Nodes in my A* algorithm. The Node class stores the parent, x, y, g, and h values for a Node and has a method to calculate the heuristic using the Manhatten Distance. Since I am using a HashSet, I overrided the hashCode and equals methods in my Node class.

To implement A* pathfinding in my program, I refernced the following algorithm:

Start.g = 0;
Start.h = heuristic(Start)
OPEN = [Start];
CLOSED = []
WHILE OPEN is not empty
N = OPEN.removeLowestF()
IF goal(N) RETURN path to N
CLOSED.add(N)
FOR all children M of N not in CLOSED:
M.parent = N
M.g = N.g + 1;
M.h = heuristic(M)
OPEN.add(M)
ENDFOR
ENDWHILE

In order for A* to work properly, I had to implement three helper methods removeLowestF, retrievePath, and isCellFree. The removeLowestF method removes the node with the lowest F, the value of g and h combined, from the open list. The retrievePath method retrieves the shortest path by returning a list of the goal node's parents. The isCellFree method checks if the S3PhysicalEntity is able to a desired cell.

rts-pathfinding's People

Contributors

kuinsim avatar

Watchers

 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.