clone

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

bug/architecture-test-trim-path
puzzletea / games / wordsearch / gamemode.go
gamemode.go 2.6K
1package wordsearch23import (4 _ "embed"5 "math/rand/v2"67 "github.com/FelineStateMachine/puzzletea/difficulty"8 "github.com/FelineStateMachine/puzzletea/game"9 "github.com/FelineStateMachine/puzzletea/gameentry"10 "github.com/FelineStateMachine/puzzletea/puzzle"11)1213//go:embed help.md14var HelpContent string1516type WordSearchMode struct {17 game.BaseMode18 Width int19 Height int20 WordCount int21 MinWordLen int22 MaxWordLen int23 AllowedDirs []Direction24}2526var (27 _ game.Mode = WordSearchMode{}28 _ game.Spawner = WordSearchMode{}29 _ game.SeededSpawner = WordSearchMode{}30 _ game.EloSpawner = WordSearchMode{}31)3233func NewMode(title, description string, width, height, wordCount, minLen, maxLen int, allowedDirs []Direction) WordSearchMode {34 return WordSearchMode{35 BaseMode: game.NewBaseMode(title, description),36 Width: width,37 Height: height,38 WordCount: wordCount,39 MinWordLen: minLen,40 MaxWordLen: maxLen,41 AllowedDirs: allowedDirs,42 }43}4445func (w WordSearchMode) Spawn() (game.Gamer, error) {46 grid, words := GenerateWordSearch(w.Width, w.Height, w.WordCount, w.MinWordLen, w.MaxWordLen, w.AllowedDirs)47 return New(w, grid, words)48}4950func (w WordSearchMode) SpawnSeeded(rng *rand.Rand) (game.Gamer, error) {51 grid, words := GenerateWordSearchSeeded(w.Width, w.Height, w.WordCount, w.MinWordLen, w.MaxWordLen, w.AllowedDirs, rng)52 return New(w, grid, words)53}5455var Modes = []game.Mode{56 NewMode("Easy 10x10", "Find 6 words in a 10x10 grid.", 10, 10, 6, 3, 5, []Direction{Right, Down, DownRight}),57 NewMode("Medium 15x15", "Find 10 words in a 15x15 grid.", 15, 15, 10, 4, 7, []Direction{Right, Down, DownRight, DownLeft, Left, Up}),58 NewMode("Hard 20x20", "Find 15 words in a 20x20 grid.", 20, 20, 15, 5, 10, []Direction{Right, Down, DownRight, DownLeft, Left, Up, UpRight, UpLeft}),59}6061var ModeDefinitions = wordSearchModeDefinitions(Modes)6263func wordSearchModeDefinitions(modes []game.Mode) []puzzle.ModeDef {64 defs := gameentry.BuildModeDefs(modes)65 presets := []difficulty.Elo{600, 1500, 2400}66 for i := range defs {67 if i >= len(presets) {68 break69 }70 elo := presets[i]71 defs[i].PresetElo = &elo72 }73 return defs74}7576var Definition = puzzle.NewDefinition(puzzle.DefinitionSpec{77 Name: "Word Search",78 Description: "Find the hidden words in a letter grid.",79 Aliases: []string{"words", "wordsearch", "ws"},80 Modes: ModeDefinitions,81 DailyModeIDs: puzzle.SelectModeIDsByIndex(ModeDefinitions, 0),82})8384var Entry = gameentry.NewEntry(gameentry.EntrySpec{85 Definition: Definition,86 Help: HelpContent,87 Import: game.AdaptImport(ImportModel),88 Modes: Modes,89 Print: PDFPrintAdapter,90})