From 52029417226f312a2963862384c4ffb527ff01a0 Mon Sep 17 00:00:00 2001
From: DamianKomdeur <77113617+DamianKomdeur@users.noreply.github.com>
Date: Wed, 8 Jan 2025 14:07:27 +0100
Subject: [PATCH] Hint for binary and sudoku

^^
---
 PuzzlePlayer/Binary.cs       | 29 ++++++++++++++++++++++++++---
 PuzzlePlayer/Board.cs        | 13 ++++++++++++-
 PuzzlePlayer/Maze.cs         |  6 ++++++
 PuzzlePlayer/Minesweeper.cs  |  6 ++++--
 PuzzlePlayer/PuzzleForm.cs   |  2 +-
 PuzzlePlayer/PuzzlePlayer.cs |  2 +-
 PuzzlePlayer/Skyscrapers.cs  |  5 +++++
 PuzzlePlayer/Sudoku.cs       | 29 +++++++++++++++++++++--------
 8 files changed, 76 insertions(+), 16 deletions(-)

diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs
index 5f32718..730c4f5 100644
--- a/PuzzlePlayer/Binary.cs
+++ b/PuzzlePlayer/Binary.cs
@@ -5,6 +5,7 @@ using System.Drawing;
 using System.Linq;
 using System.Runtime.CompilerServices;
 using System.Windows.Forms;
+using static System.Runtime.InteropServices.JavaScript.JSType;
 
 namespace PuzzlePlayer_Namespace
 { 
@@ -22,10 +23,11 @@ namespace PuzzlePlayer_Namespace
         {
             boardState = GetClearBoard(boardSize,boardSize);
             lastGeneratedBoard = GetClearBoard(boardSize, boardSize);
-
+            boardLength = boardSize;
 
             description = "Binary puzzle is played on any even-numbered square grid, with some cells initially containing black or white circles. The goal of the puzzle is to fill all cells such that:\r\n● More than two circles of the same color cannot be adjacent\r\n● Each row and column must contain an equal number of black and white circles";
             drawFactor = 8;
+
             // clear the board (fill it in with -1)
             //Clear(false);
         }
@@ -128,7 +130,29 @@ namespace PuzzlePlayer_Namespace
             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)
+                {
+                    boardState[row, col] = solution[row, col];
+                    break;
+                }
+            }
+        }
 
         private static void PrintBoard(int[,] board)
         {
@@ -472,6 +496,5 @@ namespace PuzzlePlayer_Namespace
             }
             return false;
         }
-
     }
 }
\ No newline at end of file
diff --git a/PuzzlePlayer/Board.cs b/PuzzlePlayer/Board.cs
index 0be6bef..97bb3b5 100644
--- a/PuzzlePlayer/Board.cs
+++ b/PuzzlePlayer/Board.cs
@@ -6,6 +6,7 @@ using System.Reflection.Metadata;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using System.Diagnostics;
 
 namespace PuzzlePlayer_Namespace
 {
@@ -46,6 +47,9 @@ namespace PuzzlePlayer_Namespace
         public int[,] lastGeneratedBoard;
         public int[,] solution;
 
+        public int boardLength;
+        public static Random random = new Random();
+
         // static meathode for filling a int[,] with -1
         public static int[,] GetClearBoard(int boardSizeX, int boardSizeY)
         {
@@ -97,7 +101,14 @@ namespace PuzzlePlayer_Namespace
         }
 
         // abstract methode for solving one step
-        public virtual Point Hint() { return new Point(0, 0); }
+        public abstract void Hint();
+       
+        public virtual int RandomNumber(int number)
+        {
+            Debug.WriteLine(number);
+            return (int)Math.Floor((double)(random.NextDouble() * number + 1));
+        }
+
 
         // a abstract methode to get a list of all possible moves
         protected virtual List<Move> GetSolveList(int[,] boardToSolve)
diff --git a/PuzzlePlayer/Maze.cs b/PuzzlePlayer/Maze.cs
index e533f65..254d452 100644
--- a/PuzzlePlayer/Maze.cs
+++ b/PuzzlePlayer/Maze.cs
@@ -165,6 +165,12 @@ namespace PuzzlePlayer_Namespace
             
         }
 
