mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-09 01:56:47 -05:00
lint updates for /d2astar (#507)
This commit is contained in:
parent
0f9e846834
commit
5b26624cb8
@ -4,7 +4,6 @@ package d2astar
|
||||
// the sake of testing. This functionality forms the back end for
|
||||
// goreland_test.go, and serves as an example for how to use A* for a graph.
|
||||
|
||||
|
||||
// The Magical World of Goreland, is where Ted Stevens and Al Gore are from.
|
||||
//
|
||||
// It is composed of Big Trucks, and a Series of Tubes!
|
||||
@ -22,10 +21,12 @@ package d2astar
|
||||
// 1) They both use Manhattan distance as their heuristic
|
||||
// 2) Both implement Pather
|
||||
|
||||
//Goreland represents a world of trucks and tubes.
|
||||
type Goreland struct {
|
||||
// trucks map[int]*Truck // not needed really
|
||||
}
|
||||
|
||||
//Tube is an edge. They connect Trucks, and have a cost.
|
||||
type Tube struct {
|
||||
from *Truck
|
||||
to *Truck
|
||||
@ -39,7 +40,7 @@ type Truck struct {
|
||||
X, Y int
|
||||
|
||||
// array of tubes going to other trucks
|
||||
out_to []Tube
|
||||
outTo []Tube
|
||||
|
||||
label string
|
||||
}
|
||||
@ -49,8 +50,8 @@ func (t *Truck) PathNeighbors() []Pather {
|
||||
|
||||
neighbors := []Pather{}
|
||||
|
||||
for _, tube_element := range t.out_to {
|
||||
neighbors = append(neighbors, Pather(tube_element.to))
|
||||
for _, tubeElement := range t.outTo {
|
||||
neighbors = append(neighbors, Pather(tubeElement.to))
|
||||
}
|
||||
return neighbors
|
||||
}
|
||||
@ -58,9 +59,9 @@ func (t *Truck) PathNeighbors() []Pather {
|
||||
// PathNeighborCost returns the cost of the tube leading to Truck.
|
||||
func (t *Truck) PathNeighborCost(to Pather) float64 {
|
||||
|
||||
for _, tube_element := range (t).out_to {
|
||||
if Pather((tube_element.to)) == to {
|
||||
return tube_element.Cost
|
||||
for _, tubeElement := range (t).outTo {
|
||||
if Pather((tubeElement.to)) == to {
|
||||
return tubeElement.Cost
|
||||
}
|
||||
}
|
||||
return 10000000
|
||||
|
@ -19,8 +19,8 @@ func AddTube(t1, t2 *Truck, cost float64) *Tube {
|
||||
tube1.from = t1
|
||||
tube1.to = t2
|
||||
|
||||
t1.out_to = append(t1.out_to, *tube1)
|
||||
t2.out_to = append(t2.out_to, *tube1)
|
||||
t1.outTo = append(t1.outTo, *tube1)
|
||||
t2.outTo = append(t2.outTo, *tube1)
|
||||
|
||||
return tube1
|
||||
}
|
||||
@ -49,21 +49,21 @@ func AddTube(t1, t2 *Truck, cost float64) *Tube {
|
||||
// Solver should avoid the plugged tube.
|
||||
// Expect solution Start,Middle,End Total cost: 2.0
|
||||
|
||||
func createGorelandGraphPath_Diagonal(t *testing.T, diagonal_cost float64, expectedDist float64) {
|
||||
func createGorelandGraphPathDiagonal(t *testing.T, diagonalCost float64, expectedDist float64) {
|
||||
|
||||
world := new(Goreland)
|
||||
|
||||
tr_start := AddTruck(0, 0, "Start")
|
||||
tr_mid := AddTruck(0, 1, "Middle")
|
||||
tr_end := AddTruck(1, 1, "End")
|
||||
trStart := AddTruck(0, 0, "Start")
|
||||
trMid := AddTruck(0, 1, "Middle")
|
||||
trEnd := AddTruck(1, 1, "End")
|
||||
|
||||
AddTube(tr_start, tr_end, diagonal_cost)
|
||||
AddTube(tr_start, tr_mid, 1)
|
||||
AddTube(tr_mid, tr_end, 1)
|
||||
AddTube(trStart, trEnd, diagonalCost)
|
||||
AddTube(trStart, trMid, 1)
|
||||
AddTube(trMid, trEnd, 1)
|
||||
|
||||
t.Logf("Goreland. Diagonal cost: %v\n\n", diagonal_cost)
|
||||
t.Logf("Goreland. Diagonal cost: %v\n\n", diagonalCost)
|
||||
|
||||
p, dist, found := Path(tr_start, tr_end, math.MaxFloat64)
|
||||
p, dist, found := Path(trStart, trEnd, math.MaxFloat64)
|
||||
|
||||
if !found {
|
||||
t.Log("Could not find a path")
|
||||
@ -79,8 +79,8 @@ func createGorelandGraphPath_Diagonal(t *testing.T, diagonal_cost float64, expec
|
||||
}
|
||||
|
||||
func TestGraphPaths_ShortDiagonal(t *testing.T) {
|
||||
createGorelandGraphPath_Diagonal(t, 1.9, 1.9)
|
||||
createGorelandGraphPathDiagonal(t, 1.9, 1.9)
|
||||
}
|
||||
func TestGraphPaths_LongDiagonal(t *testing.T) {
|
||||
createGorelandGraphPath_Diagonal(t, 10000, 2.0)
|
||||
createGorelandGraphPathDiagonal(t, 10000, 2.0)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user