poprawiony bfs
This commit is contained in:
parent
3c7c3bbba5
commit
c3b0d5f609
@ -56,34 +56,7 @@ namespace MonoGameView.Algorithms
|
|||||||
|
|
||||||
var result = new List<IStep>();
|
var result = new List<IStep>();
|
||||||
var itemdupa = grid[collector.Coords.X, collector.Coords.Y];
|
var itemdupa = grid[collector.Coords.X, collector.Coords.Y];
|
||||||
if (!(itemdupa is House && collector.TrashContainers.All(i=>i.FillPercent==0)))
|
|
||||||
{
|
|
||||||
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>()
|
||||||
@ -119,6 +92,34 @@ namespace MonoGameView.Algorithms
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!(itemdupa is House && collector.TrashContainers.All(i=>i.FillPercent==0)))
|
||||||
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
@ -141,8 +142,9 @@ namespace MonoGameView.Algorithms
|
|||||||
var nodes2 = new List<Tuple<List<IStep>, GarbageCollector, ICloneable[,]>>();
|
var nodes2 = new List<Tuple<List<IStep>, GarbageCollector, ICloneable[,]>>();
|
||||||
foreach (var item in nodes)
|
foreach (var item in nodes)
|
||||||
{
|
{
|
||||||
// Thread.Sleep(100);
|
//Thread.Sleep(1);
|
||||||
this.Collector.Coords = item.Item2.Coords;
|
this.Collector.Coords = item.Item2.Coords;
|
||||||
|
this.Collector.TrashContainers = item.Item2.TrashContainers;
|
||||||
for (int x = 0; x < item.Item3.GetLength(0); x++)
|
for (int x = 0; x < item.Item3.GetLength(0); x++)
|
||||||
{
|
{
|
||||||
for (int y = 0; y < item.Item3.GetLength(1); y++)
|
for (int y = 0; y < item.Item3.GetLength(1); y++)
|
||||||
|
@ -127,7 +127,7 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
|
|||||||
KeyValuePair<List<IStep>, int> Search(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length)
|
KeyValuePair<List<IStep>, int> Search(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length)
|
||||||
{
|
{
|
||||||
|
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(10);
|
||||||
this.Collector.Coords = collector.Coords;
|
this.Collector.Coords = collector.Coords;
|
||||||
this.Collector.TrashContainers = collector.TrashContainers;
|
this.Collector.TrashContainers = collector.TrashContainers;
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ namespace MonoGameView.DataModels
|
|||||||
int processingTimePerUnit = Convert.ToInt32(garbageNode.SelectSingleNode("ProcessingTimePerUnit").InnerText);
|
int processingTimePerUnit = Convert.ToInt32(garbageNode.SelectSingleNode("ProcessingTimePerUnit").InnerText);
|
||||||
int maxVolume = Convert.ToInt32(objectNode.SelectSingleNode("Volume").InnerText);
|
int maxVolume = Convert.ToInt32(objectNode.SelectSingleNode("Volume").InnerText);
|
||||||
typeOfGarbage = new TypeOfGarbage(garbageType, density, processingTimePerUnit);
|
typeOfGarbage = new TypeOfGarbage(garbageType, density, processingTimePerUnit);
|
||||||
Dump dump = new Dump(typeOfGarbage, maxVolume, new Coords(x, y));
|
Dump dump = new Dump(typeOfGarbage, int.MaxValue, new Coords(x, y));
|
||||||
grid[x, y] = dump;
|
grid[x, y] = dump;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ namespace CzokoŚmieciarka.MonoGameView
|
|||||||
|
|
||||||
|
|
||||||
stepN = 0;
|
stepN = 0;
|
||||||
var dfs = new DFS(collector,grid);
|
var dfs = new BFS(collector,grid);
|
||||||
//steps = dfs.BestPath(Content, collector, grid);
|
//steps = dfs.BestPath(Content, collector, grid);
|
||||||
new Thread(delegate() {
|
new Thread(delegate() {
|
||||||
var x = dfs.BestPath(Content, collector, grid);
|
var x = dfs.BestPath(Content, collector, grid);
|
||||||
|
Loading…
Reference in New Issue
Block a user