From be0a97fe46725b8b62957dd9f68dbc6ebad89f10 Mon Sep 17 00:00:00 2001
From: DamianKomdeur <77113617+DamianKomdeur@users.noreply.github.com>
Date: Mon, 13 Jan 2025 10:52:33 +0100
Subject: [PATCH] Maze hint

Maze hint
---
 PuzzlePlayer/Binary.cs |  9 ++-------
 PuzzlePlayer/Board.cs  | 22 +++++++++++++++++++---
 PuzzlePlayer/Maze.cs   | 17 ++++++++++++++++-
 PuzzlePlayer/Sudoku.cs |  6 +++---
 4 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs
index 730c4f5..d1ec58b 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 97bb3b5..5b4d5a5 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 254d452..0713888 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 fbb3d95..c4757f8 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())
-- 
GitLab