Initial commit

This commit is contained in:
2026-07-17 22:35:11 +02:00
parent 3121a7d818
commit 1ff0efb557
31 changed files with 895046 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
package logic
type Change struct {
}
+1
View File
@@ -0,0 +1 @@
package logic
+43
View File
@@ -0,0 +1,43 @@
package logic
import "git.kleiax.de/homepage/libs/sudoku/board"
// ────────────────────────────────────────────────────────────────────────────── //
// SOLVER STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
type Solver struct {
strategies []Strategy
conf struct {
all bool
repeat bool
}
}
func (s *Solver) Add(strategy Strategy) {
s.strategies = append(s.strategies, strategy)
}
func (s *Solver) initStragies(field *board.Field) {
for _, strategy := range s.strategies {
strategy.Init(field)
}
}
func (s *Solver) run(i int) bool {
//TODO: clean und Fehlerauffangen
s.strategies[i].SearchProgressableCells()
numberOfChanges := s.strategies[i].ApplyAll()
if numberOfChanges == 0 {
return false
}
return true
}
func (s *Solver) search() {
}
func (s *Solver) getSolutionPath() []board.Change {
return nil
}
+15
View File
@@ -0,0 +1,15 @@
package strategies
type XChain struct {
Base
}
type XYChain struct {
Base
}
type XChainLoop struct {
Base
}
type XYChainLoop struct {
Base
}
+53
View File
@@ -0,0 +1,53 @@
package strategies
import "git.kleiax.de/homepage/libs/sudoku/board"
// ────────────────────────────────────────────────────────────────────────────── //
// LAST_DIGIT STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
type LastDigit struct {
Base
}
func (ld *LastDigit) SearchProgressableCells() int {
ld.field.ForEachPart(func(part board.Part) {
missingNumbers := part.GetMissingNumbers()
if len(missingNumbers) == 1 {
// var emptyCell *Cell
// part.forEachCell(func(cell *Cell) {
// if cell.number == 0 {
// emptyCell = cell
// }
// })
// change := Change{
// cell: emptyCell,
// action: ActionSetNumber,
// value: missingNumbers[0],
// }
// ld.changes = append(ld.changes, change)
}
})
//fmt.Printf("LastDigit Changes %d", len(ld.changes))
return len(ld.changes)
}
func (ld *LastDigit) getName() string {
return "Last Digit - Letzte Zahl"
}
// ────────────────────────────────────────────────────────────────────────────── //
// CRP STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
type CRP struct {
Base
}
// ────────────────────────────────────────────────────────────────────────────── //
// SIMPLE_COLORING_T1 STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
type SimpleColoringT1 struct {
Base
}
+25
View File
@@ -0,0 +1,25 @@
package strategies
// ────────────────────────────────────────────────────────────────────────────── //
// HIDDEN_SINGLE STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
type HiddenSingle struct {
Base
}
// ────────────────────────────────────────────────────────────────────────────── //
// HIDDEN_PAIR STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
type HiddenPair struct {
Base
}
// ────────────────────────────────────────────────────────────────────────────── //
// HIDDEN_TRIPLE STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
type HiddenTriple struct {
Base
}
+12
View File
@@ -0,0 +1,12 @@
package strategies
type LockedPair struct {
Base
}
type LockedCandidateT1 struct {
Base
}
type LockedCandidateT2 struct {
Base
}
+44
View File
@@ -0,0 +1,44 @@
package strategies
import "git.kleiax.de/homepage/libs/sudoku/board"
// ────────────────────────────────────────────────────────────────────────────── //
// NAKED_SINGLE STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
type NakedSingle struct {
Base
}
func (ns *NakedSingle) SearchProgressableCells() int {
ns.field.ForEachPart(func(part board.Part) {
part.ForEachCell(func(cell *board.Cell) {
// candidates := cell.notes.numbers
// if len(candidates) == 1 {
// change := Change{
// cell: cell,
// action: ActionSetNumber,
// value: candidates[0],
// }
// ns.changes = append(ns.changes, change)
// }
})
})
return len(ns.changes)
}
// ────────────────────────────────────────────────────────────────────────────── //
// NAKED_DOUBLE STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
type NakedPair struct {
Base
}
// ────────────────────────────────────────────────────────────────────────────── //
// NAKED_TRIPLE STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
type NakedTriple struct {
Base
}
+14
View File
@@ -0,0 +1,14 @@
package strategies
type EmptyRectangle struct {
Base
}
type UniqueRectangleT1 struct {
Base
}
type UniqueRectangleT4 struct {
Base
}
type UniqueRectangleT7 struct {
Base
}
+67
View File
@@ -0,0 +1,67 @@
package strategies
import (
"fmt"
"git.kleiax.de/homepage/libs/sudoku/board"
)
// ────────────────────────────────────────────────────────────────────────────── //
// STRATEGY INTERFACE //
// ────────────────────────────────────────────────────────────────────────────── //
type Strategy interface {
Init(f *board.Field)
ApplyAll() int
ApplyNext() bool
ApplyOne(n int) bool
Name() string
SearchProgressableCells() int
}
// ────────────────────────────────────────────────────────────────────────────── //
// BASE STRUCTURE //
// ────────────────────────────────────────────────────────────────────────────── //
type Base struct {
name string
field *board.Field
changes []board.Change //eigener Typ muss her
}
func (b *Base) Init(f *board.Field) {
b.field = f
}
func (b *Base) ApplyAll() int {
// for _, change := range sb.changes {
// //change.do()
// }
return len(b.changes)
}
func (b *Base) ApplyNext() bool {
if len(b.changes) < 1 {
return false
}
//sb.changes[0].do()
b.changes = b.changes[1:]
return true
}
func (b *Base) ApplyOne(n int) bool {
if len(b.changes) <= n || n < 0 {
return false
}
//sb.changes[n].do()
b.changes = append(b.changes[:n], b.changes[n+1:]...)
return true
}
func (b *Base) getName() string {
return "Unkown"
}
func (b *Base) Name() string {
return fmt.Sprintf("Die Strategie heißt: %s", b.getName())
}
+8
View File
@@ -0,0 +1,8 @@
package strategies
type Turbot2StringKite struct {
Base
}
type TurbotSkyscraper struct {
Base
}
+14
View File
@@ -0,0 +1,14 @@
package strategies
type XWing struct {
Base
}
type XYWing struct {
Base
}
type XYZWing struct {
Base
}
type WXYZWingBasic struct {
Base
}