static void printAndPredict(string [,] board, int[, ][,] suggestedBoard, int [,] predictionBoard) { //print header Console.WriteLine(" 0 1 2 3 4 5 6 7 8 \n"); for (int i = 0; i < 9; i++) { Console.Write(" {0}: ", i); for (int j = 0; j < 9; j++) { IntSet currentSet = getCurrentSet(suggestedBoard[i, j]); //what's currently already suggested (now filter this list) IntSet allSet; IntSet rowSet = getRowSetSuggested(suggestedBoard, j, i); IntSet colSet = getColSetSuggested(suggestedBoard, i, j); IntSet blockSet = getSuggestBlockSet(suggestedBoard, i, j); //if 1 number is left in the set after currentSet is filtered(from either the row, column or block) //then that 1 number has to be the value of that blocks if ((allSet = currentSet.Difference(rowSet)).Members() == 1) { int num = Convert.ToInt32(allSet.ToString()[1] + ""); Console.Write("(" + num + ") "); //extract the number predictionBoard[i, j] = num; predictions++; } else if ((allSet = currentSet.Difference(colSet)).Members() == 1) { int num = Convert.ToInt32(allSet.ToString()[1] + ""); Console.Write("(" + num + ") "); //extract the number predictionBoard[i, j] = num; predictions++; } else if ((allSet = currentSet.Difference(blockSet)).Members() == 1) { int num = Convert.ToInt32(allSet.ToString()[1] + ""); Console.Write("(" + num + ") "); //extract the number predictionBoard[i, j] = num; predictions++; } else { Console.Write(board[i, j] + " "); } } Console.WriteLine(); } //print footer Console.WriteLine(); Console.WriteLine(" 0 1 2 3 4 5 6 7 8 \n"); }
static void updateSuggestedBoard(string[,] assignedBoard, int[, ][,] suggestedBoard) { int emptySpots = 0; for (int row = 0; row < 9; row++) { for (int col = 0; col < 9; col++) { if (assignedBoard[row, col] != "..") //if a number is already assinged to that position { suggestedBoard[row, col] = null; emptySpots++; //an empty suggested block } else //find the possible numbers { IntSet currentSet = getCurrentSet(suggestedBoard[row, col]); //what's currently already suggested (now filter this list) IntSet rowSet = getRowSet(assignedBoard, row); IntSet colSet = getColSet(assignedBoard, col); IntSet blockSet = getBlockSet(assignedBoard, row, col); //check the square the number is in //print the block of the (row,col) point // the final set of containing the suggested block IntSet allSet = currentSet.Difference(rowSet.Union(colSet).Union(blockSet)); if (allSet.IsEmpty()) //an empty suggested block { emptySpots++; } //set the block to contain values corresponding to the SET int[,] block = new int[3, 3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { int numberToCheck = 3 * i + j + 1; if (allSet.Contains(numberToCheck)) //check if number in the suggested set { block[i, j] = numberToCheck; } } } suggestedBoard[row, col] = block; } } } if (emptySpots == 81) //no more suggested spots { suggestedBoardEmpty = true; } }
static IntSet[][] updateSuggestions() { IntSet[][] result = new IntSet[9][]; for (int i = 0; i < 9; i++) { result[i] = new IntSet[9]; for (int j = 0; j < 9; j++) { IntSet R = getRow(i); IntSet C = getCol(j); IntSet B = getBlock(i, j); IntSet union = R.Union(C).Union(B); IntSet suggestion = uSet.Difference(union); result[i][j] = suggestion; Console.WriteLine($"({i},{j}) -- " + suggestion.ToString()); } } return(result); }