public NTree <Puzzle>[] construireTree(Puzzle puz) { //allAdded.Add(puz); List <Puzzle> oriz = generateO(puz); List <Puzzle> vert = generateV(puz); //Console.WriteLine(oriz.Count+" "+vert.Count); if (oriz.Count == 0 && vert.Count == 0) { NTree <Puzzle>[] nTree1 = new NTree <Puzzle> [0]; return(null); } int c = 0; int size = oriz.Count + vert.Count; NTree <Puzzle>[] nTree = new NTree <Puzzle> [size]; foreach (var e in oriz) { nTree[c] = new NTree <Puzzle>(e); c++; } foreach (var e in vert) { nTree[c] = new NTree <Puzzle>(e); c++; } return(nTree); }
public RepoPuzzle(Puzzle puzzle, Puzzle goal) { tree = new NTree <Puzzle>(puzzle); this.puz = puzzle; this.goal = goal; Tuple <int, int> tuple = new Tuple <int, int>(puzzle.IndexE.First, puzzle.IndexE.Second); Dictionary <int, List <Puzzle> > dictionary = new Dictionary <int, List <Puzzle> >(); List <Puzzle> listPuz = new List <Puzzle>(); listPuz.Add(puzzle); dictionary.Add(getSum(puzzle), listPuz); added.Add(tuple, dictionary); }
public List <Puzzle> BFS() { tree = new NTree <Puzzle>(puz, construireTree(puz)); List <Puzzle> allVisited = new List <Puzzle>(); Queue <Node <Puzzle> > q = new Queue <Node <Puzzle> >(); q.Enqueue(tree.root); while (q.Count() != 0) { Node <Puzzle> temp = q.Peek(); q.Dequeue(); // allVisited.Add(temp.Value); if (isGoal(temp.Value)) { return(allVisited); } NTree <Puzzle>[] noduri = construireTree(temp.Value); if (temp.ChildrensCount == 0 && noduri.Count() != 0) { if (noduri.Count() != 0) { //Console.WriteLine(allAdded.Count); NTree <Puzzle> temporar = new NTree <Puzzle>(temp.Value, noduri); temp.Childrens = temporar.root.Childrens; foreach (var aux in temporar.root.Childrens) { q.Enqueue(aux); } } } // else { foreach (var va1 in temp.Childrens) { q.Enqueue(va1); } } } return(null); }