patmooney/java-astar


Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.patmooney:java-astar:0.004'
	}
	dependencies {
		implementation("com.github.patmooney:java-astar:0.004")
	}
	<dependency>
	    <groupId>com.github.patmooney</groupId>
	    <artifactId>java-astar</artifactId>
	    <version>0.004</version>
	</dependency>

                            
    libraryDependencies += "com.github.patmooney" % "java-astar" % "0.004"
        
        

                            
    :dependencies [[com.github.patmooney/java-astar "0.004"]]
        
        

Readme


AStar - for pathfinding

A library for pathfinding using A Star

Usage

import github.patmooney.astar.AStar;
import github.patmooney.astar.Tile;

/*
    A Tile has three attributes, x (int) + y (int) coordinates are it's array indexes
    and solid ( boolean ) signifies whether it is walkable
*/

// Tile array is treated as Tile[y][x]
Tile[][] map = new Tile[][]{
    { ... }, // 2d array of tiles to represent map
};

Tile fromTile = map[0][0]; // must be a reference to a tile in map
Tile toTile = map[9][9];

Tile[] waypoints = AStar.buildPath( map, fromTile, toTile );

Speed

With 1000 iterations over a map of 100 X 100 tiles from one corner to the other, the pathfinding was an average of 1.42ms

How to develop

build

gradle build

test

gradle test