示例#1
0
 private static bool ColumnCompleteCheck(GridSquareScript[] gridSquares, int col)
 {
     int[] colSquares = GridMaths.GridColumnIndices(col);
     int[] numbers    = GridsAtIndexes(colSquares, gridSquares).Where(x => x.Number > 0).Select(x => x.Number).Distinct().ToArray();
     print($"Column check - Numbers count: {numbers.Length} => {string.Join(",", numbers)}");
     return(numbers.Length == 9);
 }
示例#2
0
        private static bool CheckSeveralMissingColumn(GridSquareScript selection, GridSquareScript[] gridSquares)
        {
            int col = GridMaths.ColumnForSquare(selection.Index);

            GridSquareScript[] emptyColSquares = EmptyGridsAtIndexes(GridMaths.GridColumnIndices(col), gridSquares, selection);
            int[] emptyIndices     = emptyColSquares.Select(x => x.Index).Distinct().ToArray();
            int[] bigSquareIndices = emptyColSquares.Select(x => GridMaths.BigSquareForSquare(x.Index)).Distinct().ToArray();

            List <int> usableSquares = new List <int>();

            for (int i = 0; i < bigSquareIndices.Length; i++)
            {
                int box = bigSquareIndices[i];
                if (!DoesBigSquareContainNumber(box, selection, gridSquares))
                {
                    int[] checks = emptyIndices.Intersect(GridMaths.GridColumnInSquare(col, box)).ToArray();
                    if (checks.Length > 0)
                    {
                        usableSquares.AddRange(checks);
                    }
                }
            }
            if (usableSquares.Count > 0)
            {
                return(usableSquares.All(x => DoesRowContainNumber(GridMaths.RowForSquare(x), selection, gridSquares)));
            }
            return(true);
        }
示例#3
0
        private static int[] ExistingNumbersInColumn(GridSquareScript[] gridSquares, int col)
        {
            int[] allNumbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            GridSquareScript[] colData = GridsAtIndexes(GridMaths.GridColumnIndices(col), gridSquares);
            int[] remaining            = allNumbers.Intersect(colData.Where(x => x.Number != 0 && !x.IsTarget).Select(s => s.Number)).ToArray();
            print($"COL {col} existing numbers: {string.Join(",", remaining)}");
            return(remaining);
        }
示例#4
0
        //TODO - NEEDED?
        private static int[] MissingNumbersInColumn(GridSquareScript[] gridSquares, int col)
        {
            int[] allNumbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            GridSquareScript[] colData = GridsAtIndexes(GridMaths.GridColumnIndices(col), gridSquares);
            int[] remaining            = allNumbers.Except(colData.Select(s => s.Number).Where(x => x != 0)).ToArray();
            print($"COL remaining numbers: {string.Join(",", remaining)}");
            return(remaining);
        }
示例#5
0
        public void HighlightColumn(int index)
        {
            int col = GridMaths.ColumnForSquare(index);

            int[] colSquares = GridMaths.GridColumnIndices(col);
            for (int i = 0; i < colSquares.Length; i++)
            {
                gridSquares[colSquares[i]].HighlightSquare(index);
            }
        }
示例#6
0
 private static bool DoesColumnContainNumber(int col, GridSquareScript selection, GridSquareScript[] gridSquares)
 {
     GridSquareScript[] colSquares = GridsAtIndexes(GridMaths.GridColumnIndices(col), gridSquares);
     return(colSquares.Any(x => x.Number == selection.Number && !x.IsTarget));//x.Index != selection.Index);
 }