first successful run to solve a simple puzzle

This commit is contained in:
2026-07-25 06:58:15 +02:00
parent 8e99087a30
commit 7bf4a8d725
15 changed files with 201 additions and 28 deletions
+6
View File
@@ -4,6 +4,8 @@ package board
// NOTES STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
import "slices"
type Notes struct {
numbers []int
}
@@ -49,6 +51,10 @@ func (n *Notes) Get() []int {
return copySlice
}
func (n *Notes) Has(i int) bool {
return slices.Contains(n.numbers, i)
}
// ────────────────────────────────────────────────────────────────────────────── //
// CELL STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
+26 -1
View File
@@ -82,10 +82,28 @@ func (f *Field) GetBlock(r, c int) (*Block, error) {
block.cells[row][column] = &f.cells[startRow+row][startCol+column]
}
}
return block, nil
}
func (f *Field) GetEachPartAtPos(pos *Position) []Part {
row, err := f.GetRow(pos.row)
if err != nil {
return nil
}
column, err := f.GetColumn(pos.column)
if err != nil {
return nil
}
block, err := f.GetBlock(pos.blockRow, pos.blockColumn)
if err != nil {
return nil
}
return append([]Part{}, row, column, block)
}
func (f *Field) GetCell(r, c int) (*Cell, error) {
if r > f.rows || c > f.columns {
return nil, outOfBound
@@ -111,6 +129,13 @@ func (f *Field) ForEachPart(fn func(part Part)) {
})
}
func (f *Field) ForEachPartAtPos(pos *Position, fn func(part Part)) {
parts := f.GetEachPartAtPos(pos)
for _, part := range parts {
fn(part)
}
}
func (f *Field) ForEachRow(fn func(row *Row)) {
for i := range f.rows {
row, err := f.GetRow(i)
+1
View File
@@ -80,6 +80,7 @@ func (pb *PuzzleBank) Parse(data []byte) error {
return fmt.Errorf("Kann Zeichen nicht in Zahl konvertieren")
}
field.cells[i][j].number = number
field.cells[i][j].Notes = &Notes{}
field.cells[i][j].Pos = &Position{
row: i,
column: j,
+17 -1
View File
@@ -1,6 +1,9 @@
package board
import "strings"
import (
"fmt"
"strings"
)
func (f *Field) String() string {
//TODO: auf beliebige größen anpassen
@@ -45,6 +48,19 @@ func (f *Field) String() string {
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) {