Add method TrivialHint()
authorMikael Berthe <mikael@lilotux.net>
Thu, 08 Sep 2016 21:57:30 +0200
changeset 4 4ad659431711
parent 3 8415b6bd06e9
child 5 733df0275d78
Add method TrivialHint()
takuzu.go
--- a/takuzu.go	Thu Sep 08 20:56:07 2016 +0200
+++ b/takuzu.go	Thu Sep 08 21:57:30 2016 +0200
@@ -421,6 +421,24 @@
 	return -1 // dunno
 }
 
+// TrivialHint returns the coordinates and the value of the first cell that
+// can be guessed using trivial methods.
+// It returns {-1, -1, -1} if none can be found.
+func (b Takuzu) TrivialHint() (line, col, value int) {
+	for line = 0; line < b.Size; line++ {
+		for col = 0; col < b.Size; col++ {
+			if b.Board[line][col].Defined {
+				continue
+			}
+			if value = b.guessPos(line, col); value != -1 {
+				return
+			}
+		}
+	}
+	value, line, col = -1, -1, -1
+	return
+}
+
 // trySolveTrivialPass does 1 pass over the takuzu board and tries to find
 // values using simple guesses.
 func (b Takuzu) trySolveTrivialPass() (changed bool) {