This commit is contained in:
ryuga4 2019-04-21 01:28:38 +02:00
parent 6071eb60b9
commit 0260ff777c
10 changed files with 361 additions and 382 deletions

View File

@ -45,6 +45,10 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\CzokoŚmieciarka.DataModels.GeneralModels\CzokoŚmieciarka.DataModels.GeneralModels.csproj">
<Project>{a3d5da96-69d7-463f-b1ee-6fc70716e3b2}</Project>
<Name>CzokoŚmieciarka.DataModels.GeneralModels</Name>
</ProjectReference>
<ProjectReference Include="..\CzokoŚmieciarka.DataModels\CzokoŚmieciarka.DataModels.csproj"> <ProjectReference Include="..\CzokoŚmieciarka.DataModels\CzokoŚmieciarka.DataModels.csproj">
<Project>{f2e11fee-c5ac-47d2-ba9c-819909b6dff7}</Project> <Project>{f2e11fee-c5ac-47d2-ba9c-819909b6dff7}</Project>
<Name>CzokoŚmieciarka.DataModels</Name> <Name>CzokoŚmieciarka.DataModels</Name>

View File

@ -1,5 +1,7 @@
using CzokoŚmieciarka.DataModels.Enums; using CzokoŚmieciarka.DataModels.Enums;
using CzokoŚmieciarka.DataModels.Interfaces; using CzokoŚmieciarka.DataModels.Interfaces;
using CzokoŚmieciarka.DataModels.Interfaces.Road;
using CzokoŚmieciarka.DataModels.Interfaces.RoutePlanningEngine; using CzokoŚmieciarka.DataModels.Interfaces.RoutePlanningEngine;
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans; using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
using CzokoŚmieciarka.DataModels.Models; using CzokoŚmieciarka.DataModels.Models;
@ -12,105 +14,50 @@ namespace Czoko_Smieciarka.AI_Naive
{ {
public class RoutePlanningEngine : IRoutePlanningEngine public class RoutePlanningEngine : IRoutePlanningEngine
{ {
public IGarbageCollector Collector { get; } IGarbageCollector Collector { get; set; }
public IEnumerable<IGarbageLocalization> Cans { get; }
public IEnumerable<ADump> Dumps { get; } IGarbageCollector CollectorClone { get; set; }
object[,] Board { get; set; }
object[,] BoardClone { get; set; }
enum State { TravelToDump, TravelToCan, Wait, Finish } public IEnumerable<IStep> ReturnSteps()
public Coords Destination { get; set; }
public object DestinationObject { get; set; }
private State CurrentState { get; set; }
public void PerformStep()
{ {
PerformMove(); throw new NotImplementedException();
} }
public RoutePlanningEngine(IGarbageCollector collector, IEnumerable<IGarbageLocalization> cans, IEnumerable<ADump> dumps) public RoutePlanningEngine(object[,] board, IGarbageCollector collector)
{ {
this.Collector = collector; this.Collector = collector;
this.Cans = cans; this.CollectorClone = (IGarbageCollector) collector.Clone();
this.Dumps = dumps; this.Board = board;
this.CurrentState = State.Wait; this.BoardClone = (object [,]) board.Clone();
} }
IEnumerable<IStep> PossibleSteps(object[,] BoardClone, IGarbageCollector CollectorClone)
private bool PerformMove()
{ {
var x = CollectorClone.Coords.X;
var y = CollectorClone.Coords.Y;
var maxX = BoardClone.GetLength(0) - 1;
var maxY = BoardClone.GetLength(1) - 1;
switch (CurrentState)
var currentCollector = CollectorClone.Clone();
var Moves = new List<IStep>
{ {
case State.TravelToDump: new MoveStep(Direction.Left, CollectorClone),
if (Destination == Collector.Coords) new MoveStep(Direction.Right, CollectorClone),
{ new MoveStep(Direction.Up, CollectorClone),
var dump = (DestinationObject as ADump); new MoveStep(Direction.Down, CollectorClone)
var step = new SpillStep(Collector, dump, dump.TypeOfGarbage);
step.Invoke();
this.CurrentState = State.Wait;
}
else
{
var dif = Destination - Collector.Coords;
Direction nextDirection = (dif.X == 0) ?
((dif.Y > 0) ? Direction.Up : Direction.Down) :
((dif.X > 0) ? Direction.Right : Direction.Left);
var step = new MoveStep(nextDirection, Collector);
step.Invoke();
}
break;
case State.TravelToCan:
if (Destination == Collector.Coords)
{
var garbage = (DestinationObject as IGarbageLocalization);
foreach (var item in garbage.TrashCans)
{
var step = new CollectStep(Collector, garbage, item.TypeOfGarbage);
step.Invoke();
}
this.CurrentState = State.Wait;
}
else
{
var dif = Destination - Collector.Coords;
Direction nextDirection = (dif.X == 0) ?
((dif.Y > 0) ? Direction.Up : Direction.Down) :
((dif.X > 0) ? Direction.Right : Direction.Left);
var step = new MoveStep(nextDirection, Collector);
step.Invoke();
}
break;
case State.Wait:
var notEmpty = Collector.TrashContainers.Where(i => i.FillPercent > 0);
if (notEmpty.Any())
{
var destDump = Dumps.First(i => i.TypeOfGarbage == notEmpty.First().TypeOfGarbage);
this.Destination = destDump.Coords;
this.CurrentState = State.TravelToDump;
}
else
{
var notEmptyCans = Cans.Where(i => i.TrashCans.Any(j => j.FillPercent > 0));
if (notEmptyCans.Any())
{
this.Destination = notEmptyCans.First().Coords;
this.CurrentState = State.TravelToCan;
}
else
{
this.CurrentState = State.Finish;
}
}
break;
case State.Finish:
return false;
} }
return true;
} }
} }
} }

