private Nonant FindMostSolvedNonant() { Nonant temp = null; foreach (Nonant n in sections) { if (n.getNumberAnswered < 9) { temp = n; break; } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (sections[i, j].getNumberAnswered <9 && sections[i, j].getNumberAnswered> temp.getNumberAnswered) { temp = sections[i, j]; } } } return(temp); }
public bool GuessAndCheck() { while (numberFound < 81) { Nonant tempNon = FindMostSolvedNonant(); //find the nonant with the fewest //answers left to find //Line tempLine = FindMostSolvedLine(); //find the line with the fewest answers left to find //if (tempNon.getNumberAnswered > tempLine.getNumberFound) //{ // tempNon.GuessNodes(); //} //else tempLine.GuessNodes(); tempNon.GuessNodes(); SolveBoard(); } foreach (Nonant non in sections) { if (!non.CheckNonant()) { return(false); } } for (int i = 0; i < 9; i++) { if (!rows[i].CheckLine()) { return(false); } if (!cols[i].CheckLine()) { return(false); } } return(true); }
/// <summary> /// Creates the Nonants of the board. /// </summary> private void MakeNonants() { Node[,] temp1 = new Node[3, 3]; Node[,] temp2 = new Node[3, 3]; Node[,] temp3 = new Node[3, 3]; Node[,] temp4 = new Node[3, 3]; Node[,] temp5 = new Node[3, 3]; Node[,] temp6 = new Node[3, 3]; Node[,] temp7 = new Node[3, 3]; Node[,] temp8 = new Node[3, 3]; Node[,] temp9 = new Node[3, 3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { temp1[i, j] = MainBoard[i, j]; temp2[i, j] = MainBoard[i, j + 3]; temp3[i, j] = MainBoard[i, j + 6]; temp4[i, j] = MainBoard[i + 3, j]; temp5[i, j] = MainBoard[i + 3, j + 3]; temp6[i, j] = MainBoard[i + 3, j + 6]; temp7[i, j] = MainBoard[i + 6, j]; temp8[i, j] = MainBoard[i + 6, j + 3]; temp9[i, j] = MainBoard[i + 6, j + 6]; } } sections[0, 0] = new Nonant(temp1, new Line[3] { rows[0], rows[1], rows[2] }, new Line[3] { cols[0], cols[1], cols[2] }); sections[0, 1] = new Nonant(temp2, new Line[3] { rows[0], rows[1], rows[2] }, new Line[3] { cols[3], cols[4], cols[5] }); sections[0, 2] = new Nonant(temp3, new Line[3] { rows[0], rows[1], rows[2] }, new Line[3] { cols[6], cols[7], cols[8] }); sections[1, 0] = new Nonant(temp4, new Line[3] { rows[3], rows[4], rows[5] }, new Line[3] { cols[0], cols[1], cols[2] }); sections[1, 1] = new Nonant(temp5, new Line[3] { rows[3], rows[4], rows[5] }, new Line[3] { cols[3], cols[4], cols[5] }); sections[1, 2] = new Nonant(temp6, new Line[3] { rows[3], rows[4], rows[5] }, new Line[3] { cols[6], cols[7], cols[8] }); sections[2, 0] = new Nonant(temp7, new Line[3] { rows[6], rows[7], rows[8] }, new Line[3] { cols[0], cols[1], cols[2] }); sections[2, 1] = new Nonant(temp8, new Line[3] { rows[6], rows[7], rows[8] }, new Line[3] { cols[3], cols[4], cols[5] }); sections[2, 2] = new Nonant(temp9, new Line[3] { rows[6], rows[7], rows[8] }, new Line[3] { cols[6], cols[7], cols[8] }); }