private void btnSolve_Click(object sender, RoutedEventArgs e) { int steps = 0; _solver = new Solver( new GameSuccessorNodesGenerator(), new GameGValueCalculator(), new GameHValueCalulator()); var start = new GameNode { Tiles = blocks.stringBoard() }; NodeInterface result = _solver.Execute(start, Goal); var stack = new Stack<NodeInterface>(); do { stack.Push(result); } while ((result = result.ParentNode) != null); new Thread(() => { foreach (var node in stack) { //The invoke only needs to be used when updating GUI Elements this.Dispatcher.Invoke((MethodInvoker)delegate { //Everything inside of this Invoke runs on the GUI Thread int[,] unstrung = node.unstringNode(node); // turns node of int[] into board of int[,] blocks.setBoard(unstrung); // sets the board to pass in to the GUI DrawBoard(); // Takes the board (int[,]) and sets the squares on the GUI to match it. txtSteps.Text = "Steps: " + steps; steps++; }); Thread.Sleep(500); } }).Start(); }
private static int GetEmptyTilePosition(GameNode node) { int emptyTilePos = -1; for (int i = 0; i < 9; i++) { if (node.Tiles[i] == 0) { emptyTilePos = i; break; } } return emptyTilePos; }
public static int[] getNode(GameNode node) { return node.Tiles; }