wordsearch

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 16 Imported by: 0

README

Find hidden words in a letter grid.

Word Search gameplay

How to Play

Words are hidden in the grid horizontally, vertically, and diagonally. Select the first letter of a word, then navigate to the last letter and confirm. Found words are highlighted in green and crossed off the word list. The puzzle is solved when all words are found.

  1. Move the cursor to the start of a word and press Enter or Space.
  2. Navigate to the end of the word.
  3. Press Enter or Space to confirm, or Backspace to cancel.

Controls

Key Action
Arrow keys / WASD / hjkl Move cursor
Enter / Space Select start or confirm end
Backspace Cancel current selection
Ctrl+R Reset puzzle
Ctrl+H Toggle full help
Escape Return to main menu

Modes

Mode Grid Words Directions Description
Easy 10x10 6 3 Right, Down, DownRight
Medium 15x15 10 6 + DownLeft, Left, Up
Hard 20x20 15 8 All 8 directions

Quick Start

puzzletea new word-search easy-10x10
puzzletea new word-search medium-15x15
puzzletea new word-search hard-20x20

Documentation

Overview

Package wordsearch implements the word-finding grid puzzle.

Index

Constants

This section is empty.

Variables

View Source
var DefaultKeyMap = KeyMap{
	CursorKeyMap: game.DefaultCursorKeyMap,
	Select: key.NewBinding(
		key.WithKeys("enter", "space"),
		key.WithHelp("enter/space", "Select"),
	),
	Cancel: key.NewBinding(
		key.WithKeys("backspace"),
		key.WithHelp("bkspc", "Cancel"),
	),
}
View Source
var Definition = puzzle.NewDefinition(puzzle.DefinitionSpec{
	Name:         "Word Search",
	Description:  "Find the hidden words in a letter grid.",
	Aliases:      []string{"words", "wordsearch", "ws"},
	Modes:        ModeDefinitions,
	DailyModeIDs: puzzle.SelectModeIDsByIndex(ModeDefinitions, 0),
})
View Source
var HelpContent string
View Source
var ModeDefinitions = gameentry.BuildModeDefs(Modes)
View Source
var Modes = []game.Mode{
	NewMode("Easy 10x10", "Find 6 words in a 10x10 grid.", 10, 10, 6, 3, 5, []Direction{Right, Down, DownRight}),
	NewMode("Medium 15x15", "Find 10 words in a 15x15 grid.", 15, 15, 10, 4, 7, []Direction{Right, Down, DownRight, DownLeft, Left, Up}),
	NewMode("Hard 20x20", "Find 15 words in a 20x20 grid.", 20, 20, 15, 5, 10, []Direction{Right, Down, DownRight, DownLeft, Left, Up, UpRight, UpLeft}),
}
View Source
var PDFPrintAdapter = printAdapter{}

Functions

func New

func New(mode WordSearchMode, g grid, words []Word) (game.Gamer, error)

Types

type Direction

type Direction int

Direction represents one of 8 possible directions a word can be placed

const (
	Right Direction = iota
	Down
	DownRight
	DownLeft
	Left
	Up
	UpRight
	UpLeft
)

func (Direction) Vector

func (d Direction) Vector() (int, int)

Vector returns the dx, dy unit vector for a direction

type KeyMap

type KeyMap struct {
	game.CursorKeyMap
	Select key.Binding
	Cancel key.Binding
}

type Model

type Model struct {
	// contains filtered or unexported fields
}

func ImportModel

func ImportModel(data []byte) (*Model, error)

func (Model) GetDebugInfo

func (m Model) GetDebugInfo() string

func (Model) GetFullHelp

func (m Model) GetFullHelp() [][]key.Binding

func (Model) GetSave

func (m Model) GetSave() ([]byte, error)

func (Model) Init

func (m Model) Init() tea.Cmd

func (Model) IsSolved

func (m Model) IsSolved() bool

func (Model) Reset added in v1.3.0

func (m Model) Reset() game.Gamer

func (Model) SetTitle

func (m Model) SetTitle(t string) game.Gamer

func (Model) Update

func (m Model) Update(msg tea.Msg) (game.Gamer, tea.Cmd)

func (Model) View

func (m Model) View() string

type Position

type Position struct {
	X, Y int
}

Position represents a coordinate in the grid

type Save

type Save struct {
	Width      int    `json:"width"`
	Height     int    `json:"height"`
	Grid       string `json:"grid"`
	Words      []Word `json:"words"`
	CursorX    int    `json:"cursor_x"`
	CursorY    int    `json:"cursor_y"`
	Selection  int    `json:"selection"`
	SelectionX int    `json:"selection_x"`
	SelectionY int    `json:"selection_y"`
	Solved     bool   `json:"solved"`
}

type Word

type Word struct {
	Text      string
	Start     Position
	End       Position
	Direction Direction
	Found     bool
}

Word represents a hidden word in the puzzle

func GenerateWordSearch

func GenerateWordSearch(width, height, wordCount, minLen, maxLen int, allowedDirs []Direction) (grid, []Word)

func GenerateWordSearchSeeded added in v1.3.0

func GenerateWordSearchSeeded(width, height, wordCount, minLen, maxLen int, allowedDirs []Direction, rng *rand.Rand) (grid, []Word)

func (*Word) Contains

func (w *Word) Contains(pos Position) bool

Contains checks if the given position is part of this word

func (*Word) Positions

func (w *Word) Positions() []Position

Positions returns all positions occupied by this word

type WordSearchMode

type WordSearchMode struct {
	game.BaseMode
	Width       int
	Height      int
	WordCount   int
	MinWordLen  int
	MaxWordLen  int
	AllowedDirs []Direction
}

func NewMode

func NewMode(title, description string, width, height, wordCount, minLen, maxLen int, allowedDirs []Direction) WordSearchMode

func (WordSearchMode) Spawn

func (w WordSearchMode) Spawn() (game.Gamer, error)

func (WordSearchMode) SpawnSeeded added in v1.3.0

func (w WordSearchMode) SpawnSeeded(rng *rand.Rand) (game.Gamer, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL