public Column(int xID, Square[,] sMap) { for(int y = 0; y < 9; y++) { listOfSquares.Add(sMap[xID,y]); } }
public Row(int yID, Square[,] sMap) { for(int x = 0; x < 9; x++) { listOfSquares.Add(sMap[x,yID]); } }
public void PopulateSudokuMap(int[,] sudokuvalues) { for(int y = 0; y < 9; y++) { for(int x = 0; x < 9; x++) { _sudokuMap[x,y] = new Square(x,y,sudokuvalues[x,y]); SetOutstandingBoxes(sudokuvalues[x,y]); } } }
public Quadrant(int xID, int yID, Square[,] sMap) { int minX = 0; int minY = 0; int maxX = 0; int maxY = 0; QuadrantMapping(xID, yID, ref minX, ref minY, ref maxX, ref maxY); for(int y = minY; y <= maxY; y++) { for(int x = minX; x <= maxX; x++) { listOfSquares.Add(sMap[x,y]); } } }
public int[] SolveSquare(Square sq, Column col, Row row, Quadrant quad) { //This array is returned with the info as to whether the square was solved. //It's values are: //solveInfo[0] = -1 / 1 : indicates if the square was solved //solveInfo[1] = int : indicates the solved value. 0 if it couldn't be solved. int[] solveInfo = new int[2]{-1,0}; foreach(int number in sq.PossibleValues) { //Is this a possible value elsewhere in the quad? If not, then it's the correct value if(!NumberIsPossibleElsewhereInQuad(number, quad)) { solveInfo[0] = 1; solveInfo[1] = number; return solveInfo; } if(!NumberIsPossibleElsewhereInRow(number, row)) { solveInfo[0] = 1; solveInfo[1] = number; return solveInfo; } if(!NumberIsPossibleElsewhereInCol(number, col)) { solveInfo[0] = 1; solveInfo[1] = number; return solveInfo; } if(HasOnlyOnePossibleValue(sq)) { solveInfo[0] = 1; solveInfo[1] = number; return solveInfo; } } return solveInfo; }
private bool HasOnlyOnePossibleValue(Square sq) { if(sq.PossibleValues.Count == 1) { return true; } else { return false; } }