still doesnt work

This commit is contained in:
BOTLester 2020-05-03 17:52:35 +02:00
parent dfbe50ee10
commit 8db46409f1
3 changed files with 8 additions and 5 deletions

View File

@ -67,6 +67,7 @@ class Astar
Path path = new Path();
PriorityQueue openList = new PriorityQueue();
PriorityQueue closedList = new PriorityQueue();
Nodes target = new Nodes(targetPos);
Nodes startPos = new Nodes (tractorPos);
Nodes current = null;
int g = 0;
@ -79,7 +80,7 @@ class Astar
closedList.Enqueue(current);
openList.Dequeue();
if (closedList.Peek().getCords() == targetPos)
if (closedList.Peek().getCords() == target.getCords())
break;
var adjacentNodes = GetAdjacentNodes(current.getCords());
@ -92,7 +93,7 @@ class Astar
if (!(openList.Exists(adjacentNode.getCords())))
{
adjacentNode.setG(g);
adjacentNode.setH(ComputeHScore(adjacentNode.getCords(), targetPos));
adjacentNode.setH(ComputeHScore(adjacentNode.getCords(), target.getCords()));
adjacentNode.calculateF();
adjacentNode.setParent(current);
openList.Enqueue(adjacentNode);
@ -109,7 +110,7 @@ class Astar
}
}
while (current.getParent() != null)
while (current != null)
{
path.AddNode(current);
current = current.getParent();

View File

@ -41,8 +41,9 @@ class PriorityQueue
{
Nodes min = Peek();
Nodes root = list[Count - 1];
list.RemoveAt(Count - 1);
list.RemoveAt(0);
int i = 0;
while (i * 2 + 1 < Count)
{
@ -56,6 +57,7 @@ class PriorityQueue
}
if (Count > 0) list[i] = root;
}
public Nodes Peek()

View File

@ -20,7 +20,6 @@ class SmartTractor
//What to do next
public Path returnChoice(int task)
{
astar.update(crops, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target);
if (task == 0)
{
//To the house
@ -31,6 +30,7 @@ class SmartTractor
//To the fields
getTargetPosition(r.Next(0, (int)Size.X), r.Next(0, (int)Size.Y));
}
astar.update(crops, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target/(tileSize+Spacing));
//astar.FindPath();
return astar.FindPath();
}