clone

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

main
puzzletea / games / hashiwokakero / gamemode.go
gamemode.go 2.9K
1package hashiwokakero23import (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 HashiMode struct {17 game.BaseMode18 Width int19 Height int20 MinIslands int21 MaxIslands int22}2324var (25 _ game.Mode = HashiMode{}26 _ game.Spawner = HashiMode{}27 _ game.SeededSpawner = HashiMode{}28 _ game.EloSpawner = HashiMode{}29)3031func NewMode(title, description string, width, height, minIslands, maxIslands int) HashiMode {32 return HashiMode{33 BaseMode: game.NewBaseMode(title, description),34 Width: width,35 Height: height,36 MinIslands: minIslands,37 MaxIslands: maxIslands,38 }39}4041func (h HashiMode) Spawn() (game.Gamer, error) {42 puzzle, err := GeneratePuzzle(h)43 if err != nil {44 return nil, err45 }46 return New(h, puzzle), nil47}4849func (h HashiMode) SpawnSeeded(rng *rand.Rand) (game.Gamer, error) {50 puzzle, err := GeneratePuzzleSeeded(h, rng)51 if err != nil {52 return nil, err53 }54 return New(h, puzzle), nil55}5657var Modes = []game.Mode{58 NewMode("Easy 7x7", "7x7 grid with 8-10 islands.", 7, 7, 8, 10),59 NewMode("Medium 7x7", "7x7 grid with 12-15 islands.", 7, 7, 12, 15),60 NewMode("Hard 7x7", "7x7 grid with 17-20 islands.", 7, 7, 17, 20),61 NewMode("Easy 9x9", "9x9 grid with 12-16 islands.", 9, 9, 12, 16),62 NewMode("Medium 9x9", "9x9 grid with 20-24 islands.", 9, 9, 20, 24),63 NewMode("Hard 9x9", "9x9 grid with 28-32 islands.", 9, 9, 28, 32),64 NewMode("Easy 11x11", "11x11 grid with 18-24 islands.", 11, 11, 18, 24),65 NewMode("Medium 11x11", "11x11 grid with 30-36 islands.", 11, 11, 30, 36),66 NewMode("Hard 11x11", "11x11 grid with 42-48 islands.", 11, 11, 42, 48),67 NewMode("Easy 13x13", "13x13 grid with 25-34 islands.", 13, 13, 25, 34),68 NewMode("Medium 13x13", "13x13 grid with 42-51 islands.", 13, 13, 42, 51),69 NewMode("Hard 13x13", "13x13 grid with 59-68 islands.", 13, 13, 59, 68),70}7172var ModeDefinitions = hashiModeDefinitions(Modes)7374func hashiModeDefinitions(modes []game.Mode) []puzzle.ModeDef {75 defs := gameentry.BuildModeDefs(modes)76 presets := []difficulty.Elo{250, 500, 800, 700, 1100, 1500, 1300, 1700, 2100, 1900, 2400, 2900}77 for i, mode := range modes {78 if i >= len(defs) || i >= len(presets) {79 break80 }81 if _, ok := mode.(game.EloSpawner); !ok {82 continue83 }84 elo := presets[i]85 defs[i].PresetElo = &elo86 }87 return defs88}8990var Definition = puzzle.NewDefinition(puzzle.DefinitionSpec{91 Name: "Hashiwokakero",92 Description: "Connect the islands with bridges.",93 Aliases: []string{"hashi", "bridges"},94 Modes: ModeDefinitions,95 DailyModeIDs: puzzle.SelectModeIDsByIndex(ModeDefinitions, 3, 1),96})9798var Entry = gameentry.NewEntry(gameentry.EntrySpec{99 Definition: Definition,100 Help: HelpContent,101 Import: game.AdaptImport(ImportModel),102 Modes: Modes,103 Print: PDFPrintAdapter,104})