Пример #1
0
func (p *Path) RouteTo(source Loc) *Path {

	astar_source := []astar.Point{
		astar.Point{
			Row: int(source.Row - p.row_off),
			Col: int(source.Col - p.col_off),
		},
	}

	path := p.aStar.FindPath(astar.NewListToPoint(true), p.astar_path, astar_source)

	return NewPath(p.aStar, path, p.row_off, p.col_off)
}
Пример #2
0
func main() {

	var start_t int64
	var end_t int64

	var seed int64 = 0

	// Setup the aStar structs
	ast := astar.NewAStar(50, 50)

	p2p := astar.NewPointToPoint()
	p2l := astar.NewListToPoint(true)

	// Generate a random map
	grid, source, target, me := GenerateRandomMap(ast, seed, 50, 600, 24, 100000)
	PrintGrid(grid)

	// Route from source to target (point to point)
	start_t = time.Now().UnixNano()
	end := ast.FindPath(p2p, source, target)
	end_t = time.Now().UnixNano()

	first_path_t := float64(end_t-start_t) / float64(time.Millisecond)

	DrawPath(grid, end, "*")
	PrintGrid(grid)

	// record path as array so it can be used in the next search
	p := end
	path := make([]astar.Point, 0)
	for p != nil {
		path = append(path, p.Point)
		p = p.Parent
	}

	start_t = time.Now().UnixNano()
	end = ast.FindPath(p2l, path, me)
	end_t = time.Now().UnixNano()
	second_path_t := float64(end_t-start_t) / float64(time.Millisecond)

	DrawPath(grid, end, ".")
	PrintGrid(grid)

	fmt.Println("me", me)
	fmt.Println("end", end)
	fmt.Println("end_grid", grid[end.Row][end.Col])
	fmt.Println(first_path_t)
	fmt.Println(second_path_t)
}