inny interfejs

This commit is contained in:
ryuga4 2019-03-26 23:59:58 +01:00
parent aaeb1b3adb
commit 6e6d115a59
2 changed files with 12 additions and 16 deletions

View File

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

View File

@ -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.Select(i=>(IGarbageLocalization) i.Clone()); this.Cans = cans;
this.Dumps = dumps.Select(i => (ADump) i.Clone()); 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
{ {
@ -57,7 +58,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:
@ -68,7 +68,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;
@ -82,7 +81,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:
@ -106,12 +104,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;
} }
} }
} }