- commit
- cfe1c313f7ad127acc5ba79596ffee47ef72a6f4
- parent
- 31aba7fdb0740572e0f5f60658a9afa02c33604f
- author
- Dami <dami.etoile@gmail.com>
| M | AGENTS.md | 8 | ++++++++ |
| M | README.md | 6 | +++++- |
| M | cmd/ | 25 | +++++++++++++++++++++---- |
| M | cmd/ | 2 | +- |
| M | vhs/ | 2 | +- |
| M | vhs/ | 2 | +- |
| M | vhs/ | 2 | +- |
| M | vhs/ | 2 | +- |
| M | vhs/ | 2 | +- |
| M | vhs/ | 6 | +++--- |
| M | vhs/ | 2 | +- |
| M | vhs/ | 2 | +- |
| M | vhs/ | 2 | +- |
| M | vhs/ | 2 | +- |
| M | vhs/ | 2 | +- |
| M | vhs/ | 4 | ++-- |
@@ -11,6 +11,14 @@ just clean # remove binary and dist/
1111 ```1212 Without `just`: `go build -ldflags "-X github.com/FelineStateMachine/puzzletea/cmd.Version=$(git describe --tags --always --dirty)" -o puzzletea`1313 14+### CLI Seed Flags15+```bash16+puzzletea new --set-seed myseed # deterministic game/mode/puzzle selection17+puzzletea new nonogram epic --with-seed s1 # deterministic puzzle in selected game/mode18+```19+- `--set-seed` cannot be combined with positional game/mode arguments.20+- `--with-seed` is used with explicit game/mode arguments for mode-local reproducibility.21+1422 ### Testing1523 ```bash1624 just test # go test ./...@@ -96,10 +96,14 @@ puzzletea list --all # include abandoned games
9696 puzzletea continue amber-falcon # resume by name9797 ```9898 99-Use a seed for deterministic puzzle generation:99+Use seeds for deterministic puzzle generation:100100 101101 ```bash102+# Deterministically selects game, mode, and puzzle from one seed.102103 puzzletea new --set-seed myseed104+105+# Deterministically generates a puzzle within a chosen game/mode.106+puzzletea new nonogram epic --with-seed myseed103107 ```104108 105109 Override the color theme:@@ -6,6 +6,7 @@ import (
66 77 "github.com/FelineStateMachine/puzzletea/app"88 "github.com/FelineStateMachine/puzzletea/config"9+ "github.com/FelineStateMachine/puzzletea/game"910 "github.com/FelineStateMachine/puzzletea/namegen"1011 "github.com/FelineStateMachine/puzzletea/resolve"1112 "github.com/FelineStateMachine/puzzletea/stats"@@ -14,7 +15,10 @@ import (
1415 "github.com/spf13/cobra"1516 )1617 17-var flagSetSeed string18+var (19+ flagSetSeed string20+ flagWithSeed string21+)1822 1923 var newCmd = &cobra.Command{2024 Use: "new <game> [mode]",@@ -40,16 +44,17 @@ var newCmd = &cobra.Command{
4044 if len(args) > 1 {4145 modeArg = args[1]4246 }43- return launchNewGame(gameArg, modeArg, cfg)47+ return launchNewGame(gameArg, modeArg, flagWithSeed, cfg)4448 },4549 }4650 4751 func init() {4852 newCmd.Flags().StringVar(&flagSetSeed, "set-seed", "", "seed string for deterministic puzzle selection and generation")53+ newCmd.Flags().StringVar(&flagWithSeed, "with-seed", "", "seed string for deterministic puzzle generation within the selected game/mode")4954 }5055 5156 // launchNewGame resolves the game/mode, spawns a new game, and launches the TUI.52-func launchNewGame(gameArg, modeArg string, cfg *config.Config) error {57+func launchNewGame(gameArg, modeArg, seed string, cfg *config.Config) error {5358 cat, err := resolve.Category(gameArg, app.GameCategories)5459 if err != nil {5560 return err@@ -60,7 +65,7 @@ func launchNewGame(gameArg, modeArg string, cfg *config.Config) error {
6065 return err6166 }6267 63- g, err := spawner.Spawn()68+ g, err := spawnFromMode(spawner, seed)6469 if err != nil {6570 return fmt.Errorf("failed to spawn game: %w", err)6671 }@@ -84,6 +89,18 @@ func launchNewGame(gameArg, modeArg string, cfg *config.Config) error {
8489 return runGameProgram(s, cfg, g, rec.ID, false)8590 }8691 92+func spawnFromMode(spawner game.Spawner, seed string) (game.Gamer, error) {93+ if seed == "" {94+ return spawner.Spawn()95+ }96+97+ seeded, ok := spawner.(game.SeededSpawner)98+ if !ok {99+ return nil, fmt.Errorf("mode does not support deterministic spawning")100+ }101+ return seeded.SpawnSeeded(resolve.RNGFromString(seed))102+}103+87104 // launchSeededGame uses an arbitrary seed string to deterministically select88105 // a game type, mode, and puzzle. The same seed always produces the same puzzle.89106 // If a game with the same seed-derived name already exists, it is resumed.@@ -2,8 +2,8 @@ Output vhs/nonogram.gif
22 33 Set Theme "Monokai Pro"44 Set FontSize 145-Set Width 12006-Set Height 8605+Set Width 16006+Set Height 120077 Set Margin 6088 Set MarginFill "#A85C40"99 Set WindowBar ColorfulRight@@ -19,7 +19,7 @@ Sleep 2s
1919 Ctrl+L2020 Show2121 22-Type "./puzzletea new nonogram epic"22+Type './puzzletea --theme "Monokai Pro" new nonogram epic --with-seed "vhs-nonogram-epic"'2323 Sleep 500ms2424 Enter2525 Sleep 2s@@ -1,7 +1,7 @@
11 Output vhs/wordsearch.gif22 33 Set Theme "Solarized Darcula"4-Set FontSize 164+Set FontSize 1455 Set Width 120066 Set Height 80077 Set Margin 40@@ -20,7 +20,7 @@ Sleep 2s
2020 Ctrl+L2121 Show2222 23-Type "./puzzletea new word-search hard-20x20"23+Type './puzzletea --theme "Solarized Darcula" new word-search hard-20x20 --with-seed "vhs-wordsearch-hard-20x20"'2424 Sleep 500ms2525 Enter2626 Sleep 2s