diff --git a/Trunk/Components/CzokoŚmieciarka.AI_Naive/RoutePlanningEngine.cs b/Trunk/Components/CzokoŚmieciarka.AI_Naive/RoutePlanningEngine.cs index b0fb894..0772fc3 100644 --- a/Trunk/Components/CzokoŚmieciarka.AI_Naive/RoutePlanningEngine.cs +++ b/Trunk/Components/CzokoŚmieciarka.AI_Naive/RoutePlanningEngine.cs @@ -16,26 +16,28 @@ namespace Czoko_Smieciarka.AI_Naive public IEnumerable Cans { get; } public IEnumerable Dumps { get; } + + enum State { TravelToDump, TravelToCan, Wait, Finish } public Coords Destination { get; set; } public object DestinationObject { get; set; } private State CurrentState { get; set; } - public IEnumerable CalculateStep() + public void PerformStep() { - return PerformMove(); + PerformMove(); } public RoutePlanningEngine(IGarbageCollector collector, IEnumerable cans, IEnumerable dumps) { - this.Collector = collector.Clone() as IGarbageCollector; + this.Collector = collector; this.Cans = cans; this.Dumps = dumps; this.CurrentState = State.Wait; } - private IEnumerable PerformMove() + private bool PerformMove() { switch (CurrentState) @@ -46,7 +48,6 @@ namespace Czoko_Smieciarka.AI_Naive var dump = (DestinationObject as ADump); var step = new SpillStep(Collector, dump, dump.TypeOfGarbage); step.Invoke(); - yield return step; this.CurrentState = State.Wait; } else @@ -58,7 +59,6 @@ namespace Czoko_Smieciarka.AI_Naive var step = new MoveStep(nextDirection, Collector); step.Invoke(); - yield return step; } break; case State.TravelToCan: @@ -69,7 +69,6 @@ namespace Czoko_Smieciarka.AI_Naive { var step = new CollectStep(Collector, garbage, item.TypeOfGarbage); step.Invoke(); - yield return step; } this.CurrentState = State.Wait; @@ -83,7 +82,6 @@ namespace Czoko_Smieciarka.AI_Naive var step = new MoveStep(nextDirection, Collector); step.Invoke(); - yield return step; } break; case State.Wait: @@ -109,12 +107,10 @@ namespace Czoko_Smieciarka.AI_Naive } break; case State.Finish: - yield break; - } - foreach (var item in PerformMove()) - { - yield return item; + return false; } + return true; + } } -} +} \ No newline at end of file diff --git a/Trunk/Components/CzokoŚmieciarka.DataModels.GeneralModels/Models/TrashCan.cs b/Trunk/Components/CzokoŚmieciarka.DataModels.GeneralModels/Models/TrashCan.cs index a06ae71..c42c7ef 100644 --- a/Trunk/Components/CzokoŚmieciarka.DataModels.GeneralModels/Models/TrashCan.cs +++ b/Trunk/Components/CzokoŚmieciarka.DataModels.GeneralModels/Models/TrashCan.cs @@ -8,5 +8,8 @@ namespace CzokoŚmieciarka.DataModels.GeneralModels.Models public TrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume) : base(typeOfGarbage, maxVolume) { } + public TrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume, Garbage garbage) : base(typeOfGarbage, maxVolume, garbage) + { + } } } diff --git a/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/RoutePlanningEngine/IRoutePlanningEngine.cs b/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/RoutePlanningEngine/IRoutePlanningEngine.cs index 5632500..ebace0a 100644 --- a/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/RoutePlanningEngine/IRoutePlanningEngine.cs +++ b/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/RoutePlanningEngine/IRoutePlanningEngine.cs @@ -8,7 +8,7 @@ using CzokoŚmieciarka.DataModels.Interfaces.TrashCans; namespace CzokoŚmieciarka.DataModels.Interfaces.RoutePlanningEngine { public interface IRoutePlanningEngine - { - IEnumerable CalculateStep(); + { + void PerformStep(); } -} +} \ No newline at end of file diff --git a/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/TrashCans/ATrashCan.cs b/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/TrashCans/ATrashCan.cs index 5859ad4..9d900cf 100644 --- a/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/TrashCans/ATrashCan.cs +++ b/Trunk/Components/CzokoŚmieciarka.DataModels/Interfaces/TrashCans/ATrashCan.cs @@ -9,6 +9,12 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.TrashCans this.MaxVolume = maxVolume; this.TypeOfGarbage = typeOfGarbage; } + protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume, AGarbage garbage) + { + this.MaxVolume = maxVolume; + this.TypeOfGarbage = typeOfGarbage; + this.Garbage = garbage; + } public ITypeOfGarbage TypeOfGarbage { get; } diff --git a/Trunk/Interface/CzokoŚmieciarka.WPFv2/MainWindow.xaml.cs b/Trunk/Interface/CzokoŚmieciarka.WPFv2/MainWindow.xaml.cs index 1948c70..2c38d4a 100644 --- a/Trunk/Interface/CzokoŚmieciarka.WPFv2/MainWindow.xaml.cs +++ b/Trunk/Interface/CzokoŚmieciarka.WPFv2/MainWindow.xaml.cs @@ -13,8 +13,10 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Czoko_Smieciarka.AI_Naive; using CzokoŚmieciarka.DataModels.Enums; using CzokoŚmieciarka.DataModels.GeneralModels.Models; +using CzokoŚmieciarka.DataModels.Interfaces; using CzokoŚmieciarka.DataModels.Interfaces.TrashCans; using CzokoŚmieciarka.DataModels.Models; using CzokoŚmieciarka.WPFv2.Interfaces; @@ -32,7 +34,7 @@ namespace CzokoŚmieciarka.WPFv2 IWPFObject[,] Objects = new IWPFObject[Columns,Rows]; private IEnumerable GarbageCollectorContainers; private WPFGarbageCollector garbageCollector; - + private RoutePlanningEngine routePlanningEngine; public MainWindow() { @@ -45,7 +47,7 @@ namespace CzokoŚmieciarka.WPFv2 if (e.Key == Key.Space) { - garbageCollector.Position = garbageCollector.MoveRight(); + routePlanningEngine.PerformStep(); } CollectorBoard.Children.Clear(); @@ -79,15 +81,6 @@ namespace CzokoŚmieciarka.WPFv2 Board.Children.Add(Objects[i, j].Image); } - IEnumerable trashCans = new List(); - if(i != 6) - { - WPFHouse house = new WPFHouse(new Coords(i, i), trashCans); - Objects[i, i] = house; - Grid.SetRow(Objects[i, i].Image, i); - Grid.SetColumn(Objects[i, i].Image, i); - Board.Children.Add(Objects[i, i].Image); - } } Objects[2,7] = new WPFDump(new TypeOfGarbage(GarbageType.Glass,1,1), 10000,new Coords(2,7)); Grid.SetColumn(Objects[2, 7].Image, 2); @@ -123,6 +116,29 @@ namespace CzokoŚmieciarka.WPFv2 //CollectorInfo.Items.Add(garbageCollector); //CollectorInfo.Columns.Add(new DataGridTextColumn {Header="X", Binding = new Binding("Position.X")}); //CollectorInfo.Columns.Add(new DataGridTextColumn { Header = "Y", Binding = new Binding("Position.Y") }); + IEnumerable trashCans = new List() + { + new TrashCan(new TypeOfGarbage(GarbageType.Glass,1,1), 500, new Garbage(new TypeOfGarbage(GarbageType.Glass,1,1), 100)), + new TrashCan(new TypeOfGarbage(GarbageType.Organic,1,1), 500, new Garbage(new TypeOfGarbage(GarbageType.Organic,1,1), 100)), + new TrashCan(new TypeOfGarbage(GarbageType.Paper,1,1), 500, new Garbage(new TypeOfGarbage(GarbageType.Paper,1,1), 100)), + new TrashCan(new TypeOfGarbage(GarbageType.PlasticMetal,1,1), 500, new Garbage(new TypeOfGarbage(GarbageType.PlasticMetal,1,1), 100)) + }; + + WPFHouse house = new WPFHouse(new Coords(1, 3), trashCans); + Objects[1, 3] = house; + Grid.SetRow(Objects[1, 3].Image, 1); + Grid.SetColumn(Objects[1, 3].Image, 3); + Board.Children.Add(Objects[1, 3].Image); + + + routePlanningEngine = new RoutePlanningEngine(garbageCollector, + new List() + { + new GarbageLocalization(house.Coords,house.TrashCans) + }, + new List() + { + }); } } }