diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs index 5f3271810fbaeff380489691771fba7be00d33c5..730c4f5fd1c20ef9c19c4bd19e626c8a72ca9336 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 0be6bef34576f9cb4664eb456292f74e94fa08e2..97bb3b55926c51002b7f025f6a9df289069f2b07 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 e533f65c0049fa74419d86a46f43c6c261e94e32..254d452a2072416d9965f1976358300be24b7cf0 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 ce7dabeb771e24c560102bc19c76ca2020fdaf70..a855acf48adecfa3254752906995c22a58efaa97 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 2f0bf489e3caffe4bdc540cd324c1fbd801aff77..343eca1fe44ebdbef7b69009ad1dbebadec065e8 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 cb920c42ec577e9612680ecee48ab146094b8b48..b9d14b88f22c093067b32182f29586aef7c4a8e6 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 a1e07844e71978d40386202fe9ae2feb4bcb9097..122572c6c5f924146baf8cac9cabdaa677e9f628 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 ebfb05beb9e66cb2db9b4310198b2d88fb8a483f..fbb3d95292d7633a4bb3b9ebc69d282bb99ca8d4 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 = "";