astar

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 5 Imported by: 0

README

astar

四边形网格和六边形网格的A*寻路算法。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Astar

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

func New

func New(opts ...Option) *Astar

New 新建寻路对象。

func (*Astar) Ctx

func (a *Astar) Ctx() context.Context

Ctx 上下文。

func (*Astar) FindPath

func (a *Astar) FindPath(start, end *Tile) []*Tile

FindPath 寻找路径。

func (*Astar) Mode

func (a *Astar) Mode() VectorMode

Mode 向量模式。

func (*Astar) Vector2H

func (a *Astar) Vector2H(start, end *Vector) int32

Vector2H H = |x1 – x2| + |y1 – y2|。

func (*Astar) Vector3H

func (a *Astar) Vector3H(start, end *Vector) int32

Vector3H H = Max(|x1 – x2|, |y1 – y2|, |z1 – z2|)。

type Option

type Option func(f *Astar)

func Context

func Context(ctx context.Context) Option

Context 设置上下文。

func Mode

func Mode(mode VectorMode) Option

Mode 设置向量模式。

type Tile

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

Tile 地格。

func NewTile

func NewTile(vector *Vector) *Tile

NewTile 新建地格。

func (*Tile) AddNearList

func (t *Tile) AddNearList(tile *Tile)

AddNearList 添加相邻地格。

func (*Tile) F

func (t *Tile) F() int32

F 是 g 和 h 的总和。

func (*Tile) IsObstacle

func (t *Tile) IsObstacle() bool

IsObstacle 是否阻挡?

func (*Tile) NearList

func (t *Tile) NearList() []*Tile

NearList 相邻地格列表。

func (*Tile) SetIsObstacle

func (t *Tile) SetIsObstacle(isObstacle bool)

SetIsObstacle 设置是否阻挡。

func (*Tile) Vector

func (t *Tile) Vector() *Vector

Vector 地格坐标。

type Vector

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

Vector 坐标。

func NewVector

func NewVector(x, y int32) *Vector

NewVector 新建坐标。

func (*Vector) X

func (v *Vector) X() int32

func (*Vector) Y

func (v *Vector) Y() int32

func (*Vector) Z

func (v *Vector) Z() int32

type VectorMode

type VectorMode int8
const (
	Vector2Mode VectorMode = iota + 1 // 二维模式
	Vector3Mode                       // 三维模式
)

Jump to

Keyboard shortcuts

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