goeasystar

package module
v0.0.0-...-eebb5d4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2015 License: MIT Imports: 4 Imported by: 1

README

goeasystar

A port of EasyStar.js to the Go programming language.

##Installation

go get github.com/prettymuchbryce/goeasystar

##Documentation GoDoc

API

Main Methods
easystar := goeasystar.NewPathfinder()
easystar.SetGrid(grid [][]int)
easystar.SetAcceptableTiles(t []int)`
easystar.FindPath(startX, startY, endX, endY) ([]*goeasystar.Point, error)
Additional Features
  • Avoiding additional points (outside of acceptable tiles)

  • Diagonals

  • Corner cutting

  • Setting costs per-tile

  • Setting additional point costs (outside of tile costs)

Usage

First create an instance of the Pathfinder.

easystar := NewPathfinder()

Create a grid, or tilemap. You may have made this with a level editor, or procedurally. Let's keep it simple for this example.

var grid [][]int
grid = append(grid, []int{1, 0, 0, 0, 0})
grid = append(grid, []int{0, 1, 0, 0, 0})
grid = append(grid, []int{0, 0, 1, 0, 0})
grid = append(grid, []int{0, 0, 0, 1, 0})
grid = append(grid, []int{0, 0, 0, 0, 1})

Set our grid.

easystar.SetGrid(grid)

Set tiles which are "walkable".

easystar.SetAcceptableTiles([]int{1})

Find a path.

path, err := easystar.FindPath(0, 0, 4, 4)
fmt.Println(err == nil) // false

Oops. We didn't have diagonals enabled so there is no valid path. Lets try again.

easystar.EnableDiagonals()
path, err := easystar.FindPath(0, 0, 4, 4)
fmt.Println(err) // nil
len(path) // 4

License

goeasystar is licensed under the MIT license.

goeasystar uses facebookgo's pqueue which falls under the Apache 2 License.

I would be happy to eventually remove it in favor of an MIT-licensed priority queue implementation.

Support

If you have any questions, comments, or suggestions please open an issue.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pathfinder

type Pathfinder struct {
	// contains filtered or unexported fields
}

Pathfinder represents a single instance of a pathfinding configuration

func NewPathfinder

func NewPathfinder() *Pathfinder

NewPathfinder returns a new instance of a pathfinder

func (*Pathfinder) AvoidAdditionalPoint

func (p *Pathfinder) AvoidAdditionalPoint(x int, y int)

AvoidAdditionalPoint avoids a particular point on the grid regardless of whether or not it is an acceptable tile

func (*Pathfinder) DisableCornerCutting

func (p *Pathfinder) DisableCornerCutting()

DisableCornerCutting disables corner cutting in diagonal movement

func (*Pathfinder) DisableDiagonals

func (p *Pathfinder) DisableDiagonals()

DisableDiagonals disables diagonals on the Pathfinder

func (*Pathfinder) EnableCornerCutting

func (p *Pathfinder) EnableCornerCutting()

EnableCornerCutting enables corner cutting in diagonal movement

func (*Pathfinder) EnableDiagonals

func (p *Pathfinder) EnableDiagonals()

EnableDiagonals enables diagonals on the Pathfinder

func (*Pathfinder) FindPath

func (p *Pathfinder) FindPath(startX int, startY int, endX int, endY int) ([]*Point, error)

FindPath finds a path Returns a slice of points which consists the starting point up to the end point inclusively

func (*Pathfinder) RemoveAdditionalPointCost

func (p *Pathfinder) RemoveAdditionalPointCost(x int, y int)

RemoveAdditionalPointCost removes the additional cost for a particular point

func (*Pathfinder) RemoveAllAdditionalPointCosts

func (p *Pathfinder) RemoveAllAdditionalPointCosts()

RemoveAllAdditionalPointCosts removes all additional point costs

func (*Pathfinder) SetAcceptableTiles

func (p *Pathfinder) SetAcceptableTiles(t []int)

SetAcceptableTiles sets a list of tiles which are deemed acceptable to pass through

func (*Pathfinder) SetAdditionalPointCost

func (p *Pathfinder) SetAdditionalPointCost(x int, y int, cost float64)

SetAdditionalPointCost sets the an additional cost for a particular point Overrides the cost from SetTileCost

func (*Pathfinder) SetGrid

func (p *Pathfinder) SetGrid(grid [][]int)

SetGrid sets the grid of the Pathfinder

func (*Pathfinder) StopAvoidingAdditionalPoint

func (p *Pathfinder) StopAvoidingAdditionalPoint(x int, y int)

StopAvoidingAdditionalPoint stops avoiding a particular point on the grid

func (*Pathfinder) StopAvoidingAllAdditionalPoints

func (p *Pathfinder) StopAvoidingAllAdditionalPoints()

StopAvoidingAllAdditionalPoints stops avoiding all additional points on the grid

type Point

type Point struct {
	X int
	Y int
}

Point represents a point in the completed path

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL