15c7959d96
A Go library that returns every legal play ranked by score and scores or validates plays, using the Appel-Jacobson DAWG algorithm over github.com/iliadenisov/dafsa v1.1.0. - DAWG move generation (across / down / both), full tournament scoring with a per-tile breakdown; public Solver: GenerateMoves (ranked), ScorePlay, ValidatePlay. - Rulesets: English Scrabble, Russian Scrabble, Эрудит (parameterizable Ruleset). - cmd/builddict (build the DAWG from the dictionaries submodule), cmd/stress (self-play benchmark), selfplay engine; brute-force test oracle. - A GADDAG was implemented, benchmarked and removed (the DAWG was smaller and faster for a scoring solver); see RESULTS.md and ALGORITHM.md.
31 lines
925 B
Go
31 lines
925 B
Go
// Package dictdawg builds a plain left-to-right DAWG of a dictionary, as used by the
|
|
// Appel-Jacobson move generator.
|
|
package dictdawg
|
|
|
|
import (
|
|
"github.com/iliadenisov/alphabet"
|
|
dawg "github.com/iliadenisov/dafsa"
|
|
)
|
|
|
|
// Build returns a DAWG Finder over words, which must be alphabet-index slices sorted by
|
|
// index order and de-duplicated (see wordlist.Encode).
|
|
func Build(idx alphabet.Indexer, words [][]byte) (dawg.Finder, error) {
|
|
d := dawg.New(idx)
|
|
for _, w := range words {
|
|
if err := d.AddB(w); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return d.Finish(), nil
|
|
}
|
|
|
|
// Save writes the DAWG to filename. It requires an embedded alphabet (for example
|
|
// alphabet.Latin()), so that Load can reconstruct it.
|
|
func Save(f dawg.Finder, filename string) error {
|
|
_, err := f.Save(filename)
|
|
return err
|
|
}
|
|
|
|
// Load reopens a DAWG saved with Save.
|
|
func Load(filename string) (dawg.Finder, error) { return dawg.Load(filename) }
|