bfs
This commit is contained in:
parent
2b996b21ee
commit
1afa3fdb70
12
Trunk/MonoGameView/Algorithms/BFS.cs
Normal file
12
Trunk/MonoGameView/Algorithms/BFS.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MonoGameView.Algorithms
|
||||||
|
{
|
||||||
|
class BFS
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -50,7 +50,7 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<IStep> PossibleSteps(ContentManager content, AGarbageCollector collector, ICloneable[,] grid)
|
List<IStep> PossibleSteps(AGarbageCollector collector, ICloneable[,] grid)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
|
|||||||
|
|
||||||
Console.WriteLine(collector.HouseCounter);
|
Console.WriteLine(collector.HouseCounter);
|
||||||
|
|
||||||
if (collector.Counter> 10 || length > 55)
|
if (collector.Counter> 15 || length > 100)
|
||||||
return new KeyValuePair<List<IStep>, int>(null,length);
|
return new KeyValuePair<List<IStep>, int>(null,length);
|
||||||
count++;
|
count++;
|
||||||
if (Houses.All(c => (grid[c.X, c.Y] as IGarbageLocalization).TrashCans.All(j => j.FillPercent == 0.0))
|
if (Houses.All(c => (grid[c.X, c.Y] as IGarbageLocalization).TrashCans.All(j => j.FillPercent == 0.0))
|
||||||
@ -149,7 +149,7 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
|
|||||||
{
|
{
|
||||||
return new KeyValuePair<List<IStep>, int>(new List<IStep>(), length);
|
return new KeyValuePair<List<IStep>, int>(new List<IStep>(), length);
|
||||||
}
|
}
|
||||||
var possibleSteps = PossibleSteps(content, collector, grid);
|
var possibleSteps = PossibleSteps(collector, grid);
|
||||||
|
|
||||||
foreach (var item in possibleSteps)
|
foreach (var item in possibleSteps)
|
||||||
{
|
{
|
||||||
@ -182,6 +182,30 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private ICloneable[,] CopyGrid(ICloneable[,] grid)
|
private ICloneable[,] CopyGrid(ICloneable[,] grid)
|
||||||
{
|
{
|
||||||
ICloneable[,] result = new ICloneable[grid.GetLength(0), grid.GetLength(1)];
|
ICloneable[,] result = new ICloneable[grid.GetLength(0), grid.GetLength(1)];
|
||||||
|
@ -31,7 +31,7 @@ namespace CzokoŚmieciarka.MonoGameView
|
|||||||
MapLoader mapLoader = new MapLoader();
|
MapLoader mapLoader = new MapLoader();
|
||||||
Vector2 roadPos;
|
Vector2 roadPos;
|
||||||
float timer;
|
float timer;
|
||||||
const float TIMER = 0.02f;
|
const float TIMER = 1f;
|
||||||
int stepN;
|
int stepN;
|
||||||
List<IStep> steps;
|
List<IStep> steps;
|
||||||
GarbageCollector collector;
|
GarbageCollector collector;
|
||||||
@ -84,13 +84,16 @@ namespace CzokoŚmieciarka.MonoGameView
|
|||||||
),
|
),
|
||||||
|
|
||||||
};
|
};
|
||||||
collector = new GarbageCollector(new Coords(9,9), containers, size, size,0);
|
collector = new GarbageCollector(new Coords(0,0), containers, size, size,0);
|
||||||
|
|
||||||
|
|
||||||
stepN = 0;
|
stepN = 0;
|
||||||
var dfs = new DFS(collector,grid);
|
var dfs = new DFS(collector,grid);
|
||||||
//steps = dfs.BestPath(Content, collector, grid);
|
//steps = dfs.BestPath(Content, collector, grid);
|
||||||
new Thread(delegate() { dfs.BestPath(Content, collector, grid); }).Start();
|
new Thread(delegate() {
|
||||||
|
var x = dfs.BestPath(Content, collector, grid);
|
||||||
|
|
||||||
|
}).Start();
|
||||||
|
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
}
|
}
|
||||||
@ -126,8 +129,8 @@ namespace CzokoŚmieciarka.MonoGameView
|
|||||||
{
|
{
|
||||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
|
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
|
||||||
Exit();
|
Exit();
|
||||||
/*
|
|
||||||
var elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
|
/*var elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
|
||||||
timer -= elapsed;
|
timer -= elapsed;
|
||||||
if (timer<0)
|
if (timer<0)
|
||||||
{
|
{
|
||||||
@ -137,8 +140,8 @@ namespace CzokoŚmieciarka.MonoGameView
|
|||||||
steps.First().Invoke(collector, grid);
|
steps.First().Invoke(collector, grid);
|
||||||
steps.RemoveAt(0);
|
steps.RemoveAt(0);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
*/
|
|
||||||
// TODO: Add your update logic here
|
// TODO: Add your update logic here
|
||||||
|
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
|
Loading…
Reference in New Issue
Block a user