From e1b4dec7649ea89c897e11a11207c303080bdc99 Mon Sep 17 00:00:00 2001 From: BOTLester <58360400+BOTLester@users.noreply.github.com> Date: Fri, 8 May 2020 00:35:53 +0200 Subject: [PATCH] Damn it works --- Game1/Sources/Pathing/A-Star/Astar.cs | 2 +- Game1/Sources/Smart/AI.cs | 50 ++++++++++++++++++++------- Game1/Sources/Smart/SmartTractor.cs | 1 - 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/Game1/Sources/Pathing/A-Star/Astar.cs b/Game1/Sources/Pathing/A-Star/Astar.cs index 4d92e25..f84c936 100644 --- a/Game1/Sources/Pathing/A-Star/Astar.cs +++ b/Game1/Sources/Pathing/A-Star/Astar.cs @@ -41,7 +41,7 @@ class Astar } // Get all adjacent nodes - private List GetAdjacentNodes(Vector2 currentPos) + public List GetAdjacentNodes(Vector2 currentPos) { var adjacentNodes = new List() diff --git a/Game1/Sources/Smart/AI.cs b/Game1/Sources/Smart/AI.cs index f6b9051..a168f10 100644 --- a/Game1/Sources/Smart/AI.cs +++ b/Game1/Sources/Smart/AI.cs @@ -59,25 +59,49 @@ class AI { PriorityQueueC5 queue = new PriorityQueueC5(); int score = 0; + int count = 0; + int testsize = 2; Vector2 newTarget; - 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)) + while (true) + { + for (int x = 0; x < Size.X; x++) + 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 - } - else - { - score = calculateSoilScore(x, y); - queue.AddToQueue(x, y, score); + 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; - newTarget = GetMinFNode(5, queue); + /* + else if (tractorPos == housePos) + { + List temp = astar.GetAdjacentNodes(tractorPos); + return temp[0].getCords(); + } + */ + } + + newTarget = GetMinFNode(Math.Min(testsize, count), queue); return newTarget; } diff --git a/Game1/Sources/Smart/SmartTractor.cs b/Game1/Sources/Smart/SmartTractor.cs index 6cdbfbc..29fdf50 100644 --- a/Game1/Sources/Smart/SmartTractor.cs +++ b/Game1/Sources/Smart/SmartTractor.cs @@ -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); }