forked from s425077/PotatoPlan
Damn it works
This commit is contained in:
parent
3e034cf958
commit
e1b4dec764
@ -41,7 +41,7 @@ class Astar
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get all adjacent nodes
|
// Get all adjacent nodes
|
||||||
private List<Nodes> GetAdjacentNodes(Vector2 currentPos)
|
public List<Nodes> GetAdjacentNodes(Vector2 currentPos)
|
||||||
{
|
{
|
||||||
var adjacentNodes = new List<Nodes>()
|
var adjacentNodes = new List<Nodes>()
|
||||||
|
|
||||||
|
@ -59,25 +59,49 @@ class AI
|
|||||||
{
|
{
|
||||||
PriorityQueueC5 queue = new PriorityQueueC5();
|
PriorityQueueC5 queue = new PriorityQueueC5();
|
||||||
int score = 0;
|
int score = 0;
|
||||||
|
int count = 0;
|
||||||
|
int testsize = 2;
|
||||||
Vector2 newTarget;
|
Vector2 newTarget;
|
||||||
for (int x = 0; x < Size.X; x++)
|
while (true)
|
||||||
for (int y = 0; y < Size.Y; y++)
|
{
|
||||||
{
|
for (int x = 0; x < Size.X; x++)
|
||||||
if (farm.getCrop(x, y).getStatus() >= 2 && tractorPos != new Vector2(x, y))
|
for (int y = 0; y < Size.Y; y++)
|
||||||
{
|
{
|
||||||
if (farm.getCrop(x, y).getStatus() == 4 && farm.getCrop(x, y).getCropTimer() != 1)
|
if (farm.getCrop(x, y).getStatus() >= 2 && tractorPos != new Vector2(x, y))
|
||||||
{
|
{
|
||||||
//do nothing
|
if (farm.getCrop(x, y).getStatus() == 3 && farm.getCrop(x, y).getCropTimer() != 1)
|
||||||
}
|
{
|
||||||
else
|
if (housePos == tractorPos)
|
||||||
{
|
{
|
||||||
score = calculateSoilScore(x, y);
|
score = calculateSoilScore(x, y);
|
||||||
queue.AddToQueue(x, y, score);
|
queue.AddToQueue(x, y, score);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
score = calculateSoilScore(x, y);
|
||||||
|
queue.AddToQueue(x, y, score);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (count > 0)
|
||||||
|
break;
|
||||||
|
else if (tractorPos != housePos)
|
||||||
|
return housePos;
|
||||||
|
|
||||||
newTarget = GetMinFNode(5, queue);
|
/*
|
||||||
|
else if (tractorPos == housePos)
|
||||||
|
{
|
||||||
|
List<Nodes> temp = astar.GetAdjacentNodes(tractorPos);
|
||||||
|
return temp[0].getCords();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
newTarget = GetMinFNode(Math.Min(testsize, count), queue);
|
||||||
return newTarget;
|
return newTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ class SmartTractor
|
|||||||
getTargetPosition(ai.newTarget());
|
getTargetPosition(ai.newTarget());
|
||||||
astar.update(farm.getCrops(), Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target / (tileSize + Spacing), Rotation);
|
astar.update(farm.getCrops(), Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target / (tileSize + Spacing), Rotation);
|
||||||
|
|
||||||
|
|
||||||
return astar.FindPath(true);
|
return astar.FindPath(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user