clone

fifteen puzzle games for the terminal, with daily puzzles, weekly ladders and xp, built on bubble tea

feat/app-decomposition
puzzletea / games / nonogram / gamemode.go
gamemode.go 2.4K
1package nonogram23import (4 _ "embed"5 "math/rand/v2"67 "github.com/FelineStateMachine/puzzletea/game"8 "github.com/FelineStateMachine/puzzletea/gameentry"9 "github.com/FelineStateMachine/puzzletea/puzzle"10)1112//go:embed help.md13var HelpContent string1415type NonogramMode struct {16 game.BaseMode17 Width, Height int18 Density float64 // target fill percentage, 0.0–1.019}2021var (22 _ game.Mode = NonogramMode{}23 _ game.Spawner = NonogramMode{}24 _ game.SeededSpawner = NonogramMode{}25)2627func NewMode(title, description string, width, height int, density float64) NonogramMode {28 return NonogramMode{29 BaseMode: game.NewBaseMode(title, description),30 Width: width,31 Height: height,32 Density: density,33 }34}3536func (n NonogramMode) Spawn() (game.Gamer, error) {37 hints := GenerateRandomTomography(n)38 return New(n, hints)39}4041func (n NonogramMode) SpawnSeeded(rng *rand.Rand) (game.Gamer, error) {42 hints := GenerateRandomTomographySeeded(n, rng)43 return New(n, hints)44}4546var Modes = []game.Mode{47 // 5x548 NewMode("Mini", "5x5 grid, ~65% filled. Quick puzzle, straightforward hints.", 5, 5, 0.65),49 NewMode("Pocket", "5x5 grid, ~50% filled. Compact but balanced.", 5, 5, 0.50),50 NewMode("Teaser", "5x5 grid, ~35% filled. Small but tricky.", 5, 5, 0.35),51 // 10x1052 NewMode("Standard", "10x10 grid, ~67% filled. Classic size, dense hints.", 10, 10, 0.67),53 NewMode("Classic", "10x10 grid, ~52% filled. The typical nonogram experience.", 10, 10, 0.52),54 NewMode("Tricky", "10x10 grid, ~37% filled. Sparse hints require reasoning.", 10, 10, 0.37),55 // 15x1556 NewMode("Large", "15x15 grid, ~69% filled. Bigger grid, constraining hints.", 15, 15, 0.69),57 NewMode("Grand", "15x15 grid, ~54% filled. A substantial challenge.", 15, 15, 0.54),58 // 20x2059 NewMode("Epic", "20x20 grid, ~71% filled. A epic undertaking.", 20, 20, 0.71),60 NewMode("Massive", "20x20 grid, ~56% filled. Truly massive puzzle.", 20, 20, 0.56),61}6263var ModeDefinitions = gameentry.BuildModeDefs(Modes)6465var Definition = puzzle.NewDefinition(puzzle.DefinitionSpec{66 Name: "Nonogram",67 Description: "Fill the cells to match tomographic hints.",68 Modes: ModeDefinitions,69 DailyModeIDs: puzzle.SelectModeIDsByIndex(ModeDefinitions, 3, 4),70})7172var Entry = gameentry.NewEntry(gameentry.EntrySpec{73 Definition: Definition,74 Help: HelpContent,75 Import: game.AdaptImport(ImportModel),76 Modes: Modes,77 Print: PDFPrintAdapter,78})