From b66d57b27d422d13246f96d162f54e482eae2a56 Mon Sep 17 00:00:00 2001 From: ryuga4 Date: Wed, 22 May 2019 00:11:35 +0200 Subject: [PATCH] zapis stanow --- .../Algorithms/BestFirstSearch.cs | 36 +++++++++---------- Trunk/MonoGameView/Game1.cs | 4 +-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Trunk/MonoGameView/Algorithms/BestFirstSearch.cs b/Trunk/MonoGameView/Algorithms/BestFirstSearch.cs index f96e334..77aab5b 100644 --- a/Trunk/MonoGameView/Algorithms/BestFirstSearch.cs +++ b/Trunk/MonoGameView/Algorithms/BestFirstSearch.cs @@ -27,7 +27,7 @@ namespace MonoGameView.Algorithms int count; public List Houses { get; set; } public List Dumps { get; set; } - public List BestPath(ContentManager content, GarbageCollector collector, ICloneable[,] grid) + public Tuple,int,List> BestPath(ContentManager content, GarbageCollector collector, ICloneable[,] grid) { Houses = new List(); @@ -49,9 +49,9 @@ namespace MonoGameView.Algorithms - var r = SearchBestFirst(content, collector, grid, 0).Key; + var r = SearchBestFirst(content, collector, grid, 0); Console.WriteLine($"Counts : {count}"); - if (r == null) return new List(); + if (r == null) return new Tuple, int, List>(new List(), 0, new List()); return r; } @@ -135,7 +135,7 @@ namespace MonoGameView.Algorithms - int Priority (Tuple,GarbageCollector,ICloneable[,]> t) + int Priority (Tuple,List>,GarbageCollector,ICloneable[,]> t) { var inHouses = Houses .Aggregate(0.0, (a, b) => a + (t.Item3[b.X, b.Y] as IGarbageLocalization) @@ -189,15 +189,15 @@ namespace MonoGameView.Algorithms - KeyValuePair, int> SearchBestFirst(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length) + Tuple, int, List> SearchBestFirst(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length) { //Thread.Sleep(1); count = 0; - var nodes = new PriorityQueue, GarbageCollector, ICloneable[,]>>(); + var nodes = new PriorityQueue, List>, GarbageCollector, ICloneable[,]>>(); - var f = new Tuple, GarbageCollector, ICloneable[,]>(new List(), collector, grid); + var f = new Tuple, List>, GarbageCollector, ICloneable[,]>(new KeyValuePair, List>(new List(),new List() { grid }), collector, grid); nodes.Enqueue(f,Priority(f)); while (true) @@ -223,27 +223,27 @@ namespace MonoGameView.Algorithms item.Item2.TrashContainers.All(i => i.FillPercent == 0.0) ) { - return new KeyValuePair, int>(item.Item1, length); + return new Tuple, int, List>(item.Item1.Key, length, item.Item1.Value); } if (true)//item.Item2.Counter <= 12) { - foreach (var step in PossibleSteps(item.Item2, item.Item3)) - { - if (step is SpillStep) + foreach (var step in PossibleSteps(item.Item2, item.Item3)) + { + if (step is SpillStep) { Console.WriteLine(); } - var collectorClone = (GarbageCollector)item.Item2.Clone(); - var gridClone = CopyGrid(item.Item3); - step.Invoke(collectorClone, gridClone); + var collectorClone = (GarbageCollector)item.Item2.Clone(); + var gridClone = CopyGrid(item.Item3); + step.Invoke(collectorClone, gridClone); - var steps = new List(); - steps.AddRange(item.Item1); - steps.Add(step); - var f2 = new Tuple, GarbageCollector, ICloneable[,]>(steps, collectorClone, gridClone); + var steps = new List(); + steps.AddRange(item.Item1.Key); + steps.Add(step); + var f2 = new Tuple, List>, GarbageCollector, ICloneable[,]>(new KeyValuePair, List>(steps, item.Item1.Value.Concat(new List() {gridClone }).ToList()), collectorClone, gridClone); var f2P = Priority(f2); nodes.Enqueue(f2,Priority(f2)); diff --git a/Trunk/MonoGameView/Game1.cs b/Trunk/MonoGameView/Game1.cs index ebdd309..0605d85 100644 --- a/Trunk/MonoGameView/Game1.cs +++ b/Trunk/MonoGameView/Game1.cs @@ -93,9 +93,9 @@ namespace CzokoŚmieciarka.MonoGameView stepN = 0; - var dfs = new DFS(collector,grid); + var dfs = new BestFirstSearch(collector,grid); var r = dfs.BestPath(Content, collector, grid); - steps = r.Key; + steps = r.Item1; Console.WriteLine(r); //displayer.Add("Count", r.Value.ToString()); //new Thread(delegate() {