diff --git a/PuzzlePlayer/Board.cs b/PuzzlePlayer/Board.cs index 0e4778440090d4734f9ae8992bb41d7263e011a8..b7a1fe1b43225910b58144b76aeca65e81dbb626 100644 --- a/PuzzlePlayer/Board.cs +++ b/PuzzlePlayer/Board.cs @@ -60,19 +60,6 @@ namespace PuzzlePlayer_Namespace } - // checks if the board is valid and solvable before setting the variable. - public bool setBoardState(int[,] newState) - { - int[,] copy = boardState; - boardState = newState; - if (IsBoardValid(newState) && Solve(false) == SOLUTIONS.UNIQUE) - return true; - else - { - boardState = copy; - return false; - } - } public abstract void Draw(Graphics gr, Rectangle r); @@ -109,20 +96,7 @@ namespace PuzzlePlayer_Namespace } // abstract methode for solving one step - private Move? SolveStep(int[,] currentBoardState) - { - // get a list with all the possible moves - List<Move> moves = GetSolveList(currentBoardState); - - // if there are no moves found then null is returned - if (moves.Count == 0) - return null; - - // return one of the possible moves - // (if the first one is always chosen than that may lead to expected behavior. For example if the possible moves are checked in a certain order) - Random rnd = new Random(); - return moves[rnd.Next(0, moves.Count - 1)]; - } + public virtual Point Hint() { return new Point(0, 0); } // a abstract methode to get a list of all possible moves protected abstract List<Move> GetSolveList(int[,] boardToSolve); diff --git a/PuzzlePlayer/PuzzleForm.cs b/PuzzlePlayer/PuzzleForm.cs index 76746ba1b5db718d6611b61e7a96c91a67aabba2..ea1fed3cc2ac720c163a5e193028cc727c5a308b 100644 --- a/PuzzlePlayer/PuzzleForm.cs +++ b/PuzzlePlayer/PuzzleForm.cs @@ -12,17 +12,16 @@ namespace PuzzlePlayer_Namespace { internal class PuzzleForm : Form { - public readonly string puzzleType; private readonly Button solvebutton; private readonly Button hintbutton; private readonly Button generatebutton; private readonly Button restartbutton; + private readonly Button UPDATEBUTTON; private readonly Label titlebox; private readonly Label informationbox; private Rectangle boardspace; private readonly MenuStrip menuStrip; private readonly ToolStripMenuItem menuSettings; - private readonly BufferedGraphics bufferedGraphics; private Board board; public Board Board //updating the Board member will immediately call board.Draw method so that the board is updated visually @@ -34,9 +33,7 @@ namespace PuzzlePlayer_Namespace this.Invalidate(); } } - - private readonly Button UPDATEBUTTON; - + public readonly string puzzleType; public PuzzleForm(Board b, Size s = default) //takes Board and Size parameter and sets up the PuzzleForm window. { @@ -100,7 +97,6 @@ namespace PuzzlePlayer_Namespace TextAlign = ContentAlignment.BottomRight, Font = SettingForm.mainFont, }; - menuStrip.Items.Add(menuSettings); this.Controls.Add(menuStrip); @@ -199,12 +195,12 @@ namespace PuzzlePlayer_Namespace private void UpdateUI() //resizes the boardspace rectangle and updates the rest of the ui around the new boardspace size { bufferedGraphics.Graphics.Clear(this.BackColor); - boardspace.Size = FitBoard(new Size(Board.boardState.GetLength(0), Board.boardState.GetLength(1)), new Size(this.Width - 350, this.Height - 125), Board.drawFactor); - generatebutton.Location = new Point(boardspace.Right + 30, 55); - hintbutton.Location = new Point(boardspace.Right + 30, 135); - solvebutton.Location = new Point(boardspace.Right + 30, 215); - restartbutton.Location = new Point(boardspace.Right + 30, 295); - UPDATEBUTTON.Location = new Point(boardspace.Right + 30, 375); + boardspace.Size = FitBoard(new Size(Board.boardState.GetLength(0), Board.boardState.GetLength(1)), new Size(this.Width - 350, this.Height - 100), Board.drawFactor); + generatebutton.Location = new Point(boardspace.Right + 30, 30); + hintbutton.Location = new Point(boardspace.Right + 30, 110); + solvebutton.Location = new Point(boardspace.Right + 30, 190); + restartbutton.Location = new Point(boardspace.Right + 30, 270); + UPDATEBUTTON.Location = new Point(boardspace.Right + 30, 350); this.Invalidate(); } public static Size FitBoard(Size gamesize, Size maxboardsize, int drawfactor) //returns the largest rectangle smaller than MaxBoardSize that fits the given GameSize well @@ -251,7 +247,7 @@ namespace PuzzlePlayer_Namespace return; } Point tile = GetTile(new Size(Board.boardState.GetLength(0), Board.boardState.GetLength(1)), boardspace, Control.MousePosition); - if (!(tile.X >= 0 && tile.X < Board.boardState.GetLength(0) && tile.Y >= 0 && tile.Y < Board.boardState.GetLength(1))) return; //if tile is in bounds + if (!(tile.X >= 0 && tile.X < Board.boardState.GetLength(0) && tile.Y >= 0 && tile.Y < Board.boardState.GetLength(1))) return; //if tile is out of bounds if (!(Board.lastGeneratedBoard[tile.X, tile.Y] == Board.emptySpace)) return; //if tile is a given switch (k) { diff --git a/PuzzlePlayer/Skyscrapers.cs b/PuzzlePlayer/Skyscrapers.cs new file mode 100644 index 0000000000000000000000000000000000000000..b38470d632595a3983839ef42280d78a53142aed --- /dev/null +++ b/PuzzlePlayer/Skyscrapers.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Text; +using System.IO; +using System.Linq; +using System.Security.Cryptography.Xml; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Windows.Forms.Design; +using System.Windows.Forms.VisualStyles; + +namespace PuzzlePlayer_Namespace +{ + internal class Skyscrapers : Board + { + public int[,] visionState; + public string[,] candidateState; + public Skyscrapers(int boardSize = 6) + { + boardState = GetClearBoard(boardSize + 2); + lastGeneratedBoard = GetClearBoard(boardSize + 2); + candidateState = new string[boardSize + 2, boardSize + 2]; + description = "lol"; + drawFactor = 1; + candidateState[1, 1] = "123"; + candidateState[2, 3] = "1734"; + candidateState[4, 4] = "123456789"; + boardState[1, 1] = 1; + boardState[2, 2] = 2; + boardState[3, 3] = 3; + boardState[4, 4] = 4; + } + public override void Draw(Graphics gr, Rectangle r) + { + Size tilesize = new Size(r.Width / boardState.GetLength(0), r.Height / boardState.GetLength(1)); + int stringsize = Math.Min(tilesize.Height / 2, tilesize.Width); + StringFormat stringFormat = new StringFormat(); + stringFormat.LineAlignment = StringAlignment.Center; + stringFormat.Alignment = StringAlignment.Center; + gr.FillRectangle(Brushes.Beige, r.X + tilesize.Width, r.Y + tilesize.Height, r.Width - 2 * tilesize.Width, r.Height - 2 * tilesize.Height); + for (int i = 0; i < boardState.GetLength(0); i++) + { + for (int j = 0; j < boardState.GetLength(1); j++) + { + if (i == 0 || i == boardState.GetLength(0) - 1 || j == 0 || j == boardState.GetLength(1) - 1) + { + if (boardState[i, j] != emptySpace) + { + gr.DrawString(Convert.ToString(boardState[i, j]), + new Font("Verdana", stringsize / 2), + Brushes.Black, + (int)(r.X + ((double)i + 0.5) * tilesize.Width), + (int)(r.Y + ((double)j + 0.5) * tilesize.Height), + stringFormat); + } + } + else + { + gr.DrawRectangle(Pens.DarkGray, + r.X + i * tilesize.Width, + r.Y + j * tilesize.Height, + tilesize.Width, + tilesize.Height); + if (boardState[i, j] != emptySpace) + { + gr.DrawString(Convert.ToString(boardState[i, j]), + new Font("Verdana", stringsize), + Brushes.Black, + (int)(r.X + ((double)i + 0.5) * tilesize.Width), + (int)(r.Y + ((double)j + 0.5) * tilesize.Height), + stringFormat); + } + else + { + if (candidateState[i, j] == null) continue; + foreach (char c in candidateState[i, j]) + { + gr.DrawString(Convert.ToString(c), + new Font("Verdana", stringsize / 3), + Brushes.Black, + (int)(r.X + ((double)i + 0.25 * ((char.GetNumericValue(c) - 1) % 3 + 1)) * tilesize.Width), + (int)(r.Y + ((double)j + 0.25 * Math.Ceiling(char.GetNumericValue(c) / 3)) * tilesize.Height), + stringFormat); + } + } + } + } + } + } + + public override SOLUTIONS Solve(bool CheckOnly) + { + return SOLUTIONS.NONE; + } + + public override void Generate() + { + + } + + public override void TileInput(Point? p, Keys k) + { + if (p == null) return; + double center = ((double)boardState.GetLength(0) - 1) / 2; + if (Math.Abs(((Point)p).X - center) == center && Math.Abs(((Point)p).Y - center) == center) return; + int num = (int)k - 48; + if (num > 0 && num <= boardState.GetLength(0) - 2) boardState[((Point)p).X, ((Point)p).Y] = num; + } + + protected override List<Move> GetSolveList(int[,] boardToSolve) + { + return new List<Move>(); + } + } +}