diff --git a/Trunk/MonoGameView/Algorithms/DFS.cs b/Trunk/MonoGameView/Algorithms/DFS.cs index b088ba9..36c952f 100644 --- a/Trunk/MonoGameView/Algorithms/DFS.cs +++ b/Trunk/MonoGameView/Algorithms/DFS.cs @@ -141,7 +141,7 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms Console.WriteLine(collector.HouseCounter); - if (collector.Counter> 100 || length > 100) + if (collector.Counter> 100 || length > 1000) return new KeyValuePair, int>(null,length); count++; if (Houses.All(c => (grid[c.X, c.Y] as IGarbageLocalization).TrashCans.All(j => j.FillPercent == 0.0)) diff --git a/Trunk/MonoGameView/DataModels/Interfaces/TrashCans/ATrashCan.cs b/Trunk/MonoGameView/DataModels/Interfaces/TrashCans/ATrashCan.cs index ea2a4c6..cb1c74f 100644 --- a/Trunk/MonoGameView/DataModels/Interfaces/TrashCans/ATrashCan.cs +++ b/Trunk/MonoGameView/DataModels/Interfaces/TrashCans/ATrashCan.cs @@ -30,17 +30,17 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans get { return ((double)Garbage.Volume) / this.MaxVolume; } } - public virtual void AddGarbage(AGarbage garbage) + public virtual bool AddGarbage(AGarbage garbage) { //if (this.TypeOfGarbage.GarbageType != garbage.TypeOfGarbage.GarbageType) // throw new Exception("You cannot add up different type garbage!"); var newGarbage = this.Garbage + garbage; - //if (newGarbage.Volume > this.MaxVolume) - // throw new Exception("Trash overload"); + if (newGarbage.Volume > this.MaxVolume) + return false; this.Garbage = newGarbage; - return; + return true; } public virtual object Clone() @@ -50,9 +50,9 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans public virtual AGarbage TakeGarbage() { - + if (this.Garbage.Weight == 0) - throw new Exception("Pusty śmietnik matole"); + return null; var result = (AGarbage)this.Garbage.Clone(); this.Garbage.Weight = 0; return result; diff --git a/Trunk/MonoGameView/DataModels/Models/Steps/CollectStep.cs b/Trunk/MonoGameView/DataModels/Models/Steps/CollectStep.cs index 8b89df3..73fd31a 100644 --- a/Trunk/MonoGameView/DataModels/Models/Steps/CollectStep.cs +++ b/Trunk/MonoGameView/DataModels/Models/Steps/CollectStep.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using CzokoŚmieciarka.MonoGameView.DataModels.Enums; using CzokoŚmieciarka.MonoGameView.DataModels.Exceptions; +using CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models; using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces; using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector; using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans; @@ -28,13 +29,15 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps var trashCans = _garbageLocalization.TrashCans.Where(t => t.TypeOfGarbage.GarbageType == _typeOfGarbage); if (!trashCans.Any()) return false; - var garbage = trashCans.Select(t => t.TakeGarbage()).Aggregate((a,b)=>a+b); + var preGarbage = trashCans.Select(t => t.TakeGarbage()).ToList(); + if (preGarbage.Any(x => x == null)) return false; + var garbage = preGarbage.Aggregate((a,b)=>a+b); if (_garbageCollector.TrashContainers.All(c => c.TypeOfGarbage.GarbageType != _typeOfGarbage)) return false; - _garbageCollector.TrashContainers.First(t => t.TypeOfGarbage.GarbageType == _typeOfGarbage).AddGarbage(garbage); - + var r = _garbageCollector.TrashContainers.First(t => t.TypeOfGarbage.GarbageType == _typeOfGarbage).AddGarbage(garbage); + if (!r) return false; for (int x= 0;x < grid.GetLength(0); x++){ for (int y = 0; y < grid.GetLength(1); y++) { diff --git a/Trunk/MonoGameView/DataModels/Models/Steps/SpillStep.cs b/Trunk/MonoGameView/DataModels/Models/Steps/SpillStep.cs index d6278df..f67d1c4 100644 --- a/Trunk/MonoGameView/DataModels/Models/Steps/SpillStep.cs +++ b/Trunk/MonoGameView/DataModels/Models/Steps/SpillStep.cs @@ -32,8 +32,10 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps var containers = _garbageCollector.TrashContainers.Where(t => t.TypeOfGarbage.GarbageType == _typeOfGarbage && t.FillPercent > 0); if (containers.Any()) { - var garbage = containers.Select(t => t.TakeGarbage()).Aggregate((a, b) => a + b); - _dump.AddGarbage(garbage); + var preGarbage = containers.Select(t => t.TakeGarbage()).ToList(); + if (preGarbage.Any(x => x == null)) return false; + var garbage = preGarbage.Aggregate((a, b) => a + b); + if (!_dump.AddGarbage(garbage)) return false; for (int x = 0; x < grid.GetLength(0); x++) { for (int y = 0; y < grid.GetLength(1); y++)