Skip to content
Snippets Groups Projects
Commit a0c1c187 authored by bionic85's avatar bionic85
Browse files

added enum

parent c32dc198
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,13 @@ using System.Windows.Forms;
namespace PuzzlePlayer_Namespace
{
public enum SOLUTIONS
{
NONE = 0,
UNIQUE = 1,
MULTIPLE = 2
}
/*
* 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
......@@ -22,14 +29,28 @@ namespace PuzzlePlayer_Namespace
public int[,] 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
public Board Solve()
public SOLUTIONS Solve()
{
// two variables for storing the result and the next solveStep
int[,] result = boardToSolve;
int[,] result = boardState;
int[,] step;
// keep looping until the SolveStep returns null
......@@ -44,9 +65,12 @@ namespace PuzzlePlayer_Namespace
for (int i = 0; i < result.GetLength(0); i++)
for (int j = 0; j < result.GetLength(1); j++)
if (result[i, j] == emptySpace)
return null;
{
return SOLUTIONS.NONE;
}
return result;
boardState = result;
return SOLUTIONS.UNIQUE;
}
// 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