Esempio n. 1
0
        private void EliminateNakedPairFromOthersInBlock(int[,] sudokuBoard, int givenRow, int givenCol)
        {
            if (!HasNakedPairInBlock(sudokuBoard, givenRow, givenCol)) return;

            var sudokuMap = _sudokuMapper.Find(givenRow, givenCol);

            for (int row = sudokuMap.StartRow; row <= sudokuMap.StartRow + 2; row++)
            {
                for (int col = sudokuMap.StartCol; col <= sudokuMap.StartCol + 2; col++)
                {
                    if (sudokuBoard[row, col].ToString().Length > 1 && sudokuBoard[row, col] != sudokuBoard[givenRow, givenCol])
                    {
                        EliminateNakedPair(sudokuBoard, sudokuBoard[givenRow, givenCol], row, col);
                    }
                }
            }
        }
Esempio n. 2
0
        void EliminateNakedPairFromOthersInBlock(int[,] board, int givenRow, int givenCol)
        {
            if (!HasNakedPairInBlock(board, givenRow, givenCol))
            {
                return;
            }

            var sudokuMap = sudokuMapper.Find(givenRow, givenCol);

            for (int row = sudokuMap.StartRow; row <= sudokuMap.StartRow + 2; row++)
            {
                for (int col = sudokuMap.StartColumn; col <= sudokuMap.StartColumn + 2; col++)
                {
                    if (board[row, col].ToString().Length > 1 && board[row, col] != board[givenRow, givenCol])
                    {
                        EliminateNakedPair(board, board[givenRow, givenCol], row, col);
                    }
                }
            }
        }
Esempio n. 3
0
        private void EliminateNakedPairFromBlock(int[,] board, int row, int col)
        {
            if (!HasNakedPairInBlock(board, row, col))
            {
                return;
            }

            var sudokuMap = _sudokuMapper.Find(row, col);

            for (int r = sudokuMap.StartRow; r <= sudokuMap.StartRow + 2; r++)
            {
                for (int c = sudokuMap.StartCol; c <= sudokuMap.StartCol + 2; c++)
                {
                    if (board[r, c].ToString().Length > 1 && board[r, c] != board[row, col])
                    {
                        EliminateNakedPair(board, board[row, col], r, c);
                    }
                }
            }
        }
        private int GetPosibilitiesInBlock(int[,] sudokuBoard, int givenRow, int givenCol)
        {
            int[] possibilities = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var   sudokuMap     = _sudokuMapper.Find(givenRow, givenCol);

            for (int row = sudokuMap.StartRow; row <= sudokuMap.StartRow + 2; row++)
            {
                for (int col = sudokuMap.StartCol; col <= sudokuMap.StartCol + 2; col++)
                {
                    if (IsValidSingle(sudokuBoard[row, col]))
                    {
                        possibilities[sudokuBoard[row, col] - 1] = 0;
                    }
                }
            }
            return(Convert.ToInt32(String.Join(string.Empty, possibilities.Select(p => p).Where(p => p != 0))));
        }
Esempio n. 5
0
        int GetPossibilitiesInBlock(int[,] board, int givenRow, int givenCol)
        {
            int[] possibilities = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var   sudokuMap     = sudokuMapper.Find(givenRow, givenCol);

            for (int row = sudokuMap.StartRow; row <= sudokuMap.StartRow + 2; row++)
            {
                for (int col = sudokuMap.StartColumn; col <= sudokuMap.StartColumn + 2; col++)
                {
                    if (Utils.IsValidSingle(board[row, col]))
                    {
                        possibilities[board[row, col] - 1] = 0;
                    }
                }
            }

            return(Utils.joinNonZeroArrayValues(possibilities));
        }
