From dffd16542b9f3780bcd2306dbf5885354cef032a Mon Sep 17 00:00:00 2001
From: bionic85 <144353436+bionic85@users.noreply.github.com>
Date: Thu, 21 Nov 2024 14:46:26 +0100
Subject: [PATCH] Binary werkt helemaal toppp

---
 PuzzlePlayer/Binary.cs     | 24 ++++++++++++++++--------
 PuzzlePlayer/Board.cs      |  6 +++---
 PuzzlePlayer/PuzzleForm.cs | 22 ++++++++++++++++++----
 3 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs
index 6cc7434..e3f2f20 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 9c21623..48faf26 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 31713df..930b178 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()
         {
-- 
GitLab