public bool BacktrackingSearch() { if (Solved) { return(OnSolution()); } Requirement c = EasiestRequirement; int s = c.s; int i = 0; if (s == 0) { return(false); } c.Cover(); bool brk = false; for (Tile r = c.d; r != c; r = r.d) { CoverRow(r); brk = BacktrackingSearch(); UncoverRow(); if (brk) { break; } } c.Uncover(); return(brk); }
public bool BacktrackingProof(TextWriter log) { if (Solved) { return(OnSolution()); } Requirement c = EasiestRequirement; log.WriteLine(c.ToString()); int s = c.s; int i = 0; if (s == 0) { return(false); } c.Cover(); if (s != 1) { log.WriteLine("(start of loop)"); } bool brk = false; for (Tile r = c.d; r != c; r = r.d) { if (s != 1) { log.WriteLine("(loop " + (++i) + "/" + s + ")"); } log.WriteLine(r.Candidate.ToString()); CoverRow(r); brk = BacktrackingProof(log); UncoverRow(); if (brk) { break; } } c.Uncover(); if (s != 1) { log.WriteLine("(end of loop)"); } return(brk); }