public MiniArea(int[,] data, MiniArea father, int weight, int steps) { this.data = data; this.father = father; this.weight = weight; this.steps = steps; }
static void recreatePath(MiniArea actual) { List <MiniArea> paths = new List <MiniArea>(); while (actual != null) { paths.Add(actual); actual = actual.father; } paths.Reverse(); foreach (MiniArea path in paths) { printGame(path.data); Console.WriteLine(); } }
static void process(int[,] game) { MiniArea actual = new MiniArea(game, null, 0, 0); actual.weight = getWeight(actual); posibles.Add(actual); while (posibles.Any()) { actual = posibles.First(); // Console.WriteLine("\nActual: "); // printGame(actual.data); // Console.WriteLine("Weight: " + actual.weight); // Console.WriteLine("Steps: " + actual.steps + "\n"); Console.SetCursorPosition(0, Console.CursorTop); Console.Write(new string(' ', Console.BufferWidth)); Console.SetCursorPosition(0, Console.CursorTop - 3); Console.WriteLine("Best steps: " + actual.steps); Console.WriteLine("Attempted: " + alreadyVisited.Count()); if (getWrong(actual.data) == 0) { break; } string dataString = actual.dataString(); alreadyVisited.Add(dataString); // Console.WriteLine(dataString); // Console.WriteLine("Getting neighbors"); foreach (MiniArea neighbor in actual.getNeighbors()) { if (!alreadyVisited.Contains( neighbor.dataString())) { // Console.WriteLine("The neighbor is not in the visited list"); neighbor.weight = getWeight(neighbor); // Console.WriteLine("neighbor.weight: " + neighbor.weight); posibles.Add(neighbor); } else { // Console.WriteLine("The neighbor is in the visited list"); } } posibles.Remove(actual); posibles.Sort(orderWeights); /*Console.WriteLine("\n-------- ALREADY VISITED LIST ---------"); * for (int i = 0; i < alreadyVisited.Count; i++) * { * Console.WriteLine(alreadyVisited[i]); * } * Console.WriteLine("\n---------------------------------------"); * * Console.WriteLine("\n------------ POSIBLES LIST ------------"); * for (int i = 0; i<posibles.Count; i++) * { * printGame(posibles[i].data); * Console.WriteLine(); * } * Console.WriteLine("\n---------------------------------------");*/ } Console.WriteLine("\n\nPath: \n"); recreatePath(actual); Console.WriteLine("\nVictory with {0} steps\n", actual.steps); }
static int getWeight(MiniArea actual) { return(actual.steps + getWrong(actual.data)); }