View File

@ -49,6 +49,8 @@
<Compile Include="Interfaces\GarbageCollector\IGarbageCollector.cs" /> <Compile Include="Interfaces\GarbageCollector\IGarbageCollector.cs" />
<Compile Include="Interfaces\Garbage\AGarbage.cs" /> <Compile Include="Interfaces\Garbage\AGarbage.cs" />
<Compile Include="Interfaces\Garbage\IGarbage.cs" /> <Compile Include="Interfaces\Garbage\IGarbage.cs" />
<Compile Include="Interfaces\Road\IRoad.cs" />
<Compile Include="Interfaces\Road\IRoad2.cs" />
<Compile Include="Interfaces\TrashCans\ADump.cs" /> <Compile Include="Interfaces\TrashCans\ADump.cs" />
<Compile Include="Interfaces\IGarbageLocalization.cs" /> <Compile Include="Interfaces\IGarbageLocalization.cs" />
<Compile Include="Interfaces\ITypeOfGarbage.cs" /> <Compile Include="Interfaces\ITypeOfGarbage.cs" />

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CzokoŚmieciarka.DataModels.Interfaces.Road
{
public interface IRoad
{
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CzokoŚmieciarka.DataModels.Interfaces.Road
{
public interface IRoad2
{
}
}

View File

@ -9,6 +9,6 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.RoutePlanningEngine
{ {
public interface IRoutePlanningEngine public interface IRoutePlanningEngine
{ {
void PerformStep(); IEnumerable<IStep> ReturnSteps();
} }
} }

View File

@ -7,11 +7,12 @@ using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using CzokoŚmieciarka.DataModels.Models; using CzokoŚmieciarka.DataModels.Models;
using CzokoŚmieciarka.DataModels.Interfaces.Road;
using CzokoŚmieciarka.WPFv2.Interfaces; using CzokoŚmieciarka.WPFv2.Interfaces;
namespace CzokoŚmieciarka.WPFv2.Models namespace CzokoŚmieciarka.WPFv2.Models
{ {
class Road : IWPFObject class Road : IWPFObject, IRoad
{ {
public string ImagePath { get; set; } public string ImagePath { get; set; }
public Image Image { get; set; } public Image Image { get; set; }

View File

@ -7,10 +7,11 @@ using System.Windows.Controls;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using CzokoŚmieciarka.DataModels.Models; using CzokoŚmieciarka.DataModels.Models;
using CzokoŚmieciarka.WPFv2.Interfaces; using CzokoŚmieciarka.WPFv2.Interfaces;
using CzokoŚmieciarka.DataModels.Interfaces.Road;
namespace CzokoŚmieciarka.WPFv2.Models namespace CzokoŚmieciarka.WPFv2.Models
{ {
class Road2 : IWPFObject class Road2 : IWPFObject, IRoad2
{ {
public string ImagePath { get; set; } public string ImagePath { get; set; }
public Image Image { get; set; } public Image Image { get; set; }