From 3c7c3bbba589be88a46515e0dc9fabe2dd015b1e Mon Sep 17 00:00:00 2001 From: ryuga4 Date: Mon, 13 May 2019 18:15:48 +0200 Subject: [PATCH] lepszy dfs --- Trunk/MonoGameView/Algorithms/DFS.cs | 57 ++++++++++--------- .../GarbageCollector/AGarbageCollector.cs | 2 +- .../Interfaces/TrashCans/ATrashCan.cs | 2 +- .../DataModels/Models/BasicGarbage.cs | 8 +-- .../DataModels/Models/GarbageCollector.cs | 4 ++ 5 files changed, 39 insertions(+), 34 deletions(-) diff --git a/Trunk/MonoGameView/Algorithms/DFS.cs b/Trunk/MonoGameView/Algorithms/DFS.cs index 3da7696..fae9354 100644 --- a/Trunk/MonoGameView/Algorithms/DFS.cs +++ b/Trunk/MonoGameView/Algorithms/DFS.cs @@ -57,34 +57,6 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms var result = new List(); - if (!(collector.TrashContainers.Any(x => x.FillPercent > 0) && grid[collector.Coords.X,collector.Coords.Y] is ADump)) - { - 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() @@ -120,6 +92,34 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms } + } + if (!(collector.TrashContainers.Any(x => x.FillPercent > 0) && grid[collector.Coords.X,collector.Coords.Y] is ADump)) + { + 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; } @@ -129,6 +129,7 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms Thread.Sleep(100); this.Collector.Coords = collector.Coords; + this.Collector.TrashContainers = collector.TrashContainers; for (int x = 0; x < grid.GetLength(0); x++) { diff --git a/Trunk/MonoGameView/DataModels/Interfaces/GarbageCollector/AGarbageCollector.cs b/Trunk/MonoGameView/DataModels/Interfaces/GarbageCollector/AGarbageCollector.cs index 1531481..9914928 100644 --- a/Trunk/MonoGameView/DataModels/Interfaces/GarbageCollector/AGarbageCollector.cs +++ b/Trunk/MonoGameView/DataModels/Interfaces/GarbageCollector/AGarbageCollector.cs @@ -67,7 +67,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector } - public IEnumerable TrashContainers { get; } + public IEnumerable TrashContainers { get; set; } public virtual object Clone() { throw new NotImplementedException(); diff --git a/Trunk/MonoGameView/DataModels/Interfaces/TrashCans/ATrashCan.cs b/Trunk/MonoGameView/DataModels/Interfaces/TrashCans/ATrashCan.cs index cb1c74f..fc1b86c 100644 --- a/Trunk/MonoGameView/DataModels/Interfaces/TrashCans/ATrashCan.cs +++ b/Trunk/MonoGameView/DataModels/Interfaces/TrashCans/ATrashCan.cs @@ -10,7 +10,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans { this.MaxVolume = maxVolume; this.TypeOfGarbage = typeOfGarbage; - Garbage = new BasicGarbage(typeOfGarbage, 0); + Garbage = new BasicGarbage((TypeOfGarbage)typeOfGarbage, 0); } protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume, AGarbage garbage) { diff --git a/Trunk/MonoGameView/DataModels/Models/BasicGarbage.cs b/Trunk/MonoGameView/DataModels/Models/BasicGarbage.cs index bfae64f..f2041c1 100644 --- a/Trunk/MonoGameView/DataModels/Models/BasicGarbage.cs +++ b/Trunk/MonoGameView/DataModels/Models/BasicGarbage.cs @@ -6,26 +6,26 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models { public class BasicGarbage : AGarbage { - public BasicGarbage(ITypeOfGarbage typeOfGarbage, double weight) : base(typeOfGarbage, weight) + public BasicGarbage(TypeOfGarbage typeOfGarbage, double weight) : base(typeOfGarbage, weight) { } protected override AGarbage Add(AGarbage garbageToAdd) { - return new BasicGarbage(TypeOfGarbage, Weight + garbageToAdd.Weight); + return new BasicGarbage((TypeOfGarbage)TypeOfGarbage, Weight + garbageToAdd.Weight); } protected override AGarbage Subtract(AGarbage garbageToSubtract) { - return new BasicGarbage(TypeOfGarbage, Weight - garbageToSubtract.Weight); + return new BasicGarbage((TypeOfGarbage)TypeOfGarbage, Weight - garbageToSubtract.Weight); } public override object Clone() { - return new BasicGarbage((ITypeOfGarbage)TypeOfGarbage.Clone(), Weight); + return new BasicGarbage((TypeOfGarbage)TypeOfGarbage.Clone(), Weight); } } } diff --git a/Trunk/MonoGameView/DataModels/Models/GarbageCollector.cs b/Trunk/MonoGameView/DataModels/Models/GarbageCollector.cs index c8ffbd8..c3dd5bc 100644 --- a/Trunk/MonoGameView/DataModels/Models/GarbageCollector.cs +++ b/Trunk/MonoGameView/DataModels/Models/GarbageCollector.cs @@ -28,6 +28,10 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models public override object Clone() { + if (TrashContainers.Any(x=>x.FillPercent > 0)) + { + Console.WriteLine(); + } var cloneList = TrashContainers.Select(x=>(GarbageCollectorContainer)x.Clone()).ToList(); return new GarbageCollector((Coords)Coords.Clone(), cloneList, rows,columns, HouseCounter,Counter); }