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

Move shit gefixt

parent d4b2ad59
No related branches found
Tags v1.32.3
No related merge requests found
...@@ -18,13 +18,11 @@ namespace PuzzlePlayer_Namespace ...@@ -18,13 +18,11 @@ namespace PuzzlePlayer_Namespace
// constructor with baordSize parameter (default is set to 8 but can be changed) // constructor with baordSize parameter (default is set to 8 but can be changed)
public Binary(int boardSize = 8) public Binary(int boardSize = 8)
{ {
// create a board with the specifide size // create a clear board with the specifide size
boardState = new int[boardSize,boardSize]; boardState = GetClearBoard(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\r\n- Each row and column cannot appear multiple times on the board"; 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\r\n- Each row and column cannot appear multiple times on the board";
// clear the board (fill it in with -1)
Clear();
} }
public void Draw (Graphics gr, Point p, Size s) public void Draw (Graphics gr, Point p, Size s)
...@@ -53,15 +51,18 @@ namespace PuzzlePlayer_Namespace ...@@ -53,15 +51,18 @@ namespace PuzzlePlayer_Namespace
} }
} }
private void Clear() // static meathode for filling a int[,] with -1
private static int[,] GetClearBoard(int boardSize)
{ {
int size = boardState.GetLength(0); int[,] result = new int[boardSize, boardSize];
// fill the board with empty spaces (-1) // fill the board with empty spaces (-1)
for (int i = 0; i < size; i++) for (int i = 0; i < boardSize; i++)
{ {
for (int j = 0; j < size; j++) for (int j = 0; j < boardSize; j++)
boardState[i, j] = emptySpace; result[i, j] = emptySpace;
} }
return result;
} }
/* this static methode returns true if the board is valid in a few steps /* this static methode returns true if the board is valid in a few steps
...@@ -95,30 +96,36 @@ namespace PuzzlePlayer_Namespace ...@@ -95,30 +96,36 @@ namespace PuzzlePlayer_Namespace
return true; return true;
} }
// generates a random solvable board
public override void Generate() public override void Generate()
{ {
throw new NotImplementedException(); // start with a clear board
int[,] result = GetClearBoard(boardState.GetLength(0));
} }
protected override List<int[,]> GetSolveList(int[,] boardToSolve)
// gets a list with all the possible moves
protected override List<Move> GetSolveList(int[,] boardToSolve)
{ {
List<int[,]> result = new List<int[,]>(); List<Move> result = new List<Move>();
for (int i = 0; i < boardToSolve.GetLength(0); i++) for (int i = 0; i < boardToSolve.GetLength(0); i++)
for (int j = 0; j < boardToSolve.GetLength(1);j++) for (int j = 0; j < boardToSolve.GetLength(1);j++)
{ {
int[,] move = CheckMove(i, j, boardToSolve); Move ?m = CheckMove(i, j, boardToSolve);
if (move != null) if (m != null)
result.Add(move); result.Add(m);
} }
return result; return result;
} }
private int[,] CheckMove(int x, int y, int[,] boardToSolve) private Move? CheckMove(int x, int y, int[,] boardToSolve)
{ {
int[,] result = boardToSolve;
bool validForZero = false; bool validForZero = false;
bool validForOne = false; bool validForOne = false;
...@@ -153,13 +160,11 @@ namespace PuzzlePlayer_Namespace ...@@ -153,13 +160,11 @@ namespace PuzzlePlayer_Namespace
// change the specifided place in a 0 or 1 if they are valid. if both are not valid then there is no valid move on the checked space and null is returnd. // change the specifided place in a 0 or 1 if they are valid. if both are not valid then there is no valid move on the checked space and null is returnd.
if (validForZero) if (validForZero)
result[x, y] = 0; return new Move(x, y, 0);
else if (validForOne) else if (validForOne)
result[x, y] = 1; return new Move(x, y, 1);
else else
return null; return null;
return result;
} }
// check if the space is surrounded on both sides by the same number. If it is, the checked space should be the opposite number // check if the space is surrounded on both sides by the same number. If it is, the checked space should be the opposite number
...@@ -194,7 +199,7 @@ namespace PuzzlePlayer_Namespace ...@@ -194,7 +199,7 @@ namespace PuzzlePlayer_Namespace
return false; return false;
} }
// every row and colom should have an even number of 1's and 0's. So if the total number of 1's in a row is equal to half the with of the row a 0 should be filled in. // every row and colom should have an even number of 1'boardSize and 0'boardSize. So if the total number of 1'boardSize in a row is equal to half the with of the row a 0 should be filled in.
private bool EvenCheck(int x, int y, int[,] b, int checkFor) private bool EvenCheck(int x, int y, int[,] b, int checkFor)
{ {
// check for a row and colum (provided that the width and height of the board is the same) // check for a row and colum (provided that the width and height of the board is the same)
......
...@@ -15,6 +15,20 @@ namespace PuzzlePlayer_Namespace ...@@ -15,6 +15,20 @@ namespace PuzzlePlayer_Namespace
MULTIPLE = 2 MULTIPLE = 2
} }
// a struct for a move on a certain location. changeTo is in what the place on the coordinates should change to
public struct Move
{
public int x, y;
public int changeTo;
public Move(int x, int y, int changeTo)
{
this.x = x;
this.y = y;
this.changeTo = changeTo;
}
}
/* /*
* 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
...@@ -51,13 +65,16 @@ namespace PuzzlePlayer_Namespace ...@@ -51,13 +65,16 @@ namespace PuzzlePlayer_Namespace
{ {
// two variables for storing the result and the next solveStep // two variables for storing the result and the next solveStep
int[,] result = boardState; int[,] result = boardState;
int[,] step; List<Move> possibleMoves;
// keep looping until the SolveStep returns null // keep looping until the SolveStep returns null
// if SolveStep returns null that could mean that either the whole board is solved or it is imposible to solve the board // if SolveStep returns null that could mean that either the whole board is solved or it is imposible to solve the board
while ((step = SolveStep(result)) != null) while ((possibleMoves = GetSolveList(result)) != null)
{ {
result = step; foreach (Move m in possibleMoves)
{
result[m.x, m.y] = m.changeTo;
}
} }
// check if the whole board is filled // check if the whole board is filled
...@@ -74,10 +91,10 @@ namespace PuzzlePlayer_Namespace ...@@ -74,10 +91,10 @@ namespace PuzzlePlayer_Namespace
} }
// abstract methode for solving one step // abstract methode for solving one step
private int[,] SolveStep(int[,] currentBoardState) private Move? SolveStep(int[,] currentBoardState)
{ {
// get a list with all the possible moves // get a list with all the possible moves
List<int[,]> moves = GetSolveList(currentBoardState); List<Move> moves = GetSolveList(currentBoardState);
// if there are no moves found then null is returned // if there are no moves found then null is returned
if (moves.Count == 0) if (moves.Count == 0)
...@@ -90,7 +107,7 @@ namespace PuzzlePlayer_Namespace ...@@ -90,7 +107,7 @@ namespace PuzzlePlayer_Namespace
} }
// a abstract methode to get a list of all possible moves // a abstract methode to get a list of all possible moves
protected abstract List<int[,]> GetSolveList(int[,] boardToSolve); protected abstract List<Move> GetSolveList(int[,] boardToSolve);
// abstract methode for generating a random board // abstract methode for generating a random board
public abstract void Generate(); 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