zapis stanow

This commit is contained in:
ryuga4 2019-05-22 00:11:35 +02:00
parent 627a9c7fc0
commit b66d57b27d
2 changed files with 20 additions and 20 deletions

View File

@ -27,7 +27,7 @@ namespace MonoGameView.Algorithms
int count;
public List<Coords> Houses { get; set; }
public List<Coords> Dumps { get; set; }
public List<IStep> BestPath(ContentManager content, GarbageCollector collector, ICloneable[,] grid)
public Tuple<List<IStep>,int,List<ICloneable[,]>> BestPath(ContentManager content, GarbageCollector collector, ICloneable[,] grid)
{
Houses = new List<Coords>();
@ -49,9 +49,9 @@ namespace MonoGameView.Algorithms
var r = SearchBestFirst(content, collector, grid, 0).Key;
var r = SearchBestFirst(content, collector, grid, 0);
Console.WriteLine($"Counts : {count}");
if (r == null) return new List<IStep>();
if (r == null) return new Tuple<List<IStep>, int, List<ICloneable[,]>>(new List<IStep>(), 0, new List<ICloneable[,]>());
return r;
}
@ -135,7 +135,7 @@ namespace MonoGameView.Algorithms
int Priority (Tuple<List<IStep>,GarbageCollector,ICloneable[,]> t)
int Priority (Tuple<KeyValuePair<List<IStep>,List<ICloneable[,]>>,GarbageCollector,ICloneable[,]> t)
{
var inHouses = Houses
.Aggregate(0.0, (a, b) => a + (t.Item3[b.X, b.Y] as IGarbageLocalization)
@ -189,15 +189,15 @@ namespace MonoGameView.Algorithms
KeyValuePair<List<IStep>, int> SearchBestFirst(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length)
Tuple<List<IStep>, int, List<ICloneable[,]>> SearchBestFirst(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length)
{
//Thread.Sleep(1);
count = 0;
var nodes = new PriorityQueue<Tuple<List<IStep>, GarbageCollector, ICloneable[,]>>();
var nodes = new PriorityQueue<Tuple<KeyValuePair<List<IStep>, List<ICloneable[,]>>, GarbageCollector, ICloneable[,]>>();
var f = new Tuple<List<IStep>, GarbageCollector, ICloneable[,]>(new List<IStep>(), collector, grid);
var f = new Tuple<KeyValuePair<List<IStep>, List<ICloneable[,]>>, GarbageCollector, ICloneable[,]>(new KeyValuePair<List<IStep>, List<ICloneable[,]>>(new List<IStep>(),new List<ICloneable[,]>() { grid }), collector, grid);
nodes.Enqueue(f,Priority(f));
while (true)
@ -223,27 +223,27 @@ namespace MonoGameView.Algorithms
item.Item2.TrashContainers.All(i => i.FillPercent == 0.0)
)
{
return new KeyValuePair<List<IStep>, int>(item.Item1, length);
return new Tuple<List<IStep>, int, List<ICloneable[,]>>(item.Item1.Key, length, item.Item1.Value);
}
if (true)//item.Item2.Counter <= 12)
{
foreach (var step in PossibleSteps(item.Item2, item.Item3))
{
if (step is SpillStep)
foreach (var step in PossibleSteps(item.Item2, item.Item3))
{
if (step is SpillStep)
{
Console.WriteLine();
}
var collectorClone = (GarbageCollector)item.Item2.Clone();
var gridClone = CopyGrid(item.Item3);
step.Invoke(collectorClone, gridClone);
var collectorClone = (GarbageCollector)item.Item2.Clone();
var gridClone = CopyGrid(item.Item3);
step.Invoke(collectorClone, gridClone);
var steps = new List<IStep>();
steps.AddRange(item.Item1);
steps.Add(step);
var f2 = new Tuple<List<IStep>, GarbageCollector, ICloneable[,]>(steps, collectorClone, gridClone);
var steps = new List<IStep>();
steps.AddRange(item.Item1.Key);
steps.Add(step);
var f2 = new Tuple<KeyValuePair<List<IStep>, List<ICloneable[,]>>, GarbageCollector, ICloneable[,]>(new KeyValuePair<List<IStep>, List<ICloneable[,]>>(steps, item.Item1.Value.Concat(new List<ICloneable[,]>() {gridClone }).ToList()), collectorClone, gridClone);
var f2P = Priority(f2);
nodes.Enqueue(f2,Priority(f2));

View File

@ -93,9 +93,9 @@ namespace CzokoŚmieciarka.MonoGameView
stepN = 0;
var dfs = new DFS(collector,grid);
var dfs = new BestFirstSearch(collector,grid);
var r = dfs.BestPath(Content, collector, grid);
steps = r.Key;
steps = r.Item1;
Console.WriteLine(r);
//displayer.Add("Count", r.Value.ToString());
//new Thread(delegate() {