Ejemplo n.º 1
0
        private static GridSolutionType CheckDoubleDeduction(GridSquareScript[] gridSquares, GridSquareScript selection)
        {
            int[] intersectIndices = GridEmptyIntersectIndices(gridSquares, selection);
            int[] missingRows      = intersectIndices.Select(GridMaths.RowForSquare).Where(x => x != GridMaths.RowForSquare(selection.Index)).Distinct().ToArray();
            int[] missingCols      = intersectIndices.Select(GridMaths.ColumnForSquare).Where(x => x != GridMaths.ColumnForSquare(selection.Index)).Distinct().ToArray();
            print($"Intersect indices: {string.Join(", ", intersectIndices)} Missing rows: {string.Join(", ", missingRows)} cols: {string.Join(", ", missingCols)}");

            int forceRowCount = 0;
            int big           = GridMaths.BigSquareForSquare(selection.Index);

            for (int i = 0; i < missingRows.Length; i++)
            {
                int[] otherBigRows = GridMaths.OtherBigSquaresForRow(missingRows[i], big);
                for (int j = 0; j < otherBigRows.Length; j++)
                {
                    if (DoesSquareForceRowNumber(otherBigRows[j], selection, missingRows[i], gridSquares))
                    {
                        forceRowCount += 1;
                    }
                }
            }

            int forceColCount = 0;

            for (int i = 0; i < missingCols.Length; i++)
            {
                int[] otherBigCols = GridMaths.OtherBigSquaresForColumn(missingCols[i], big);
                for (int j = 0; j < otherBigCols.Length; j++)
                {
                    if (DoesSquareForceColumnNumber(otherBigCols[j], selection, missingCols[i], gridSquares))
                    {
                        forceColCount += 1;
                    }
                }
            }
            print($"[CHECK] Double deduction: Forced rows: {missingRows.Length} = {forceRowCount} && cols: {missingCols.Length} = {forceColCount} check: {forceColCount == missingCols.Length && forceRowCount == missingRows.Length}");
            return((forceColCount == missingCols.Length && forceRowCount == missingRows.Length) ? GridSolutionType.DoubleDeduction : GridSolutionType.None);
        }