Skip to content
Snippets Groups Projects
Commit dcd14b4e authored by Floris's avatar Floris
Browse files

Merge branch 'Binair' of https://git.science.uu.nl/8783497/puzzleplayer into Binair

parents 1c9942b0 a0c1c187
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,13 @@ using System.Windows.Forms; ...@@ -8,6 +8,13 @@ using System.Windows.Forms;
namespace PuzzlePlayer_Namespace namespace PuzzlePlayer_Namespace
{ {
public enum SOLUTIONS
{
NONE = 0,
UNIQUE = 1,
MULTIPLE = 2
}
/* /*
* This abstract class can be used to implement any kind of puzzle * This abstract class can be used to implement any kind of puzzle
* One thing that is common for all puzzles is that a empty space is equal to -1 * One thing that is common for all puzzles is that a empty space is equal to -1
...@@ -22,14 +29,28 @@ namespace PuzzlePlayer_Namespace ...@@ -22,14 +29,28 @@ namespace PuzzlePlayer_Namespace
public int[,] boardState public int[,] boardState
{ {
get { return boardState; } get { return boardState; }
set { if (IsBoardValid(value) && Solve(value) != null) boardState = value; } // checks if the board is valid and solvable before setting the variable. set { setBoardState(value); }
}
// checks if the board is valid and solvable before setting the variable.
private bool setBoardState(int[,] newState)
{
int[,] copy = boardState;
boardState = newState;
if (IsBoardValid(newState) && Solve() == SOLUTIONS.UNIQUE)
return true;
else
{
boardState = copy;
return false;
}
} }
// a methode for solving the whole board. It uses the private SolveStep methode untill the whole board is solved // a methode for solving the whole board. It uses the private SolveStep methode untill the whole board is solved
public Board Solve() public SOLUTIONS Solve()
{ {
// two variables for storing the result and the next solveStep // two variables for storing the result and the next solveStep
int[,] result = boardToSolve; int[,] result = boardState;
int[,] step; int[,] step;
// keep looping until the SolveStep returns null // keep looping until the SolveStep returns null
...@@ -44,9 +65,12 @@ namespace PuzzlePlayer_Namespace ...@@ -44,9 +65,12 @@ namespace PuzzlePlayer_Namespace
for (int i = 0; i < result.GetLength(0); i++) for (int i = 0; i < result.GetLength(0); i++)
for (int j = 0; j < result.GetLength(1); j++) for (int j = 0; j < result.GetLength(1); j++)
if (result[i, j] == emptySpace) if (result[i, j] == emptySpace)
return null; {
return SOLUTIONS.NONE;
}
return result; boardState = result;
return SOLUTIONS.UNIQUE;
} }
// abstract methode for solving one step // abstract methode for solving one step
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment