From c3b0d5f60932e5be391265ba4d0b05de96be8319 Mon Sep 17 00:00:00 2001 From: ryuga4 Date: Mon, 13 May 2019 18:27:49 +0200 Subject: [PATCH] poprawiony bfs --- Trunk/MonoGameView/Algorithms/BFS.cs | 60 +++++++++++----------- Trunk/MonoGameView/Algorithms/DFS.cs | 2 +- Trunk/MonoGameView/DataModels/MapLoader.cs | 2 +- Trunk/MonoGameView/Game1.cs | 2 +- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/Trunk/MonoGameView/Algorithms/BFS.cs b/Trunk/MonoGameView/Algorithms/BFS.cs index 3a59fb2..93b3f81 100644 --- a/Trunk/MonoGameView/Algorithms/BFS.cs +++ b/Trunk/MonoGameView/Algorithms/BFS.cs @@ -56,34 +56,7 @@ namespace MonoGameView.Algorithms var result = new List(); var itemdupa = grid[collector.Coords.X, collector.Coords.Y]; - if (!(itemdupa is House && collector.TrashContainers.All(i=>i.FillPercent==0))) - { - var moveSteps = new List() - { - new MoveStep(Direction.Up), - new MoveStep(Direction.Down), - new MoveStep(Direction.Left), - new MoveStep(Direction.Right) - }; - var filteredMoveSteps = new List(); - foreach (var item in moveSteps) - { - var copyCollector = (AGarbageCollector)collector.Clone(); - if (item.Invoke(copyCollector, grid)) - { - var gcx = copyCollector.Coords.X; - var gcy = copyCollector.Coords.Y; - if (grid[gcx, gcy] is Road1 || grid[gcx, gcy] is House || (grid[gcx, gcy] is ADump && copyCollector.TrashContainers.Any(x => x.FillPercent > 0))) - { - result.Add(item); - } - } - - - } - - - } + if (grid[collector.Coords.X, collector.Coords.Y] is House) { var collectSteps = new List() @@ -119,6 +92,34 @@ namespace MonoGameView.Algorithms } + } + if (!(itemdupa is House && collector.TrashContainers.All(i=>i.FillPercent==0))) + { + var moveSteps = new List() + { + new MoveStep(Direction.Up), + new MoveStep(Direction.Down), + new MoveStep(Direction.Left), + new MoveStep(Direction.Right) + }; + var filteredMoveSteps = new List(); + foreach (var item in moveSteps) + { + var copyCollector = (AGarbageCollector)collector.Clone(); + if (item.Invoke(copyCollector, grid)) + { + var gcx = copyCollector.Coords.X; + var gcy = copyCollector.Coords.Y; + if (grid[gcx, gcy] is Road1 || grid[gcx, gcy] is House || (grid[gcx, gcy] is ADump && copyCollector.TrashContainers.Any(x => x.FillPercent > 0))) + { + result.Add(item); + } + } + + + } + + } return result; } @@ -141,8 +142,9 @@ namespace MonoGameView.Algorithms var nodes2 = new List, GarbageCollector, ICloneable[,]>>(); foreach (var item in nodes) { - // Thread.Sleep(100); + //Thread.Sleep(1); this.Collector.Coords = item.Item2.Coords; + this.Collector.TrashContainers = item.Item2.TrashContainers; for (int x = 0; x < item.Item3.GetLength(0); x++) { for (int y = 0; y < item.Item3.GetLength(1); y++) diff --git a/Trunk/MonoGameView/Algorithms/DFS.cs b/Trunk/MonoGameView/Algorithms/DFS.cs index fae9354..b6496bb 100644 --- a/Trunk/MonoGameView/Algorithms/DFS.cs +++ b/Trunk/MonoGameView/Algorithms/DFS.cs @@ -127,7 +127,7 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms KeyValuePair, int> Search(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length) { - Thread.Sleep(100); + Thread.Sleep(10); this.Collector.Coords = collector.Coords; this.Collector.TrashContainers = collector.TrashContainers; diff --git a/Trunk/MonoGameView/DataModels/MapLoader.cs b/Trunk/MonoGameView/DataModels/MapLoader.cs index 581d885..50050b9 100644 --- a/Trunk/MonoGameView/DataModels/MapLoader.cs +++ b/Trunk/MonoGameView/DataModels/MapLoader.cs @@ -105,7 +105,7 @@ namespace MonoGameView.DataModels int processingTimePerUnit = Convert.ToInt32(garbageNode.SelectSingleNode("ProcessingTimePerUnit").InnerText); int maxVolume = Convert.ToInt32(objectNode.SelectSingleNode("Volume").InnerText); typeOfGarbage = new TypeOfGarbage(garbageType, density, processingTimePerUnit); - Dump dump = new Dump(typeOfGarbage, maxVolume, new Coords(x, y)); + Dump dump = new Dump(typeOfGarbage, int.MaxValue, new Coords(x, y)); grid[x, y] = dump; break; } diff --git a/Trunk/MonoGameView/Game1.cs b/Trunk/MonoGameView/Game1.cs index 7ff4d39..87cf0b6 100644 --- a/Trunk/MonoGameView/Game1.cs +++ b/Trunk/MonoGameView/Game1.cs @@ -93,7 +93,7 @@ namespace CzokoŚmieciarka.MonoGameView stepN = 0; - var dfs = new DFS(collector,grid); + var dfs = new BFS(collector,grid); //steps = dfs.BestPath(Content, collector, grid); new Thread(delegate() { var x = dfs.BestPath(Content, collector, grid);