public void InitializeTiles() { String buttonName = ""; int faceValueCounter = 0; tileGrid = new TileGrid(); // Create ASharpSolverInstance to use checkSolvabilty function ASharpSolver solver = new ASharpSolver(); tileGrid.faceValues = getRandomizedFaceValues(tileGrid.faceValues); // Iterate through 2d grid array to instantiate new tiles for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { buttonName = "tile" + x.ToString() + y.ToString(); // Instantiate new tile and add to the grid Tile newTile = new Tile(tileGrid.faceValues[faceValueCounter], x, y, buttonName); tileGrid.tileGridArray[x, y] = newTile; faceValueCounter++; } } // Recall function if current grid is unsolvable : odd number of inversions if (!solver.CheckSolvability(tileGrid)) { InitializeTiles(); } }
private void button1_Click(object sender, EventArgs e) { ASharpSolver aSharpSolver = new ASharpSolver(tileGrid, targetCoordinatesList); List <BoardState> solution = aSharpSolver.SeekSolution(); if (solution != null) { solution.Reverse(); foreach (BoardState boardState in solution) { System.Threading.Thread.Sleep(150); BindTileGridToUI(boardState.tileGridState); } } else { MessageBox.Show("No Result found, reload please"); } }