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

small things

parent a56ff07b
No related branches found
No related tags found
No related merge requests found
......@@ -71,26 +71,9 @@ namespace PuzzlePlayer_Namespace
throw new NotImplementedException();
}
protected override int[,] SolveStep(int[,] currentBoardState)
protected override List<int[,]> GetSolveList(int[,] boardToSolve)
{
// list with all the possible moves
List<int[,]> moves = new List<int[,]>();
int[,] result = currentBoardState;
// generate all possible moves
//TODO
throw new NotImplementedException();
// if there are no moves found then null is returned
if (moves.Count == 0)
return null;
// return one of the possible moves
Random rnd = new Random();
return moves[rnd.Next(0, moves.Count - 1)];
}
}
}
......@@ -11,6 +11,7 @@ namespace PuzzlePlayer_Namespace
/*
* 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
* GetSolveList and IsBoardValid need to be overwriten in a subclass of Board
*/
public abstract class Board
{
......@@ -23,8 +24,8 @@ namespace PuzzlePlayer_Namespace
set { if (IsBoardValid(value) && Solve(value) != null) boardState = value; } // checks if the board is valid and solvable before setting the variable.
}
// a virtual methode for solving the whole board. It uses the abstract SolveStep methode untill the whole board is solved
public virtual int[,] Solve(int[,] boardToSolve)
// a methode for solving the whole board. It uses the private SolveStep methode untill the whole board is solved
public int[,] Solve(int[,] boardToSolve)
{
// two variables for storing the result and the next solveStep
int[,] result = boardToSolve;
......@@ -48,7 +49,23 @@ namespace PuzzlePlayer_Namespace
}
// abstract methode for solving one step
protected abstract int[,] SolveStep(int[,] currentBoardState);
private int[,] SolveStep(int[,] currentBoardState)
{
// get a list with all the possible moves
List<int[,]> 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)];
}
// a abstract methode to get a list of all possible moves
protected abstract List<int[,]> GetSolveList(int[,] boardToSolve);
// abstract methode for generating a random board
public abstract void Generate();
......
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