+        public override void Hint()
+        {
+            //
+
+        }
+
         private bool Recursive_DepthFirstSearchMazeGenerator(int x, int y)
         {
             visitedCells[x, y] = 1; // mark current cell as visited (this is needed for the first cell)
diff --git a/PuzzlePlayer/Minesweeper.cs b/PuzzlePlayer/Minesweeper.cs
index ce7dabe..a855acf 100644
--- a/PuzzlePlayer/Minesweeper.cs
+++ b/PuzzlePlayer/Minesweeper.cs
@@ -12,8 +12,6 @@ namespace PuzzlePlayer_Namespace
 {
     internal class Minesweeper : Board
     {
-
-        private static Random random = new Random();
         private bool[,] mineState;
         private bool isFirstClick;
         public Minesweeper(int width = 30, int height = 16)
@@ -82,6 +80,10 @@ namespace PuzzlePlayer_Namespace
             isFirstClick = true;
         }
 
+        public override void Hint()
+        {
+            //
+        }
         public override SOLUTIONS Solve(bool b)
         {
             return SOLUTIONS.UNIQUE;
diff --git a/PuzzlePlayer/PuzzleForm.cs b/PuzzlePlayer/PuzzleForm.cs
index 2f0bf48..343eca1 100644
--- a/PuzzlePlayer/PuzzleForm.cs
+++ b/PuzzlePlayer/PuzzleForm.cs
@@ -144,7 +144,7 @@ namespace PuzzlePlayer_Namespace
             hintbutton.Text = "Hint";
             hintbutton.MouseClick += (object sender, MouseEventArgs mea) =>
             {
-                MessageBox.Show("Hint: geef op");
+                Board.Hint();
                 this.Invalidate();
             };
             CreateButton(solvebutton);
diff --git a/PuzzlePlayer/PuzzlePlayer.cs b/PuzzlePlayer/PuzzlePlayer.cs
index cb920c4..b9d14b8 100644
--- a/PuzzlePlayer/PuzzlePlayer.cs
+++ b/PuzzlePlayer/PuzzlePlayer.cs
@@ -10,7 +10,7 @@ namespace PuzzlePlayer_Namespace
     {
         internal static void Main(string[] args)
         {
-            Application.Run(new PuzzleForm(new Minesweeper()));
+            Application.Run(new MainForm());
         }
     }
 
diff --git a/PuzzlePlayer/Skyscrapers.cs b/PuzzlePlayer/Skyscrapers.cs
index a1e0784..122572c 100644
--- a/PuzzlePlayer/Skyscrapers.cs
+++ b/PuzzlePlayer/Skyscrapers.cs
@@ -101,6 +101,11 @@ namespace PuzzlePlayer_Namespace
 
         }
 
+        public override void Hint()
+        {
+            //
+        }
+
         public override bool TileInput(Point? p, Keys k)
         {
             if (p == null) return false;
diff --git a/PuzzlePlayer/Sudoku.cs b/PuzzlePlayer/Sudoku.cs
index ebfb05b..fbb3d95 100644
--- a/PuzzlePlayer/Sudoku.cs
+++ b/PuzzlePlayer/Sudoku.cs
@@ -12,10 +12,8 @@ namespace PuzzlePlayer_Namespace
 {
     internal class Sudoku : Board
     {
-        private static int boardLength;
         private static int rootBoardLength;
-        private static Random random = new Random();
-        public Sudoku(int boardSize = 4)
+        public Sudoku(int boardSize = 9)
         {
             boardState = GetClearBoard(boardSize, boardSize);
             lastGeneratedBoard = GetClearBoard(boardSize, boardSize);
@@ -113,6 +111,24 @@ namespace PuzzlePlayer_Namespace
             lastGeneratedBoard = (int[,])boardState.Clone();
         }
 
+        public override 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 override SOLUTIONS Solve(bool b)
         {
             if (SolveSudoku())
@@ -122,11 +138,6 @@ namespace PuzzlePlayer_Namespace
             return SOLUTIONS.NONE;
         }
 
-        private int RandomNumber(int number)
-        {
-            return (int)Math.Floor((double)(random.NextDouble() * number + 1));
-        }
-
         private void FillBox(int row, int col)
         {
             int num;
@@ -220,6 +231,8 @@ namespace PuzzlePlayer_Namespace
             return true;
         }
 
+
+
         private static string BoardToString(int[,] board)
         {
             string result = "";
-- 
GitLab