diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs index 5389e42cb94bacdbbaaea08f0dc5ac61f04cfcac..2f10fd993593af33b70de139a5eba1c303acd595 100644 --- a/PuzzlePlayer/Binary.cs +++ b/PuzzlePlayer/Binary.cs @@ -20,8 +20,8 @@ namespace PuzzlePlayer_Namespace // constructor with boardSize parameter (default is set to 8 but can be changed) public Binary(int boardSize = 6) // should be even { - boardState = GetClearBoard(boardSize); - lastGeneratedBoard = GetClearBoard(boardSize); + boardState = GetClearBoard(boardSize,boardSize); + lastGeneratedBoard = GetClearBoard(boardSize, 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"; @@ -89,7 +89,7 @@ namespace PuzzlePlayer_Namespace int[,] generatedBoard; //generates a board starting with an empty board and a empty HashSet - while ((generatedBoard = BackTrackAlgorithm(GetClearBoard(boardState.GetLength(0)), new HashSet<string>())) == null) + while ((generatedBoard = BackTrackAlgorithm(GetClearBoard(boardState.GetLength(0), boardState.GetLength(1)), new HashSet<string>())) == null) { counter++; Debug.WriteLine($"board is null....trying for the {counter} time"); diff --git a/PuzzlePlayer/Board.cs b/PuzzlePlayer/Board.cs index a18ffc62ae05e86e9fdd474fa86f0e523f2099e9..22c6bc4d4997a0008766c5b65a9f384d4059d966 100644 --- a/PuzzlePlayer/Board.cs +++ b/PuzzlePlayer/Board.cs @@ -46,13 +46,13 @@ namespace PuzzlePlayer_Namespace public int[,] lastGeneratedBoard; // static meathode for filling a int[,] with -1 - public static int[,] GetClearBoard(int boardSize) + public static int[,] GetClearBoard(int boardSizeX, int boardSizeY) { - int[,] result = new int[boardSize, boardSize]; + int[,] result = new int[boardSizeX, boardSizeY]; // fill the board with empty spaces (-1) - for (int i = 0; i < boardSize; i++) + for (int i = 0; i < boardSizeX; i++) { - for (int j = 0; j < boardSize; j++) + for (int j = 0; j < boardSizeY; j++) result[i, j] = emptySpace; } diff --git a/PuzzlePlayer/Maze.cs b/PuzzlePlayer/Maze.cs index 82af376f77fa8249426ca4962c29c3bbe4bcf3cb..819473ccc0ddf5cbeb1ab9ba74b0c1af398f65a9 100644 --- a/PuzzlePlayer/Maze.cs +++ b/PuzzlePlayer/Maze.cs @@ -40,21 +40,21 @@ namespace PuzzlePlayer_Namespace Point playerPos; List<Point> shortestPath; - public Maze(int size = 20) + public Maze(int sizeX = 30, int sizeY = 20) { drawFactor = 1; // init all 2D array's - Reset(size); - lastGeneratedBoard = GetClearBoard(size); + Reset(sizeX, sizeY); + lastGeneratedBoard = GetClearBoard(sizeX, sizeY); description = "The maze is played on a square grid where each cells has walls. You need to navigate through the maze until you reach the end. Use the arrow keys or WASD to move the blue square to the end goal"; } - private void Reset(int size) + private void Reset(int sizeX, int sizeY) { - boardState = GetClearBoard(size); - mazeState = GetClearBoard(size); - visitedCells = GetClearBoard(size); + boardState = GetClearBoard(sizeX, sizeY); + mazeState = GetClearBoard(sizeX, sizeY); + visitedCells = GetClearBoard(sizeX, sizeY); playerPos = new Point(0,0); } @@ -96,7 +96,7 @@ namespace PuzzlePlayer_Namespace public override void Draw(Graphics gr, Rectangle r) { // clear screen - gr.FillRectangle(Brushes.Wheat, r); + gr.FillRectangle(Brushes.GhostWhite, r); Size tilesize = new Size(r.Width / boardState.GetLength(0), r.Height / boardState.GetLength(1)); Pen wall = new Pen(Color.Black, tilesize.Width / 5); @@ -119,9 +119,6 @@ namespace PuzzlePlayer_Namespace if(i == playerPos.X && j == playerPos.Y) gr.FillRectangle(Brushes.DarkBlue, currentRect); - // draw board outline - gr.DrawRectangle(Pens.LightGray,currentRect); - // drawing walls (bool top,bool right,bool bottom,bool left) = getWallsFromNumber(mazeState[i,j]); @@ -146,11 +143,11 @@ namespace PuzzlePlayer_Namespace public override void Generate() { //clear the board and all 2D array's - Reset(mazeState.GetLength(0)); + Reset(mazeState.GetLength(0), mazeState.GetLength(1)); Random rnd = new Random(); int x = rnd.Next(mazeState.GetLength(0)); - int y = rnd.Next(mazeState.GetLength(0)); + int y = rnd.Next(mazeState.GetLength(1)); if (Recursive_DepthFirstSearchMazeGenerator(x, y)) Debug.WriteLine("Maze succesfully generated"); @@ -270,8 +267,8 @@ namespace PuzzlePlayer_Namespace // don't have much in common in regards to solving. So most of the code in the abstract Board class is to no use for us here public override SOLUTIONS Solve(bool CheckOnly) { - visitedCells = GetClearBoard(mazeState.GetLength(0)); - boardState = GetClearBoard(mazeState.GetLength(0)); + visitedCells = GetClearBoard(mazeState.GetLength(0), mazeState.GetLength(1)); + boardState = GetClearBoard(mazeState.GetLength(0), mazeState.GetLength(1)); shortestPath = new List<Point>(); shortestPath.Add(new Point(0,0)); // starting point @@ -360,13 +357,6 @@ namespace PuzzlePlayer_Namespace return false; } - // this methode is not needed because we write our own Solve methode - protected override List<Move> GetSolveList(int[,] boardToSolve) - { - return null; - } - - public override void TileInput(Point? p, Keys key) { boardState[playerPos.X, playerPos.Y] = 1; //dw @@ -400,9 +390,16 @@ namespace PuzzlePlayer_Namespace boardState[playerPos.X, playerPos.Y] = 1; } - public override void TileClick(Point p, int x) + public override void Restart() { - //MessageBox.Show($"{mazeState[p.X, p.Y]}"); + base.Restart(); + playerPos = new Point(0, 0); + } + + // this methode is not needed because we write our own Solve methode + protected override List<Move> GetSolveList(int[,] boardToSolve) + { + return null; } } } diff --git a/PuzzlePlayer/Resources/Maze.jpg b/PuzzlePlayer/Resources/Maze.jpg index ce6a967411e1676e96c8f2b5abea3e0172953c72..85d6ddf757fb62795233e8b02f513b9f34369daf 100644 Binary files a/PuzzlePlayer/Resources/Maze.jpg and b/PuzzlePlayer/Resources/Maze.jpg differ diff --git a/PuzzlePlayer/Resources/MazeGray.jpg b/PuzzlePlayer/Resources/MazeGray.jpg index ce6a967411e1676e96c8f2b5abea3e0172953c72..cbb5fd7b82b3c85bf6208e0d461f8e252561167b 100644 Binary files a/PuzzlePlayer/Resources/MazeGray.jpg and b/PuzzlePlayer/Resources/MazeGray.jpg differ