84 lines
1.7 KiB
Go
84 lines
1.7 KiB
Go
package board
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func (f *Field) String() string {
|
|
//TODO: auf beliebige größen anpassen
|
|
var sb strings.Builder
|
|
|
|
// Oberer Rahmen
|
|
sb.WriteString("╔═══════╤═══════╤═══════╗\n")
|
|
|
|
for i := range f.cells {
|
|
sb.WriteString("║ ") // Linke Rahmenseite
|
|
|
|
for j, cell := range f.cells[i] {
|
|
// Wert ausgeben oder Punkt für 0
|
|
val := cell.number
|
|
if val == 0 {
|
|
sb.WriteString("·")
|
|
} else {
|
|
sb.WriteString(string('0' + val))
|
|
}
|
|
|
|
// Trennlinien zwischen Blöcken und Zellen
|
|
if (j+1)%3 == 0 {
|
|
if j < 8 {
|
|
sb.WriteString(" │ ")
|
|
} else {
|
|
sb.WriteString(" ║\n") // Rechte Rahmenseite + Zeilenumbruch
|
|
}
|
|
} else {
|
|
sb.WriteString(" ")
|
|
}
|
|
}
|
|
|
|
// Horizontale Trennlinien nach jeder 3. Zeile
|
|
if (i+1)%3 == 0 && i < 8 {
|
|
sb.WriteString("╟───────┼───────┼───────╢\n")
|
|
}
|
|
}
|
|
|
|
// Unterer Rahmen
|
|
sb.WriteString("╚═══════╧═══════╧═══════╝")
|
|
|
|
return sb.String()
|
|
}
|
|
|
|
func (f *Field) StringNotesForNumber(n int) string {
|
|
return "StringNotesForNumber is not implementet"
|
|
}
|
|
|
|
func (f *Field) StringNotes() string {
|
|
var str strings.Builder
|
|
fmt.Fprintf(&str, "Notes:\n")
|
|
f.ForEachCell(func(cell *Cell) {
|
|
fmt.Fprintf(&str, "Pos: %d/%d - Notes: %v\n", cell.Pos.row, cell.Pos.column, cell.Notes.numbers)
|
|
})
|
|
return str.String()
|
|
}
|
|
|
|
func (f *Field) IsSolved() bool {
|
|
result := true
|
|
f.ForEachCell(func(cell *Cell) {
|
|
if cell.number == 0 {
|
|
result = false
|
|
}
|
|
})
|
|
|
|
/* TODO:
|
|
if !f.isValid() {
|
|
return false
|
|
}
|
|
*/
|
|
|
|
return result
|
|
}
|
|
|
|
func (f *Field) IsValid() bool {
|
|
return false
|
|
}
|