still doesnt work
This commit is contained in:
parent
dfbe50ee10
commit
8db46409f1
@ -67,6 +67,7 @@ class Astar
|
|||||||
Path path = new Path();
|
Path path = new Path();
|
||||||
PriorityQueue openList = new PriorityQueue();
|
PriorityQueue openList = new PriorityQueue();
|
||||||
PriorityQueue closedList = new PriorityQueue();
|
PriorityQueue closedList = new PriorityQueue();
|
||||||
|
Nodes target = new Nodes(targetPos);
|
||||||
Nodes startPos = new Nodes (tractorPos);
|
Nodes startPos = new Nodes (tractorPos);
|
||||||
Nodes current = null;
|
Nodes current = null;
|
||||||
int g = 0;
|
int g = 0;
|
||||||
@ -79,7 +80,7 @@ class Astar
|
|||||||
closedList.Enqueue(current);
|
closedList.Enqueue(current);
|
||||||
openList.Dequeue();
|
openList.Dequeue();
|
||||||
|
|
||||||
if (closedList.Peek().getCords() == targetPos)
|
if (closedList.Peek().getCords() == target.getCords())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
var adjacentNodes = GetAdjacentNodes(current.getCords());
|
var adjacentNodes = GetAdjacentNodes(current.getCords());
|
||||||
@ -92,7 +93,7 @@ class Astar
|
|||||||
if (!(openList.Exists(adjacentNode.getCords())))
|
if (!(openList.Exists(adjacentNode.getCords())))
|
||||||
{
|
{
|
||||||
adjacentNode.setG(g);
|
adjacentNode.setG(g);
|
||||||
adjacentNode.setH(ComputeHScore(adjacentNode.getCords(), targetPos));
|
adjacentNode.setH(ComputeHScore(adjacentNode.getCords(), target.getCords()));
|
||||||
adjacentNode.calculateF();
|
adjacentNode.calculateF();
|
||||||
adjacentNode.setParent(current);
|
adjacentNode.setParent(current);
|
||||||
openList.Enqueue(adjacentNode);
|
openList.Enqueue(adjacentNode);
|
||||||
@ -109,7 +110,7 @@ class Astar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (current.getParent() != null)
|
while (current != null)
|
||||||
{
|
{
|
||||||
path.AddNode(current);
|
path.AddNode(current);
|
||||||
current = current.getParent();
|
current = current.getParent();
|
||||||
|
@ -41,8 +41,9 @@ class PriorityQueue
|
|||||||
{
|
{
|
||||||
Nodes min = Peek();
|
Nodes min = Peek();
|
||||||
Nodes root = list[Count - 1];
|
Nodes root = list[Count - 1];
|
||||||
list.RemoveAt(Count - 1);
|
list.RemoveAt(0);
|
||||||
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i * 2 + 1 < Count)
|
while (i * 2 + 1 < Count)
|
||||||
{
|
{
|
||||||
@ -56,6 +57,7 @@ class PriorityQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Count > 0) list[i] = root;
|
if (Count > 0) list[i] = root;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Nodes Peek()
|
public Nodes Peek()
|
||||||
|
@ -20,7 +20,6 @@ class SmartTractor
|
|||||||
//What to do next
|
//What to do next
|
||||||
public Path returnChoice(int task)
|
public Path returnChoice(int task)
|
||||||
{
|
{
|
||||||
astar.update(crops, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target);
|
|
||||||
if (task == 0)
|
if (task == 0)
|
||||||
{
|
{
|
||||||
//To the house
|
//To the house
|
||||||
@ -31,6 +30,7 @@ class SmartTractor
|
|||||||
//To the fields
|
//To the fields
|
||||||
getTargetPosition(r.Next(0, (int)Size.X), r.Next(0, (int)Size.Y));
|
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();
|
//astar.FindPath();
|
||||||
return astar.FindPath();
|
return astar.FindPath();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user