world

package
v0.0.0-...-26a3925 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ROW int = 8
	COL int = 8
)
View Source
const (
	StateStart  string = "S" //开始点
	StateTarget string = "T" //目标点
	StateFlat   string = "." //平路
	StateBlock  string = "B" //障碍
	StatePath   string = "*" //路径点
)

Variables

View Source
var DirectOffset = [8][2]int{{0, 1}, {0, -1}, {-1, 0}, {1, 0}, {-1, 1}, {1, 1}, {-1, -1}, {1, -1}}

相邻格子偏移量 上,下,左,右,上左,上右,下左,下右

Functions

This section is empty.

Types

type Grid

type Grid struct {
	S string //状态
	X int    //坐标
	Y int    //坐标
	H int    //路径增量H值, 使用曼哈顿距离方法
}

格子

type Item

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

type PriorityQueue

type PriorityQueue []*Item

func (PriorityQueue) Len

func (pq PriorityQueue) Len() int

func (PriorityQueue) Less

func (pq PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() interface{}

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x interface{})

func (PriorityQueue) Swap

func (pq PriorityQueue) Swap(i, j int)

type World

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

数组第一维代表1行row

func (*World) CreatePQ

func (this *World) CreatePQ(gs []*Grid) *PriorityQueue

func (*World) Direct

func (this *World) Direct(from, to *Grid) (ret []*Grid)

定向的格子, 返回从from向to方向的格子(遇到边界或障碍物为止), 返回值不包括from和to

func (*World) FindStep

func (this *World) FindStep() (step []*Grid, find bool)

func (*World) LoadWorld

func (this *World) LoadWorld(world string) bool

func (*World) Neighbors

func (this *World) Neighbors(posX, posY int) []*Grid

func (*World) PQPop

func (this *World) PQPop(pq *PriorityQueue) *Grid

func (*World) Print

func (this *World) Print()

打印地图

func (*World) PrintInfo

func (this *World) PrintInfo()

打印格子坐标

func (*World) SetPathState

func (this *World) SetPathState(step []*Grid)

func (*World) SetStepState

func (this *World) SetStepState(step []*Grid)

func (*World) Stand

func (this *World) Stand() *Grid

func (*World) Straight

func (this *World) Straight(start, end *Grid, retPath bool) (path []*Grid, straight bool)

与目标点直连, path不包括首尾的中间点

func (*World) Target

func (this *World) Target() *Grid

func (*World) UpdateH

func (this *World) UpdateH(g *Grid)

更新距离目标点距离

Jump to

Keyboard shortcuts

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