automatic

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2026 License: GPL-3.0 Imports: 43 Imported by: 1

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

Constants

This section is empty.

Variables

View Source
var (
	CVCCounter *expvar.Int
	IsPlaying  *expvar.Int
)
View Source
var MaxTimePerEndgame = 15 * time.Second
View Source
var MaxTimePerTurn = 30 * time.Second

Functions

func AnalyzeLogFile added in v0.4.2

func AnalyzeLogFile(filepath string) (string, error)

AnalyzeLogFile analyzes the given game CSV file and returns formatted stats. Kept for backward compatibility.

func ExportGCG added in v0.4.10

func ExportGCG(cfg *config.Config, filename, letterdist, lexicon, boardlayout, gid string,
	out io.Writer) error

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

func GenerateSeeds(n int) ([][32]byte, error)

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 LoadSeeds added in v0.11.8

func LoadSeeds(path string) ([][32]byte, error)

LoadSeeds reads seeds from a file in base64 format

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 SaveSeeds added in v0.11.8

func SaveSeeds(seeds [][32]byte, path string) error

SaveSeeds writes seeds to a file in base64 format (one per line)

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 StartCompVCompStaticGames

func StartCompVCompStaticGames(ctx context.Context, cfg *config.Config,
	numGames int, block bool, threads int,
	outputFilename, lexicon, letterDistribution string,
	players []AutomaticRunnerPlayer, detConfig *DeterministicConfig) error

func StartServer added in v0.13.0

func StartServer(addr string) error

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 Job

type Job struct {
	// contains filtered or unexported fields
}

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

func RunWMPAgreementTest(cfg *config.Config, w *wmp.WMP, numGames int) (*WMPAgreementResult, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL