Fixed closed list to compare string values
This commit is contained in:
@@ -8,7 +8,7 @@ public class Pathfinder
|
|||||||
{
|
{
|
||||||
|
|
||||||
// used to store all unique states that agent has visited (holds agent and sample coords)
|
// used to store all unique states that agent has visited (holds agent and sample coords)
|
||||||
public static HashSet<State> closed = new HashSet<State>();
|
public static HashSet<string> closed = new HashSet<string>();
|
||||||
|
|
||||||
LogicGrid world;
|
LogicGrid world;
|
||||||
public Vector2Int agent;
|
public Vector2Int agent;
|
||||||
@@ -26,7 +26,7 @@ public class Pathfinder
|
|||||||
|
|
||||||
public Pathfinder(LogicGrid world, Vector2Int a, HashSet<Vector2Int> o, HashSet<Vector2Int> s, int algo, int heu)
|
public Pathfinder(LogicGrid world, Vector2Int a, HashSet<Vector2Int> o, HashSet<Vector2Int> s, int algo, int heu)
|
||||||
{
|
{
|
||||||
closed = new HashSet<State>();
|
closed = new HashSet<string>();
|
||||||
|
|
||||||
this.world = world;
|
this.world = world;
|
||||||
height = world.GetHeight();
|
height = world.GetHeight();
|
||||||
@@ -299,7 +299,7 @@ public class Node
|
|||||||
Vector2Int onSample = new Vector2Int();
|
Vector2Int onSample = new Vector2Int();
|
||||||
|
|
||||||
// since this state is being currently visited (expanded), put in closed list
|
// since this state is being currently visited (expanded), put in closed list
|
||||||
Pathfinder.closed.Add(this.getState());
|
Pathfinder.closed.Add(this.getStateString());
|
||||||
|
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
// BEGIN CHECKING FOR VALID MOVES //
|
// BEGIN CHECKING FOR VALID MOVES //
|
||||||
@@ -319,7 +319,7 @@ public class Node
|
|||||||
//SampleWorld.nodesGenerated++;
|
//SampleWorld.nodesGenerated++;
|
||||||
|
|
||||||
// make sure that we have not already made that move
|
// make sure that we have not already made that move
|
||||||
if (!Pathfinder.closed.Contains(child.getState()))
|
if (!Pathfinder.closed.Contains(child.getStateString()))
|
||||||
children.Add(child);
|
children.Add(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,7 +329,7 @@ public class Node
|
|||||||
Node child = new Node(this, down, this.obstacles, this.samples, 'D', this.distanceTraveled + 1, this.heuristic);
|
Node child = new Node(this, down, this.obstacles, this.samples, 'D', this.distanceTraveled + 1, this.heuristic);
|
||||||
//SampleWorld.nodesGenerated++;
|
//SampleWorld.nodesGenerated++;
|
||||||
|
|
||||||
if (!Pathfinder.closed.Contains(child.getState()))
|
if (!Pathfinder.closed.Contains(child.getStateString()))
|
||||||
children.Add(child);
|
children.Add(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,7 +338,7 @@ public class Node
|
|||||||
Node child = new Node(this, left, this.obstacles, this.samples, 'L', this.distanceTraveled + 1, this.heuristic);
|
Node child = new Node(this, left, this.obstacles, this.samples, 'L', this.distanceTraveled + 1, this.heuristic);
|
||||||
//SampleWorld.nodesGenerated++;
|
//SampleWorld.nodesGenerated++;
|
||||||
|
|
||||||
if (!Pathfinder.closed.Contains(child.getState()))
|
if (!Pathfinder.closed.Contains(child.getStateString()))
|
||||||
children.Add(child);
|
children.Add(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,7 +347,7 @@ public class Node
|
|||||||
Node child = new Node(this, right, this.obstacles, this.samples, 'R', this.distanceTraveled + 1, this.heuristic);
|
Node child = new Node(this, right, this.obstacles, this.samples, 'R', this.distanceTraveled + 1, this.heuristic);
|
||||||
//SampleWorld.nodesGenerated++;
|
//SampleWorld.nodesGenerated++;
|
||||||
|
|
||||||
if (!Pathfinder.closed.Contains(child.getState()))
|
if (!Pathfinder.closed.Contains(child.getStateString()))
|
||||||
children.Add(child);
|
children.Add(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ public class nMain : MonoBehaviour
|
|||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
// Create world
|
// Create world
|
||||||
int width = 16;
|
int width = 32;
|
||||||
int height = 8;
|
int height = 16;
|
||||||
float cellSize = 10f;
|
float cellSize = 5f;
|
||||||
Vector3 origin = new Vector3(-77, -34);
|
Vector3 origin = new Vector3(-77, -34);
|
||||||
|
|
||||||
world = new LogicGrid(width, height, cellSize, origin);
|
world = new LogicGrid(width, height, cellSize, origin);
|
||||||
|
|||||||
Reference in New Issue
Block a user