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
{
IEnumerable<IStep> CalculateStep();
void PerformStep();
}
}

View File

@ -16,26 +16,28 @@ namespace Czoko_Smieciarka.AI_Naive
public IEnumerable<IGarbageLocalization> Cans { get; }
public IEnumerable<ADump> 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<IStep> CalculateStep()
public void PerformStep()
{
return PerformMove();
PerformMove();
}
public RoutePlanningEngine(IGarbageCollector collector, IEnumerable<IGarbageLocalization> cans, IEnumerable<ADump> dumps)
{
this.Collector = collector.Clone() as IGarbageCollector;
this.Cans = cans.Select(i=>(IGarbageLocalization) i.Clone());
this.Dumps = dumps.Select(i => (ADump) i.Clone());
this.Collector = collector;
this.Cans = cans;
this.Dumps = dumps;
this.CurrentState = State.Wait;
}
private IEnumerable<IStep> 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
{
@ -57,7 +58,6 @@ namespace Czoko_Smieciarka.AI_Naive
var step = new MoveStep(nextDirection, Collector);
step.Invoke();
yield return step;
}
break;
case State.TravelToCan:
@ -68,7 +68,6 @@ namespace Czoko_Smieciarka.AI_Naive
{
var step = new CollectStep(Collector, garbage, item.TypeOfGarbage);
step.Invoke();
yield return step;
}
this.CurrentState = State.Wait;
@ -82,7 +81,6 @@ namespace Czoko_Smieciarka.AI_Naive
var step = new MoveStep(nextDirection, Collector);
step.Invoke();
yield return step;
}
break;
case State.Wait:
@ -106,12 +104,10 @@ namespace Czoko_Smieciarka.AI_Naive
}
break;
case State.Finish:
yield break;
}
foreach (var item in PerformMove())
{
yield return item;
return false;
}
return true;
}
}
}