private static bool RowCompleteCheck(GridSquareScript[] gridSquares, int row) { int[] rowSquares = GridMaths.GridRowIndices(row); int[] numbers = GridsAtIndexes(rowSquares, gridSquares).Where(x => x.Number > 0).Select(x => x.Number).Distinct().ToArray(); print($"Row check - Numbers count: {numbers.Length} => {string.Join(",", numbers)}"); return(numbers.Length == 9); }
private static bool CheckSeveralMissingRow(GridSquareScript selection, GridSquareScript[] gridSquares) { int row = GridMaths.RowForSquare(selection.Index); GridSquareScript[] emptyRowSquares = EmptyGridsAtIndexes(GridMaths.GridRowIndices(row), gridSquares, selection); int[] emptyIndices = emptyRowSquares.Select(x => x.Index).Distinct().ToArray(); int[] bigSquareIndices = emptyIndices.Select(x => GridMaths.BigSquareForSquare(x)).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.GridRowInSquare(row, box)).ToArray(); if (checks.Length > 0) { usableSquares.AddRange(checks); } } } if (usableSquares.Count > 0) { return(usableSquares.All(x => DoesColumnContainNumber(GridMaths.ColumnForSquare(x), selection, gridSquares))); } return(true); }
private static int[] ExistingNumbersInRow(GridSquareScript[] gridSquares, int row) { int[] allNumbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; GridSquareScript[] rowData = GridsAtIndexes(GridMaths.GridRowIndices(row), gridSquares); int[] remaining = allNumbers.Intersect(rowData.Where(x => x.Number != 0 && !x.IsTarget).Select(s => s.Number)).ToArray(); print($"ROW {row} existing numbers: {string.Join(",", remaining)}"); return(remaining); }
////TODO - NEEDED? private static int[] MissingNumbersInRow(GridSquareScript[] gridSquares, int row) { int[] allNumbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; GridSquareScript[] rowData = GridsAtIndexes(GridMaths.GridRowIndices(row), gridSquares); int[] remaining = allNumbers.Except(rowData.Select(s => s.Number).Where(x => x != 0)).ToArray(); print($"ROW remaining numbers: {string.Join(",", remaining)}"); return(remaining); }
public void HighlightRow(int index) { int row = GridMaths.RowForSquare(index); int[] rowSquares = GridMaths.GridRowIndices(row); for (int i = 0; i < rowSquares.Length; i++) { gridSquares[rowSquares[i]].HighlightSquare(index); } }
private static bool DoesRowContainNumber(int row, GridSquareScript selection, GridSquareScript[] gridSquares) { GridSquareScript[] rowSquares = GridsAtIndexes(GridMaths.GridRowIndices(row), gridSquares); return(rowSquares.Any(x => x.Number == selection.Number && !x.IsTarget));//&& x.Index != selection.Index); }