A* workin, broke the rest

This commit is contained in:
BOTLester 2020-05-03 17:06:03 +02:00
parent 6e4199eb47
commit dfbe50ee10
3 changed files with 18 additions and 6 deletions

View File

@ -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;
}

View File

@ -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--;
}
}

View File

@ -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();
}