Implement Scrabble move generator (DAWG) with English and Russian rules
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.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package rack
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRackBasics(t *testing.T) {
|
||||
r := New(26)
|
||||
if !r.Empty() || r.Total() != 0 {
|
||||
t.Fatal("new rack not empty")
|
||||
}
|
||||
|
||||
r.Add(0) // a
|
||||
r.Add(0)
|
||||
r.Add(2) // c
|
||||
r.AddBlank()
|
||||
|
||||
if r.Count(0) != 2 {
|
||||
t.Errorf("Count(a) = %d, want 2", r.Count(0))
|
||||
}
|
||||
if !r.Has(2) || r.Has(1) {
|
||||
t.Errorf("Has c=%v b=%v, want true,false", r.Has(2), r.Has(1))
|
||||
}
|
||||
if r.Blanks() != 1 {
|
||||
t.Errorf("Blanks = %d, want 1", r.Blanks())
|
||||
}
|
||||
if r.Total() != 4 {
|
||||
t.Errorf("Total = %d, want 4", r.Total())
|
||||
}
|
||||
|
||||
r.Remove(0)
|
||||
if r.Count(0) != 1 {
|
||||
t.Errorf("after Remove, Count(a) = %d, want 1", r.Count(0))
|
||||
}
|
||||
r.RemoveBlank()
|
||||
if r.Blanks() != 0 {
|
||||
t.Errorf("after RemoveBlank, Blanks = %d, want 0", r.Blanks())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRackCloneIndependent(t *testing.T) {
|
||||
r := New(26)
|
||||
r.Add(0)
|
||||
cp := r.Clone()
|
||||
cp.Add(0)
|
||||
cp.AddBlank()
|
||||
if r.Count(0) != 1 || r.Blanks() != 0 {
|
||||
t.Errorf("mutating clone changed original: a=%d blanks=%d", r.Count(0), r.Blanks())
|
||||
}
|
||||
if cp.Count(0) != 2 || cp.Blanks() != 1 {
|
||||
t.Errorf("clone wrong: a=%d blanks=%d", cp.Count(0), cp.Blanks())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user