Git Product home page Git Product logo

java-a-star's Introduction

Java-A-Star

A basic Java implementation of A-star or A-* search algorithm

The intention is to be a small standalone Java implementation that is easy to adapt to new use cases.

This implementation is also meant to be fast and memory efficient and it can actually scale pretty well.

The input of the algorithm is :

  • a "weight" grid, giving the cost of entering a given cell. For a basic application, set cost 1.0f for empty (pathable) cells and MAX_FLOAT for walls and other obstacles.
  • a start and target positions, our goal is to find the minimal cost path from start to target.

The output is an ordered list of positions, representing one shortest path from start to target.

The assumptions are that :

  • moves are vertical or horizontal, their cost is simply the cost of entering the cell. If you want "realistic" diagonal movements, add the 4 new adjacent positions in the main loop, and remember to make their entry cost $sqrt(2)$ more expensive.
  • because of this assumption, the basic approximation used for heuristic distance estimation and cutoff is the "manhattan" distance.

The implementation uses :

  • A java.util.PriorityQueue is the important data structure used to efficiently deal with the choice of next explored node.
  • During the main loop, all data is flattened to a one dimensional array, hence positions are simply a single integer. Updates therefore do a lot of modulo width or integer divide by width, i.e. recompute (row,grid) from this index.
  • The output of the low-level procedure is a reversed list of node indexes, from goal to start. A wrapper is offered to expose this as a list of Point2D.

Example usage

The example main shows how to to produce the initial float [] weights by supposing we have a screen of pixels given as grid of characters where . is passable and # is a wall.

The code is more general than the use of it done in the main ; in particular we only consider walls or empty spaces in the grid when the algorithm supports arbitrary costs.

Acknowledgements

This project is under MIT License, use it as you will.

Originally based on project : https://github.com/hjweide/a-star/ Copyright (c) 2016 Hendrik Weideman

This port to Java by Yann Thierry-Mieg (c) (2020) based off of https://github.com/yanntm/YoBot/blob/master/Astar.cpp.

java-a-star's People

Contributors

yanntm avatar

Watchers

 avatar  avatar  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.