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