Esempio n. 1
0
 private static bool BigSquareCompleteCheck(GridSquareScript[] gridSquares, int square)
 {
     int[] bigSquares = GridMaths.GridBigSquareIndices(square);
     int[] numbers    = GridsAtIndexes(bigSquares, gridSquares).Where(x => x.Number > 0).Select(x => x.Number).Distinct().ToArray();
     print($"Big square check - Numbers count: {numbers.Length} => {string.Join(",", numbers)}");
     return(numbers.Length == 9);
 }
Esempio n. 2
0
        private static int[] ExistingNumbersInBigSquare(GridSquareScript[] gridSquares, int big)
        {
            int[] allNumbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            GridSquareScript[] bigSquareData = GridsAtIndexes(GridMaths.GridBigSquareIndices(big), gridSquares);
            int[] remaining = allNumbers.Intersect(bigSquareData.Where(x => x.Number != 0 && !x.IsTarget).Select(s => s.Number)).ToArray();
            print($"BIG SQUARE {big} existing numbers: {string.Join(",", remaining)}");
            return(remaining);
        }
Esempio n. 3
0
        //TODO - NEEDED?
        private static int[] MissingNumbersInBigSquare(GridSquareScript[] gridSquares, int big)
        {
            int[] allNumbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            GridSquareScript[] bigSquareData = GridsAtIndexes(GridMaths.GridBigSquareIndices(big), gridSquares);
            int[] remaining = allNumbers.Except(bigSquareData.Select(s => s.Number).Where(x => x != 0)).ToArray();
            print($"BIG SQUARE remaining numbers: {string.Join(",", remaining)}");
            return(remaining);
        }
Esempio n. 4
0
        public void HighLightBigSquare(int index)
        {
            int bigSquare = GridMaths.BigSquareForSquare(index);

            int[] bigSquares = GridMaths.GridBigSquareIndices(bigSquare);
            for (int i = 0; i < bigSquares.Length; i++)
            {
                gridSquares[bigSquares[i]].HighlightSquare(index);
            }
        }
Esempio n. 5
0
        private static int[] GridEmptyIntersectIndices(GridSquareScript[] gridSquares, GridSquareScript selection)
        {
            int square = GridMaths.BigSquareForSquare(selection.Index);

            GridSquareScript[] emptySquares = EmptyGridsAtIndexes(GridMaths.GridBigSquareIndices(square), gridSquares, selection);
            int[] emptyIndices = EmptyGridsAtIndexes(GridMaths.GridBigSquareIndices(square), gridSquares, selection).Select(x => x.Index).Distinct().ToArray();

            //check how many row are in the empty indicies
            int[] emptyCols        = emptyIndices.Where(x => !DoesColumnContainNumber(GridMaths.ColumnForSquare(x), selection, gridSquares)).ToArray();
            int[] emptyRows        = emptyIndices.Where(x => !DoesRowContainNumber(GridMaths.RowForSquare(x), selection, gridSquares)).ToArray();
            int[] intersectIndices = emptyCols.Intersect(emptyRows).ToArray();
            print($"GridEmptyIntersectIndices: ({string.Join(",", emptyIndices)}) empty rows: {string.Join(",", emptyRows)} cols: {string.Join(",", emptyCols)} intersect: {string.Join(",", intersectIndices)}");
            return(emptyCols.Intersect(emptyRows).ToArray());
        }
Esempio n. 6
0
        private static bool DoesSquareForceColumnNumber(int big, GridSquareScript selection, int col, GridSquareScript[] gridSquares)
        {
            print($"DoesSquare {big} ForceColumn {col} Number: {selection.Number}");
            bool numberCheck = DoesBigSquareContainNumber(big, selection, gridSquares);

            if (DoesBigSquareContainNumber(big, selection, gridSquares))
            {
                return(false);
            }
            int[] emptyIndices  = EmptyGridsAtIndexes(GridMaths.GridBigSquareIndices(big), gridSquares, selection).Select(x => x.Index).Distinct().ToArray();
            int[] noColIndices  = emptyIndices.Where(x => !DoesColumnContainNumber(GridMaths.ColumnForSquare(x), selection, gridSquares)).ToArray();
            int[] noRowIndices  = emptyIndices.Where(x => !DoesRowContainNumber(GridMaths.RowForSquare(x), selection, gridSquares)).ToArray();
            int[] forcedColumns = noColIndices.Intersect(noRowIndices).Select(GridMaths.ColumnForSquare).Distinct().ToArray();

            print($"Empty indices in square {big} = {string.Join(",", emptyIndices)} - no col indices ({string.Join(",", noColIndices)})  no row indices ({string.Join(",", noRowIndices)}) = {string.Join(",", forcedColumns)} =  {col}");
            return(forcedColumns.Length == 1 && forcedColumns[0] == col);
        }
Esempio n. 7
0
 private static bool DoesBigSquareContainNumber(int big, GridSquareScript selection, GridSquareScript[] gridSquares)
 {
     GridSquareScript[] bigSquareSquares = GridsAtIndexes(GridMaths.GridBigSquareIndices(big), gridSquares);
     return(bigSquareSquares.Any(x => x.Number == selection.Number && !x.IsTarget)); //x.Index != selection.Index);
 }