diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs index 6cc7434b95547aae0d64b86cfe74e7bb3e87b19a..e3f2f20c50260f736ebf0a4125763c507cec4fb6 100644 --- a/PuzzlePlayer/Binary.cs +++ b/PuzzlePlayer/Binary.cs @@ -195,17 +195,25 @@ namespace PuzzlePlayer_Namespace // check if the two spaces left, right, up or down of the space are the opposite number. if so return true private bool SideCheck(int x, int y, int[,] b, int checkFor) { - if (!(x - 2 < 0 || x + 2 > b.GetLength(0)-1)) - if ((b[x-2,y] == checkFor && b[x-1,y] == checkFor) || (b[x + 2, y] == checkFor && b[x + 1, y] == checkFor)) + //check the two spaces left + if (x - 2 >= 0) + if (b[x - 2, y] == checkFor && b[x - 1, y] == checkFor) return true; - if (!(y - 2 < 0 || y + 2 > b.GetLength(1)-1)) - { - Debug.WriteLine($"{x}, {y}"); - if ((b[x, y - 2] == checkFor && b[x, y - 1] == checkFor) || (b[x, y + 2] == checkFor && b[x, y + 1] == checkFor)) + //check the two spaces right + if (x + 2 < b.GetLength(0)) + if (b[x + 2, y] == checkFor && b[x + 1, y] == checkFor) return true; - } - + + //check the two spaces down + if (y - 2 >= 0) + if (b[x , y- 2] == checkFor && b[x , y- 1] == checkFor) + return true; + + //check the two spaces up + if (y + 2 < b.GetLength(1)) + if (b[x , y+ 2] == checkFor && b[x , y+ 1] == checkFor) + return true; return false; } diff --git a/PuzzlePlayer/Board.cs b/PuzzlePlayer/Board.cs index 9c21623892d3aa824072828624e2c18f7852f0ec..48faf26c0b1af74f6f46e7cbfd0147e9ef293a42 100644 --- a/PuzzlePlayer/Board.cs +++ b/PuzzlePlayer/Board.cs @@ -65,9 +65,9 @@ namespace PuzzlePlayer_Namespace int[,] result = boardState; List<Move> possibleMoves; - // 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 - while ((possibleMoves = GetSolveList(result)) != null) + // keep looping until the SolveStep returns an empty list + // if SolveStep returns a empty list that could mean that either the whole board is solved or it is imposible to solve the board + while ((possibleMoves = GetSolveList(result)).Count != 0) { foreach (Move m in possibleMoves) { diff --git a/PuzzlePlayer/PuzzleForm.cs b/PuzzlePlayer/PuzzleForm.cs index 31713df8bb9775c9239e9fe697eb4e12241864fb..930b1787c99826d35d5397d34e2ac26d1a9dfdca 100644 --- a/PuzzlePlayer/PuzzleForm.cs +++ b/PuzzlePlayer/PuzzleForm.cs @@ -45,10 +45,24 @@ namespace PuzzlePlayer_Namespace { UpdateUI(); }; - Board.boardState[4, 4] = 1; - Board.boardState[4, 5] = 1; - Board.boardState[5, 4] = 1; - Board.boardState[5, 5] = 1; + + // example board: https://imgur.com/spyYaPl + board.boardState[0, 0] = 1; + board.boardState[1, 0] = 1; + board.boardState[6, 0] = 1; + board.boardState[3, 1] = 1; + board.boardState[0, 2] = 1; + board.boardState[1, 2] = 1; + board.boardState[3, 2] = 1; + board.boardState[5, 4] = 1; + board.boardState[6, 4] = 1; + board.boardState[1, 5] = 1; + board.boardState[2, 5] = 1; + board.boardState[5, 5] = 1; + board.boardState[1, 7] = 1; + board.boardState[3, 7] = 0; + board.boardState[6, 7] = 1; + } private void CreateUI() {