Esempio n. 6
0
        private int GetPossibilitiesInBlock(int[,] board, int row, int col)
        {
            int[] possibleValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var   sudokuMap      = _sudokuMapper.Find(row, col);

            for (int r = sudokuMap.StartRow; r <= sudokuMap.StartRow + 2; r++)
            {
                for (int c = sudokuMap.StartCol; c <= sudokuMap.StartCol + 2; c++)
                {
                    if (IsValidValue(board[r, c]))
                    {
                        possibleValues[board[r, c] - 1] = 0;
                    }
                }
            }

            return(Convert.ToInt32(String.Join(string.Empty, possibleValues.Select(p => p).Where(p => p != 0))));
        }
Esempio n. 7
0
        private int GetPossibilitiesInBlock(int[,] sudokuBoard, int givenRow, int givenCol)
        {
            int[] possibilities = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            var sudokuMap = _sudokuMapper.Find(givenRow, givenCol);

            for (int row = sudokuMap.StartRow; row <= sudokuMap.StartRow + 2; row++)
            {
                for (int col = sudokuMap.StartCol; col <= sudokuMap.StartCol + 2; col++)
                {
                    //Interates through all columns and rows in the 3*3 group and check if value inside cell is within 1-9, if yes turns it to zero inside the possibilities array so it cannot be used again
                    if (IsValidSingle(sudokuBoard[row, col]))
                    {
                        possibilities[sudokuBoard[row, col] - 1] = 0;
                    }
                }
            }

            return(Convert.ToInt32(String.Join(string.Empty, possibilities.Select(p => p).Where(p => p != 0))));
        }
        private string GetPossibilityInBlock(int[,] sudokuBoard, int givenRow, int givenCol)
        {
            int[] possibilities = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            var sudokuMap = _sudokuMapper.Find(givenRow, givenCol);

            for (int row = sudokuMap.StartRow; row < sudokuMap.StartRow + 3; row++)
            {
                for (int col = sudokuMap.StartCol; col < sudokuMap.StartCol + 3; col++)
                {
                    if (IsValidSingle(sudokuBoard[row, col]))
                    {
                        possibilities[sudokuBoard[row, col] - 1] = 0;
                    }
                }
            }

            var result = possibilities.Where(item => item != 0).ToArray();

            return(string.Join(string.Empty, result));
        }
        // gets all possibilites in the block
        private int GetPossibilitiesInBlock(int[,] sudokuBoard, int givenRow, int givenCol)
        {
            int[] possibilities = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            // starts a map of the blocks with the given rows and columns
            var sudokuMap = _sudokuMapper.Find(givenRow, givenCol);

            // loops through all the blocks
            for (int row = sudokuMap.StartRow; row <= sudokuMap.StartRow + 2; row++)
            {
                for (int col = sudokuMap.StartCol; col <= sudokuMap.StartCol + 2; col++)
                {
                    // checks to see if the number is correct
                    if (IsValidSingle(sudokuBoard[row, col]))
                    {
                        possibilities[sudokuBoard[row, col] - 1] = 0;
                    }
                }
            }

            // return a number from a string from all numbers that are left
            return(Convert.ToInt32(String.Join(string.Empty, possibilities.Select(p => p).Where(p => p != 0))));
        }
Esempio n. 10
0
        private int GetPossibilitiesInBlock(int[,] sudokuBoard, int givenRow, int givenCol)
        {
            try
            {
                int[] possibilities = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
                var   sudokuMap     = _sudokuMapper.Find(givenRow, givenCol);

                for (int row = sudokuMap.StartRow; row < sudokuMap.StartRow + 3; row++)
                {
                    for (int col = sudokuMap.StartCol; col < sudokuMap.StartCol + 3; col++)
                    {
                        if (IsValidSingle(sudokuBoard[row, col]))
                        {
                            possibilities[sudokuBoard[row, col] - 1] = 0;
                        }
                    }
                }
                return(Convert.ToInt32(String.Join(string.Empty, possibilities.Select(p => p).Where(p => p != 0))));
            }
            catch (Exception ex)
            {
                throw new Exception("Error GetPossibilitiesInBlock():" + ex.Message);
            }
        }