From 6321af9f8ab878f38bebd703d1d4e2d747522008 Mon Sep 17 00:00:00 2001
From: bionic85 <144353436+bionic85@users.noreply.github.com>
Date: Wed, 20 Nov 2024 12:40:08 +0100
Subject: [PATCH] binary is bijna af

---
 PuzzlePlayer/Binary.cs | 44 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 41 insertions(+), 3 deletions(-)

diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs
index 7ac9dea..833053e 100644
--- a/PuzzlePlayer/Binary.cs
+++ b/PuzzlePlayer/Binary.cs
@@ -129,8 +129,10 @@ namespace PuzzlePlayer_Namespace
             // loop two times for checking 0 and 1
             for (int i = 0; i <= 1; i++)
             {
+                bool valid = false;
+
                 // middle check
-                MiddleCheck(x, y, boardToSolve, i);
+                valid = MiddleCheck(x, y, boardToSolve, i);
 
                 // side check
 
@@ -145,10 +147,46 @@ namespace PuzzlePlayer_Namespace
         // check if the space is surrounded on both sides by the same number. If it is, the checked space should be the opposite number
         private bool MiddleCheck(int x, int y, int[,] b, int checkFor)
         {
+            int opposite;
+
+            if (checkFor == 0)
+                opposite = 1;
+            else
+                opposite = 0;
+
+            // first check if x-1 and x+1 aren't out of bounds
+            // after that do the check if the move is valid
+            if(!(x-1 < 0 || x+1 > b.GetLength(0)))
+                if (b[x - 1, y] == opposite && b[x + 1, y] == opposite)
+                    return true;
+
+            // same for y
+            if (!(y - 1 < 0 || y + 1 > b.GetLength(1)))
+                if (b[x, y - 1] == opposite && b[x, y + 1] == opposite)
+                    return true;
+
+            // return false if nothing was found
+            return false;
+        }
 
-            if (b[x - 1, y])
+        private bool SideCheck(int x, int y, int[,] b, int checkFor)
+        {
+            int opposite;
 
-                return false;
+            if (checkFor == 0)
+                opposite = 1;
+            else
+                opposite = 0;
+
+            if (!(x - 2 < 0 || x + 2 > b.GetLength(0)))
+                if ((b[x-2,y] == opposite && b[x-1,y] == opposite) || (b[x + 2, y] == opposite && b[x + 1, y] == opposite))
+                    return true;
+
+            if (!(y - 2 < 0 || y + 2 > b.GetLength(1)))
+                if ((b[x, y - 2] == opposite && b[x, y - 1] == opposite) || (b[x, y + 2] == opposite && b[x, y + 1] == opposite))
+                    return true;
+
+            return false;
         }
 
     }
-- 
GitLab