diff --git a/Game1/Sources/Pathing/A-Star/Astar.cs b/Game1/Sources/Pathing/A-Star/Astar.cs index 2dff97c..e046110 100644 --- a/Game1/Sources/Pathing/A-Star/Astar.cs +++ b/Game1/Sources/Pathing/A-Star/Astar.cs @@ -41,10 +41,22 @@ class Astar new Nodes(new Vector2(currentPos.X - 1, currentPos.Y)), }; + for (int i = 3; i >=0; i--) + { + if (adjacentNodes[i].getCords().X < 0 || adjacentNodes[i].getCords().Y < 0) + adjacentNodes.Remove(adjacentNodes[i]); + else + { + if (adjacentNodes[i].getCords().X > Size.X || adjacentNodes[i].getCords().Y > Size.Y) + adjacentNodes.Remove(adjacentNodes[i]); + } + } + return adjacentNodes.Where( item => crops[(int)item.getCords().X, (int)item.getCords().Y].Status != 0).ToList(); } + public int ComputeHScore(Vector2 currentNode, Vector2 endNote) { return (int)(Math.Abs(endNote.X - currentNode.X) + Math.Abs(endNote.Y - currentNode.Y)); @@ -52,7 +64,7 @@ class Astar public Path FindPath() { - Path path = null; + Path path = new Path(); PriorityQueue openList = new PriorityQueue(); PriorityQueue closedList = new PriorityQueue(); Nodes startPos = new Nodes (tractorPos); @@ -102,7 +114,7 @@ class Astar path.AddNode(current); current = current.getParent(); } - + path.FlipArray(); return path; } diff --git a/Game1/Sources/Pathing/A-Star/PathSaver/Path.cs b/Game1/Sources/Pathing/A-Star/PathSaver/Path.cs index 86e17f7..a0befcb 100644 --- a/Game1/Sources/Pathing/A-Star/PathSaver/Path.cs +++ b/Game1/Sources/Pathing/A-Star/PathSaver/Path.cs @@ -34,10 +34,10 @@ class Path public void FlipArray() { int j = Count; - Nodes[] temp = nodes; + Nodes[] tempp = nodes; for (int i = 0; i < Count; i++) { - nodes[i] = temp[j]; + nodes[i] = tempp[j - 1]; j--; } } diff --git a/Game1/Sources/Smart/SmartTractor.cs b/Game1/Sources/Smart/SmartTractor.cs index 690571f..5046641 100644 --- a/Game1/Sources/Smart/SmartTractor.cs +++ b/Game1/Sources/Smart/SmartTractor.cs @@ -31,8 +31,8 @@ class SmartTractor //To the fields getTargetPosition(r.Next(0, (int)Size.X), r.Next(0, (int)Size.Y)); } - astar.FindPath(); - return path; + //astar.FindPath(); + return astar.FindPath(); }