engine: Config, scenario runner, golden regression tests; demo CLI
Config is the single source of truth for parameters (TS types will be generated from these structs in milestone 2); all randomness flows from its three seeds, so identical configs give identical results. Golden test pins the default world: none=99/120 (82%), random=70/120 (58%), most-connected=7/120 (6%). Same story as the prototype's 85/64/8 with different dice; the ordering and the collapse are asserted explicitly, exact Python numbers are out of scope by design. 'go run ./cmd/spreadlab' prints the three-scenario comparison. This completes milestone 1 (engine ported, parameterised, tested).
This commit is contained in:
parent
c40e483ee6
commit
45fdf7ffa4
3 changed files with 216 additions and 4 deletions
|
|
@ -1,9 +1,35 @@
|
|||
// Command spreadlab will serve the spreadlab dashboard. For now it only
|
||||
// proves the module builds; the HTTP server arrives in milestone 2.
|
||||
// Command spreadlab will serve the spreadlab dashboard. Until the HTTP
|
||||
// server lands (milestone 2), it runs the prototype's three scenarios in
|
||||
// the default world and prints the comparison.
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/JustinZeus/spreadlab/internal/engine"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("spreadlab: engine under construction (milestone 1)")
|
||||
config := engine.DefaultConfig()
|
||||
fmt.Printf("spreadlab: %d students, educate %d, forwarding probability %.2f\n",
|
||||
config.NumStudents, config.NumEducated, config.ForwardProb)
|
||||
fmt.Println("(illustrative, not validated)")
|
||||
fmt.Println()
|
||||
|
||||
strategies := []engine.Strategy{
|
||||
engine.StrategyNone,
|
||||
engine.StrategyRandom,
|
||||
engine.StrategyMostConnected,
|
||||
}
|
||||
for _, strategy := range strategies {
|
||||
result, err := engine.RunScenario(config, strategy)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "spreadlab:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("%-15s educated=%3d reached=%3d/%d (%2.0f%%) in %d rounds\n",
|
||||
result.Strategy, len(result.Educated), result.NumReached,
|
||||
config.NumStudents, result.ReachedPct, result.NumRounds)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue