Documentation
¶
Overview ¶
Package automatic contains all the logic for the actual gameplay of Crossword Game, which, as we said before, features all sorts of things like wingos and blonks.
Index ¶
- Variables
- func AnalyzeLogFile(filepath string) (string, error)
- func ExportGCG(cfg *config.Config, filename, letterdist, lexicon, boardlayout, gid string, ...) error
- func FormatTable(r *AnalysisResult) string
- func GenerateSeeds(n int) ([][32]byte, error)
- func LoadAutoplayConfig(path string) (*pb.AutoplayConfig, error)
- func LoadSeeds(path string) ([][32]byte, error)
- func ResolveExperimentID(cfg *pb.AutoplayConfig) string
- func SaveSeeds(seeds [][32]byte, path string) error
- func StartAutoplayFromConfig(ctx context.Context, appCfg *config.Config, expCfg *pb.AutoplayConfig) (string, error)
- func StartCompVCompStaticGames(ctx context.Context, cfg *config.Config, numGames int, block bool, threads int, ...) error
- func StartServer(addr string) error
- type AnalysisResult
- type AutomaticRunnerPlayer
- type DeterministicConfig
- type GameRunner
- func (r *GameRunner) BotTypeFor(playerIdx int) pb.BotRequest_BotCode
- func (r *GameRunner) CompVsCompStatic(addToHistory bool) error
- func (r *GameRunner) Game() *game.Game
- func (r *GameRunner) Init(players []AutomaticRunnerPlayer) error
- func (r *GameRunner) PlayBestTurn(playerIdx int, addToHistory bool) error
- func (r *GameRunner) StartGame(gidx int)
- func (r *GameRunner) StartGameWithSeed(gidx int, seed [32]byte)
- type Job
- type PlayerStats
- type ShadowAgreementResult
- type WMPAgreementResult
Constants ¶
This section is empty.
Variables ¶
var ( CVCCounter *expvar.Int IsPlaying *expvar.Int )
var MaxTimePerEndgame = 15 * time.Second
var MaxTimePerTurn = 30 * time.Second
Functions ¶
func AnalyzeLogFile ¶ added in v0.4.2
AnalyzeLogFile analyzes the given game CSV file and returns formatted stats. Kept for backward compatibility.
func FormatTable ¶ added in v0.13.0
func FormatTable(r *AnalysisResult) string
FormatTable formats analysis results as a side-by-side comparison table.
func GenerateSeeds ¶ added in v0.11.8
GenerateSeeds creates n random 32-byte seeds for deterministic game runs
func LoadAutoplayConfig ¶ added in v0.13.0
func LoadAutoplayConfig(path string) (*pb.AutoplayConfig, error)
LoadAutoplayConfig reads an AutoplayConfig from a protojson file.
func ResolveExperimentID ¶ added in v0.13.0
func ResolveExperimentID(cfg *pb.AutoplayConfig) string
ResolveExperimentID returns the experiment ID from the config, or generates one from the current timestamp and 6 random hex characters.
func StartAutoplayFromConfig ¶ added in v0.13.0
func StartAutoplayFromConfig(ctx context.Context, appCfg *config.Config, expCfg *pb.AutoplayConfig) (string, error)
StartAutoplayFromConfig runs an autoplay experiment defined by a protojson config file. It returns the resolved experiment ID. Output files are written to cfg.OutputDir (or the current directory if empty):
- {experimentId}.txt — per-turn log
- games-{experimentId}.txt — per-game summary
- {experimentId}.config.json — copy of the config for reproducibility
func StartServer ¶ added in v0.13.0
StartServer starts an HTTP server on the given address that exposes the autoanalyze endpoint. Call as:
curl 'http://host:8080/analyze?file=games.txt' curl 'http://host:8080/analyze?file=games.txt&format=json'
Types ¶
type AnalysisResult ¶ added in v0.13.0
type AnalysisResult struct {
GamesPlayed int
Player1 PlayerStats
Player2 PlayerStats
P1Wins float64
P1First float64
WentFirstWins float64
WinPValue float64 // two-sided binomial z-test, H0: win rate = 0.5
ScorePValue float64 // two-sided paired z-test on per-game score diff
ScoreDiff *stats.Statistic
}
AnalysisResult holds the full results of analyzing a log file.
func AnalyzeLogFileData ¶ added in v0.13.0
func AnalyzeLogFileData(filepath string) (*AnalysisResult, error)
AnalyzeLogFileData analyzes the given game CSV file and returns structured results.
type AutomaticRunnerPlayer ¶ added in v0.5.0
type AutomaticRunnerPlayer struct {
LeaveFile string
PEGFile string
BotCode pb.BotRequest_BotCode
MinSimPlies int
SimThreads int
StochasticStaticEval bool
InferenceTau float64
InferenceTimeSecs int
InferenceSimIters int
InferenceMaxEnumeratedLeaves int
OracleInference bool
}
func PlayersFromConfig ¶ added in v0.13.0
func PlayersFromConfig(cfg *pb.AutoplayConfig) []AutomaticRunnerPlayer
PlayersFromConfig converts an AutoplayConfig's player configs to AutomaticRunnerPlayer structs.
type DeterministicConfig ¶ added in v0.11.8
type DeterministicConfig struct {
Seeds [][32]byte // Pre-generated seeds (nil = generate new)
SeedFile string // File to read/write seeds
NumGames int // Number of games (used when generating seeds)
}
DeterministicConfig holds configuration for deterministic autoplay runs
type GameRunner ¶
type GameRunner struct {
// contains filtered or unexported fields
}
GameRunner is the master struct here for the automatic game logic.
func NewGameRunner ¶ added in v0.4.2
func NewGameRunner(logchan chan string, cfg *config.Config) *GameRunner
NewGameRunner just instantiates and initializes a game runner.
func (*GameRunner) BotTypeFor ¶ added in v0.13.0
func (r *GameRunner) BotTypeFor(playerIdx int) pb.BotRequest_BotCode
BotTypeFor returns the bot code for the given game-level player index. Accounts for player flips done by StartGameWithSeed.
func (*GameRunner) CompVsCompStatic ¶
func (r *GameRunner) CompVsCompStatic(addToHistory bool) error
CompVsCompStatic plays out a game to the end using best static turns.
func (*GameRunner) Game ¶ added in v0.4.5
func (r *GameRunner) Game() *game.Game
func (*GameRunner) Init ¶
func (r *GameRunner) Init(players []AutomaticRunnerPlayer) error
Init initializes the runner
func (*GameRunner) PlayBestTurn ¶ added in v0.5.0
func (r *GameRunner) PlayBestTurn(playerIdx int, addToHistory bool) error
PlayBestTurn generates the best move for the player and plays it on the board.
func (*GameRunner) StartGame ¶
func (r *GameRunner) StartGame(gidx int)
func (*GameRunner) StartGameWithSeed ¶ added in v0.11.8
func (r *GameRunner) StartGameWithSeed(gidx int, seed [32]byte)
type PlayerStats ¶ added in v0.13.0
type PlayerStats struct {
Name string
Score *stats.Statistic
Bingos *stats.Statistic
PPT *stats.Statistic
}
PlayerStats holds per-player statistics accumulators.
type ShadowAgreementResult ¶ added in v0.12.4
type ShadowAgreementResult struct {
GamesPlayed int
TurnsPlayed int
Disagreements int
Details []string
}
ShadowAgreementResult holds the results of a shadow agreement test.
func RunShadowAgreementTest ¶ added in v0.12.4
func RunShadowAgreementTest(cfg *config.Config, numGames int) (*ShadowAgreementResult, error)
RunShadowAgreementTest plays numGames game pairs, comparing moves generated with and without shadow. Both algorithms must produce the same top move by score on every turn. Games use deterministic seeds for reproducibility.
type WMPAgreementResult ¶ added in v0.13.0
type WMPAgreementResult struct {
GamesPlayed int
TurnsPlayed int
Disagreements int
Details []string
}
WMPAgreementResult holds the results of a WMP agreement test.
func RunWMPAgreementTest ¶ added in v0.13.0
RunWMPAgreementTest plays numGames deterministic games, comparing the top play produced by the non-WMP movegen against the top play produced by the WMP movegen on every turn. Both must match by ShortDescription, score, and equity (within 1e-6).
This exercises exactly the path Simmer's rollout loop drives: SetPlayRecorderTopPlay (shadow enabled), addExchange=true, with an equity calculator wired in. It broadens the assertions of montecarlo/wmp_equivalence_test.go across diverse positions drawn from real deterministic play rather than a fixed CGP catalogue.
Games advance along the noWMP generator's top move (the canonical path), so a disagreement is reported at the earliest turn where the two generators diverge. The game then continues along the noWMP choice, which keeps the seed->position mapping reproducible across branches and across WMP-on/off runs.