lepszy dfs

This commit is contained in:
ryuga4 2019-05-13 18:15:48 +02:00
parent 5997093c03
commit 3c7c3bbba5
5 changed files with 39 additions and 34 deletions

View File

@ -57,34 +57,6 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
var result = new List<IStep>();
if (!(collector.TrashContainers.Any(x => x.FillPercent > 0) && grid[collector.Coords.X,collector.Coords.Y] is ADump))
{
var moveSteps = new List<IStep>()
{
new MoveStep(Direction.Up),
new MoveStep(Direction.Down),
new MoveStep(Direction.Left),
new MoveStep(Direction.Right)
};
var filteredMoveSteps = new List<IStep>();
foreach (var item in moveSteps)
{
var copyCollector = (AGarbageCollector)collector.Clone();
if (item.Invoke(copyCollector, grid))
{
var gcx = copyCollector.Coords.X;
var gcy = copyCollector.Coords.Y;
if (grid[gcx, gcy] is Road1 || grid[gcx, gcy] is House || (grid[gcx, gcy] is ADump && copyCollector.TrashContainers.Any(x => x.FillPercent > 0)))
{
result.Add(item);
}
}
}
}
if (grid[collector.Coords.X, collector.Coords.Y] is House)
{
var collectSteps = new List<IStep>()
@ -120,6 +92,34 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
}
}
if (!(collector.TrashContainers.Any(x => x.FillPercent > 0) && grid[collector.Coords.X,collector.Coords.Y] is ADump))
{
var moveSteps = new List<IStep>()
{
new MoveStep(Direction.Up),
new MoveStep(Direction.Down),
new MoveStep(Direction.Left),
new MoveStep(Direction.Right)
};
var filteredMoveSteps = new List<IStep>();
foreach (var item in moveSteps)
{
var copyCollector = (AGarbageCollector)collector.Clone();
if (item.Invoke(copyCollector, grid))
{
var gcx = copyCollector.Coords.X;
var gcy = copyCollector.Coords.Y;
if (grid[gcx, gcy] is Road1 || grid[gcx, gcy] is House || (grid[gcx, gcy] is ADump && copyCollector.TrashContainers.Any(x => x.FillPercent > 0)))
{
result.Add(item);
}
}
}
}
return result;
}
@ -129,6 +129,7 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
Thread.Sleep(100);
this.Collector.Coords = collector.Coords;
this.Collector.TrashContainers = collector.TrashContainers;
for (int x = 0; x < grid.GetLength(0); x++)
{

View File

@ -67,7 +67,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector
}
public IEnumerable<AGarbageCollectorContainer> TrashContainers { get; }
public IEnumerable<AGarbageCollectorContainer> TrashContainers { get; set; }
public virtual object Clone()
{
throw new NotImplementedException();

View File

@ -10,7 +10,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans
{
this.MaxVolume = maxVolume;
this.TypeOfGarbage = typeOfGarbage;
Garbage = new BasicGarbage(typeOfGarbage, 0);
Garbage = new BasicGarbage((TypeOfGarbage)typeOfGarbage, 0);
}
protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume, AGarbage garbage)
{

View File

@ -6,26 +6,26 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models
{
public class BasicGarbage : AGarbage
{
public BasicGarbage(ITypeOfGarbage typeOfGarbage, double weight) : base(typeOfGarbage, weight)
public BasicGarbage(TypeOfGarbage typeOfGarbage, double weight) : base(typeOfGarbage, weight)
{
}
protected override AGarbage Add(AGarbage garbageToAdd)
{
return new BasicGarbage(TypeOfGarbage, Weight + garbageToAdd.Weight);
return new BasicGarbage((TypeOfGarbage)TypeOfGarbage, Weight + garbageToAdd.Weight);
}
protected override AGarbage Subtract(AGarbage garbageToSubtract)
{
return new BasicGarbage(TypeOfGarbage, Weight - garbageToSubtract.Weight);
return new BasicGarbage((TypeOfGarbage)TypeOfGarbage, Weight - garbageToSubtract.Weight);
}
public override object Clone()
{
return new BasicGarbage((ITypeOfGarbage)TypeOfGarbage.Clone(), Weight);
return new BasicGarbage((TypeOfGarbage)TypeOfGarbage.Clone(), Weight);
}
}
}

View File

@ -28,6 +28,10 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
public override object Clone()
{
if (TrashContainers.Any(x=>x.FillPercent > 0))
{
Console.WriteLine();
}
var cloneList = TrashContainers.Select(x=>(GarbageCollectorContainer)x.Clone()).ToList();
return new GarbageCollector((Coords)Coords.Clone(), cloneList, rows,columns, HouseCounter,Counter);
}