Files
tiennm99 e29c06d6f0 refactor: move test-only helpers out of production code and drop stale comments
bot.BoardFor and hub.roomCount were reachable from tests only and now live beside them; session.serve drops an always-true nil check (readLoop never returns nil); invisible characters in test literals become escapes; comments no longer cite plan phases; `.dockerignore` keeps the dump out of the build context. No behaviour change; vet, deadcode, staticcheck, go test -race, svelte-check and vitest green.
2026-09-08 23:10:39 +07:00

37 lines
1.1 KiB
Go

package bot
import (
"iter"
"github.com/tiennm99dev/noitu/server/internal/game"
)
// engineBoard adapts an Engine to Board for the simulations in this package.
// The server never needs it: the room hands the bot a Board of its own.
type engineBoard struct {
e *game.Engine
dict game.Dictionary
}
// BoardFor wraps an engine so a test can drive a strategy against it.
//
// The dictionary comes from the engine rather than the caller: handing in a
// different one would let the bot search a graph the engine does not validate
// against, and that failure surfaces as the engine rejecting its own bot's
// move at runtime.
func BoardFor(e *game.Engine) Board {
return &engineBoard{e: e, dict: e.Dict()}
}
func (b *engineBoard) LegalMoves() []string { return b.e.LegalMoves() }
func (b *engineBoard) Used(word string) bool { return b.e.Used(word) }
func (b *engineBoard) WordsStartingWith(syllable string) iter.Seq[string] {
return b.dict.WordsStartingWith(syllable)
}
func (b *engineBoard) LastSyllable(word string) (string, bool) {
return b.dict.LastSyllable(word)
}