77 lines
2.7 KiB
Go
77 lines
2.7 KiB
Go
package strategies
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.kleiax.de/homepage/field"
|
|
)
|
|
|
|
// ────────────────────────────────────────────────────────────────────────────── //
|
|
// STRATEGY INTERFACE //
|
|
// ────────────────────────────────────────────────────────────────────────────── //
|
|
|
|
type Strategy interface {
|
|
Init(f *field.Field)
|
|
ApplyAll() []field.ExternalChange
|
|
ApplyNext() field.ExternalChange
|
|
Name() string
|
|
SearchProgressableCells() int
|
|
}
|
|
|
|
// ────────────────────────────────────────────────────────────────────────────── //
|
|
// VISUALITION INTERFACE //
|
|
// ────────────────────────────────────────────────────────────────────────────── //
|
|
|
|
type StrategyVisualization interface {
|
|
pointOut(f *field.Field) []field.Mark
|
|
}
|
|
|
|
// ────────────────────────────────────────────────────────────────────────────── //
|
|
// BASE STRUCTURE //
|
|
// ────────────────────────────────────────────────────────────────────────────── //
|
|
|
|
type Base struct {
|
|
name string
|
|
field *field.Field
|
|
changes []field.ExternalChange
|
|
}
|
|
|
|
func (b *Base) Init(f *field.Field) {
|
|
b.field = f
|
|
}
|
|
|
|
func (b *Base) ApplyAll() []field.ExternalChange {
|
|
changesCopy := make([]field.ExternalChange, len(b.changes))
|
|
copy(changesCopy, b.changes)
|
|
|
|
for _, change := range b.changes {
|
|
b.field.AddChange(&change)
|
|
}
|
|
|
|
b.changes = b.changes[:0]
|
|
|
|
return changesCopy
|
|
}
|
|
|
|
func (b *Base) ApplyNext() field.ExternalChange {
|
|
if len(b.changes) < 1 {
|
|
return field.ExternalChange{}
|
|
}
|
|
|
|
changeCopy := b.changes[0]
|
|
|
|
b.field.AddChange(&b.changes[0])
|
|
|
|
b.changes = b.changes[1:]
|
|
|
|
return changeCopy
|
|
}
|
|
|
|
func (b *Base) getName() string {
|
|
return "Unkown"
|
|
}
|
|
|
|
func (b *Base) Name() string {
|
|
return fmt.Sprintf("Diese Strategie heißt: %s", b.getName())
|
|
}
|