Dodano drugi konstruktor do ATrashCan
This commit is contained in:
parent
9ef87dc4fe
commit
e105382084
@ -16,26 +16,28 @@ namespace Czoko_Smieciarka.AI_Naive
|
|||||||
public IEnumerable<IGarbageLocalization> Cans { get; }
|
public IEnumerable<IGarbageLocalization> Cans { get; }
|
||||||
public IEnumerable<ADump> Dumps { get; }
|
public IEnumerable<ADump> Dumps { get; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum State { TravelToDump, TravelToCan, Wait, Finish }
|
enum State { TravelToDump, TravelToCan, Wait, Finish }
|
||||||
public Coords Destination { get; set; }
|
public Coords Destination { get; set; }
|
||||||
public object DestinationObject { get; set; }
|
public object DestinationObject { get; set; }
|
||||||
private State CurrentState { get; set; }
|
private State CurrentState { get; set; }
|
||||||
|
|
||||||
public IEnumerable<IStep> CalculateStep()
|
public void PerformStep()
|
||||||
{
|
{
|
||||||
return PerformMove();
|
PerformMove();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RoutePlanningEngine(IGarbageCollector collector, IEnumerable<IGarbageLocalization> cans, IEnumerable<ADump> dumps)
|
public RoutePlanningEngine(IGarbageCollector collector, IEnumerable<IGarbageLocalization> cans, IEnumerable<ADump> dumps)
|
||||||
{
|
{
|
||||||
this.Collector = collector.Clone() as IGarbageCollector;
|
this.Collector = collector;
|
||||||
this.Cans = cans;
|
this.Cans = cans;
|
||||||
this.Dumps = dumps;
|
this.Dumps = dumps;
|
||||||
this.CurrentState = State.Wait;
|
this.CurrentState = State.Wait;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private IEnumerable<IStep> PerformMove()
|
private bool PerformMove()
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (CurrentState)
|
switch (CurrentState)
|
||||||
@ -46,7 +48,6 @@ namespace Czoko_Smieciarka.AI_Naive
|
|||||||
var dump = (DestinationObject as ADump);
|
var dump = (DestinationObject as ADump);
|
||||||
var step = new SpillStep(Collector, dump, dump.TypeOfGarbage);
|
var step = new SpillStep(Collector, dump, dump.TypeOfGarbage);
|
||||||
step.Invoke();
|
step.Invoke();
|
||||||
yield return step;
|
|
||||||
this.CurrentState = State.Wait;
|
this.CurrentState = State.Wait;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -58,7 +59,6 @@ namespace Czoko_Smieciarka.AI_Naive
|
|||||||
|
|
||||||
var step = new MoveStep(nextDirection, Collector);
|
var step = new MoveStep(nextDirection, Collector);
|
||||||
step.Invoke();
|
step.Invoke();
|
||||||
yield return step;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case State.TravelToCan:
|
case State.TravelToCan:
|
||||||
@ -69,7 +69,6 @@ namespace Czoko_Smieciarka.AI_Naive
|
|||||||
{
|
{
|
||||||
var step = new CollectStep(Collector, garbage, item.TypeOfGarbage);
|
var step = new CollectStep(Collector, garbage, item.TypeOfGarbage);
|
||||||
step.Invoke();
|
step.Invoke();
|
||||||
yield return step;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.CurrentState = State.Wait;
|
this.CurrentState = State.Wait;
|
||||||
@ -83,7 +82,6 @@ namespace Czoko_Smieciarka.AI_Naive
|
|||||||
|
|
||||||
var step = new MoveStep(nextDirection, Collector);
|
var step = new MoveStep(nextDirection, Collector);
|
||||||
step.Invoke();
|
step.Invoke();
|
||||||
yield return step;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case State.Wait:
|
case State.Wait:
|
||||||
@ -109,12 +107,10 @@ namespace Czoko_Smieciarka.AI_Naive
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case State.Finish:
|
case State.Finish:
|
||||||
yield break;
|
return false;
|
||||||
}
|
|
||||||
foreach (var item in PerformMove())
|
|
||||||
{
|
|
||||||
yield return item;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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) : base(typeOfGarbage, maxVolume)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
public TrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume, Garbage garbage) : base(typeOfGarbage, maxVolume, garbage)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
|||||||
namespace CzokoŚmieciarka.DataModels.Interfaces.RoutePlanningEngine
|
namespace CzokoŚmieciarka.DataModels.Interfaces.RoutePlanningEngine
|
||||||
{
|
{
|
||||||
public interface IRoutePlanningEngine
|
public interface IRoutePlanningEngine
|
||||||
{
|
{
|
||||||
IEnumerable<IStep> CalculateStep();
|
void PerformStep();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,6 +9,12 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.TrashCans
|
|||||||
this.MaxVolume = maxVolume;
|
this.MaxVolume = maxVolume;
|
||||||
this.TypeOfGarbage = typeOfGarbage;
|
this.TypeOfGarbage = typeOfGarbage;
|
||||||
}
|
}
|
||||||
|
protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume, AGarbage garbage)
|
||||||
|
{
|
||||||
|
this.MaxVolume = maxVolume;
|
||||||
|
this.TypeOfGarbage = typeOfGarbage;
|
||||||
|
this.Garbage = garbage;
|
||||||
|
}
|
||||||
|
|
||||||
public ITypeOfGarbage TypeOfGarbage { get; }
|
public ITypeOfGarbage TypeOfGarbage { get; }
|
||||||
|
|
||||||
|
@ -13,8 +13,10 @@ using System.Windows.Media;
|
|||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Navigation;
|
using System.Windows.Navigation;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
using Czoko_Smieciarka.AI_Naive;
|
||||||
using CzokoŚmieciarka.DataModels.Enums;
|
using CzokoŚmieciarka.DataModels.Enums;
|
||||||
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
|
using CzokoŚmieciarka.DataModels.GeneralModels.Models;
|
||||||
|
using CzokoŚmieciarka.DataModels.Interfaces;
|
||||||
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
||||||
using CzokoŚmieciarka.DataModels.Models;
|
using CzokoŚmieciarka.DataModels.Models;
|
||||||
using CzokoŚmieciarka.WPFv2.Interfaces;
|
using CzokoŚmieciarka.WPFv2.Interfaces;
|
||||||
@ -32,7 +34,7 @@ namespace CzokoŚmieciarka.WPFv2
|
|||||||
IWPFObject[,] Objects = new IWPFObject[Columns,Rows];
|
IWPFObject[,] Objects = new IWPFObject[Columns,Rows];
|
||||||
private IEnumerable<AGarbageCollectorContainer> GarbageCollectorContainers;
|
private IEnumerable<AGarbageCollectorContainer> GarbageCollectorContainers;
|
||||||
private WPFGarbageCollector garbageCollector;
|
private WPFGarbageCollector garbageCollector;
|
||||||
|
private RoutePlanningEngine routePlanningEngine;
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -45,7 +47,7 @@ namespace CzokoŚmieciarka.WPFv2
|
|||||||
|
|
||||||
if (e.Key == Key.Space)
|
if (e.Key == Key.Space)
|
||||||
{
|
{
|
||||||
garbageCollector.Position = garbageCollector.MoveRight();
|
routePlanningEngine.PerformStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectorBoard.Children.Clear();
|
CollectorBoard.Children.Clear();
|
||||||
@ -79,15 +81,6 @@ namespace CzokoŚmieciarka.WPFv2
|
|||||||
Board.Children.Add(Objects[i, j].Image);
|
Board.Children.Add(Objects[i, j].Image);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<TrashCan> trashCans = new List<TrashCan>();
|
|
||||||
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));
|
Objects[2,7] = new WPFDump(new TypeOfGarbage(GarbageType.Glass,1,1), 10000,new Coords(2,7));
|
||||||
Grid.SetColumn(Objects[2, 7].Image, 2);
|
Grid.SetColumn(Objects[2, 7].Image, 2);
|
||||||
@ -123,6 +116,29 @@ namespace CzokoŚmieciarka.WPFv2
|
|||||||
//CollectorInfo.Items.Add(garbageCollector);
|
//CollectorInfo.Items.Add(garbageCollector);
|
||||||
//CollectorInfo.Columns.Add(new DataGridTextColumn {Header="X", Binding = new Binding("Position.X")});
|
//CollectorInfo.Columns.Add(new DataGridTextColumn {Header="X", Binding = new Binding("Position.X")});
|
||||||
//CollectorInfo.Columns.Add(new DataGridTextColumn { Header = "Y", Binding = new Binding("Position.Y") });
|
//CollectorInfo.Columns.Add(new DataGridTextColumn { Header = "Y", Binding = new Binding("Position.Y") });
|
||||||
|
IEnumerable<TrashCan> trashCans = new List<TrashCan>()
|
||||||
|
{
|
||||||
|
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<IGarbageLocalization>()
|
||||||
|
{
|
||||||
|
new GarbageLocalization(house.Coords,house.TrashCans)
|
||||||
|
},
|
||||||
|
new List<ADump>()
|
||||||
|
{
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user