From 218ec63c0a8571c2094291b451ac9a9cc8135962 Mon Sep 17 00:00:00 2001 From: bionic85 <144353436+bionic85@users.noreply.github.com> Date: Sun, 24 Nov 2024 16:45:46 +0100 Subject: [PATCH] We zijn Cooked --- PuzzlePlayer/Binary.cs | 45 +++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/PuzzlePlayer/Binary.cs b/PuzzlePlayer/Binary.cs index 7e896f2..7dfd394 100644 --- a/PuzzlePlayer/Binary.cs +++ b/PuzzlePlayer/Binary.cs @@ -151,13 +151,8 @@ namespace PuzzlePlayer_Namespace for (int j = 0; j < board.GetLength(1); j++) { // if the checked space is already filled in than it is not a valid move - if (board[i, j] != emptySpace) - continue; - - if (SideCheck(i, j, board, checkFor) || MiddleCheck(i, j, board, checkFor)) - continue; - if (EvenCheck(i, j, board, checkFor)) - continue; + //if (board[i, j] != emptySpace) + // continue; /* // if one of the checks succeeds then it is an invalid move @@ -165,12 +160,40 @@ namespace PuzzlePlayer_Namespace continue; //*/ // if all checks pass then add the move to the list - choices.Add(new Move(i, j, checkFor)); + if(board[i, j] == emptySpace && ValidChoiceCheck(i,j,board,checkFor)) + choices.Add(new Move(i, j, checkFor)); } } return choices; } + private static bool ValidChoiceCheck(int x, int y, int[,] board, int checkFor) + { + int opposite; + if(checkFor == 0) + opposite = 1; + else + opposite = 0; + + + if (SideCheck(x, y, board, checkFor)) + { + //Debug.WriteLine("side check. return false"); + return false; + } + + if (MiddleCheck(x, y, board, checkFor)) + { + //Debug.WriteLine("middle check. return false"); + return false; + } + + if(EvenCheck(x, y, board, checkFor)) + return false; + + return true; + } + private static bool IsBoardCompletlyFilledIn(int[,] board) { for (int i = 0; i < board.GetLength(0); i++) @@ -215,7 +238,7 @@ namespace PuzzlePlayer_Namespace // check if it is a valid move if (DoAllChecks(x, y, boardToSolve, opposite)) { - Debug.WriteLine($"true {x} {y} {i}"); + //Debug.WriteLine($"true {x} {y} {i}"); return new Move(x, y, i); } @@ -289,6 +312,10 @@ namespace PuzzlePlayer_Namespace if(b[x,i] == checkFor) countCol++; } + // if there are more counted then possible return false + if ((countRow) > b.GetLength(0) / 2 || (countCol) > b.GetLength(0) / 2) + return false; + // check if the total number of oppisite numbers is equal to half te widht/heigt if (countRow == b.GetLength(0) / 2 || countCol == b.GetLength(1) / 2) return true; -- GitLab