diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs index 730c4f5fd1c20ef9c19c4bd19e626c8a72ca9336..d1ec58b73cb97c4657a04120bf59438753c027d7 100644 --- a/PuzzlePlayer/Binary.cs +++ b/PuzzlePlayer/Binary.cs @@ -129,22 +129,17 @@ namespace PuzzlePlayer_Namespace // save the generated board for testing the users solution and the use of a reset button lastGeneratedBoard = (int[,])boardState.Clone(); } - + /* public override void Hint() { int row; int col; - //boardLength = (int)Math.Sqrt(boardState.Length); while (true) { row = RandomNumber(boardLength) - 1; col = RandomNumber(boardLength) - 1; - //row = (int)Math.Floor((double)(random.NextDouble() * 6 + 1)) - 1; - //col = (int)Math.Floor((double)(random.NextDouble() * 6 + 1)) - 1; - - Debug.WriteLine(row + "," + col); if (boardState[row, col] == emptySpace) { @@ -153,7 +148,7 @@ namespace PuzzlePlayer_Namespace } } } - + */ private static void PrintBoard(int[,] board) { for (int i = 0; i < board.GetLength(0); i++) diff --git a/PuzzlePlayer/Board.cs b/PuzzlePlayer/Board.cs index 97bb3b55926c51002b7f025f6a9df289069f2b07..5b4d5a50afb1067b13943e822155ad353c41624d 100644 --- a/PuzzlePlayer/Board.cs +++ b/PuzzlePlayer/Board.cs @@ -100,9 +100,25 @@ namespace PuzzlePlayer_Namespace return SOLUTIONS.UNIQUE; } - // abstract methode for solving one step - public abstract void Hint(); - + // virtual method for solving one step + public virtual void Hint() + { + int row; + int col; + + while (true) + { + row = RandomNumber(boardLength) - 1; + col = RandomNumber(boardLength) - 1; + + if (boardState[row, col] == emptySpace) + { + boardState[row, col] = solution[row, col]; + break; + } + } + } + public virtual int RandomNumber(int number) { Debug.WriteLine(number); diff --git a/PuzzlePlayer/Maze.cs b/PuzzlePlayer/Maze.cs index 254d452a2072416d9965f1976358300be24b7cf0..071388879d05494e41e17149482ec5ccf69ee7cf 100644 --- a/PuzzlePlayer/Maze.cs +++ b/PuzzlePlayer/Maze.cs @@ -167,8 +167,23 @@ namespace PuzzlePlayer_Namespace public override void Hint() { - // + shortestPath = new List<Point>(); + visitedCells = GetClearBoard(mazeState.GetLength(0), mazeState.GetLength(1)); + + shortestPath.Add(new Point(0, 0)); + bool foundSolution = Recursive_DepthFirstSearchMazeSolve(0, 0); + if (foundSolution) + { + foreach (Point step in shortestPath) + { + if (boardState[step.X, step.Y] == emptySpace) + { + boardState[step.X, step.Y] = 1; + break; + } + } + } } private bool Recursive_DepthFirstSearchMazeGenerator(int x, int y) diff --git a/PuzzlePlayer/Sudoku.cs b/PuzzlePlayer/Sudoku.cs index fbb3d95292d7633a4bb3b9ebc69d282bb99ca8d4..c4757f8d8d789f9ca3c11bbb39d4a36c5bfafbf1 100644 --- a/PuzzlePlayer/Sudoku.cs +++ b/PuzzlePlayer/Sudoku.cs @@ -13,7 +13,7 @@ namespace PuzzlePlayer_Namespace internal class Sudoku : Board { private static int rootBoardLength; - public Sudoku(int boardSize = 9) + public Sudoku(int boardSize = 16) { boardState = GetClearBoard(boardSize, boardSize); lastGeneratedBoard = GetClearBoard(boardSize, boardSize); @@ -110,7 +110,7 @@ namespace PuzzlePlayer_Namespace lastGeneratedBoard = (int[,])boardState.Clone(); } - + /* public override void Hint() { int row; @@ -128,7 +128,7 @@ namespace PuzzlePlayer_Namespace } } } - + */ public override SOLUTIONS Solve(bool b) { if (SolveSudoku())