lepszy dfs
This commit is contained in:
parent
5997093c03
commit
3c7c3bbba5
@ -57,34 +57,6 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
|
|||||||
|
|
||||||
var result = new List<IStep>();
|
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)
|
if (grid[collector.Coords.X, collector.Coords.Y] is House)
|
||||||
{
|
{
|
||||||
var collectSteps = new List<IStep>()
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
@ -129,6 +129,7 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
|
|||||||
|
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
this.Collector.Coords = collector.Coords;
|
this.Collector.Coords = collector.Coords;
|
||||||
|
this.Collector.TrashContainers = collector.TrashContainers;
|
||||||
|
|
||||||
for (int x = 0; x < grid.GetLength(0); x++)
|
for (int x = 0; x < grid.GetLength(0); x++)
|
||||||
{
|
{
|
||||||
|
@ -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()
|
public virtual object Clone()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
@ -10,7 +10,7 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans
|
|||||||
{
|
{
|
||||||
this.MaxVolume = maxVolume;
|
this.MaxVolume = maxVolume;
|
||||||
this.TypeOfGarbage = typeOfGarbage;
|
this.TypeOfGarbage = typeOfGarbage;
|
||||||
Garbage = new BasicGarbage(typeOfGarbage, 0);
|
Garbage = new BasicGarbage((TypeOfGarbage)typeOfGarbage, 0);
|
||||||
}
|
}
|
||||||
protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume, AGarbage garbage)
|
protected ATrashCan(ITypeOfGarbage typeOfGarbage, int maxVolume, AGarbage garbage)
|
||||||
{
|
{
|
||||||
|
@ -6,26 +6,26 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models
|
|||||||
{
|
{
|
||||||
public class BasicGarbage : AGarbage
|
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)
|
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)
|
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()
|
public override object Clone()
|
||||||
{
|
{
|
||||||
return new BasicGarbage((ITypeOfGarbage)TypeOfGarbage.Clone(), Weight);
|
return new BasicGarbage((TypeOfGarbage)TypeOfGarbage.Clone(), Weight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,10 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models
|
|||||||
|
|
||||||
public override object Clone()
|
public override object Clone()
|
||||||
{
|
{
|
||||||
|
if (TrashContainers.Any(x=>x.FillPercent > 0))
|
||||||
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
var cloneList = TrashContainers.Select(x=>(GarbageCollectorContainer)x.Clone()).ToList();
|
var cloneList = TrashContainers.Select(x=>(GarbageCollectorContainer)x.Clone()).ToList();
|
||||||
return new GarbageCollector((Coords)Coords.Clone(), cloneList, rows,columns, HouseCounter,Counter);
|
return new GarbageCollector((Coords)Coords.Clone(), cloneList, rows,columns, HouseCounter,Counter);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user