lightsout

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: 12 Imported by: 0

README

Lights Out

Toggle lights in a cross pattern to turn them all off.

Lights Out gameplay

How to Play

The grid starts with some lights on and some off. Toggling a cell flips that cell and its four orthogonal neighbors (up, down, left, right). The goal is to turn every light off.

Controls

Key Action
Arrow keys / WASD / hjkl Move cursor
Mouse left-click Toggle light
Enter / Space Toggle light
Ctrl+R Reset puzzle
Ctrl+H Toggle full help
Escape Return to main menu

Modes

Mode Grid Description
Easy 3x3 Small grid
Medium 5x5 Classic size
Hard 7x7 Large grid
Extreme 9x9 Maximum size

Quick Start

puzzletea new lights-out easy
puzzletea new lights-out medium
puzzletea new lights-out extreme

Documentation

Overview

Package lightsout implements the lights out toggle puzzle game.

Index

Constants

This section is empty.

Variables

View Source
var DefaultKeyMap = KeyMap{
	CursorKeyMap: game.DefaultCursorKeyMap,

	Toggle: key.NewBinding(
		key.WithKeys("enter", "space"),
		key.WithHelp("enter/space", "Toggle"),
	),
}
View Source
var Definition = puzzle.NewDefinition(puzzle.DefinitionSpec{
	Name:         "Lights Out",
	Description:  "Turn the lights off.",
	Aliases:      []string{"lights"},
	Modes:        ModeDefinitions,
	DailyModeIDs: puzzle.SelectModeIDsByIndex(ModeDefinitions, 1, 2),
})
View Source
var HelpContent string
View Source
var ModeDefinitions = gameentry.BuildModeDefs(Modes)
View Source
var Modes = []game.Mode{
	NewMode("Easy", "3x3 grid", 3, 3),
	NewMode("Medium", "5x5 grid", 5, 5),
	NewMode("Hard", "7x7 grid", 7, 7),
	NewMode("Extreme", "9x9 grid", 9, 9),
}

Functions

func Generate

func Generate(w, h int) [][]bool

Generate creates a new w x h grid with a solvable puzzle. It starts with all lights off and applies random toggles.

func GenerateSeeded added in v1.3.0

func GenerateSeeded(w, h int, rng *rand.Rand) [][]bool

func IsSolved

func IsSolved(grid [][]bool) bool

func Toggle

func Toggle(grid [][]bool, x, y int)

Toggle switches the state of the cell at (x,y) and its immediate neighbors. It assumes grid is rectangular.

Types

type KeyMap

type KeyMap struct {
	game.CursorKeyMap
	Toggle key.Binding
}

type Mode

type Mode struct {
	game.BaseMode
	Width, Height int
}

func NewMode

func NewMode(title, desc string, w, h int) Mode

func (Mode) Spawn

func (m Mode) Spawn() (game.Gamer, error)

func (Mode) SpawnSeeded added in v1.3.0

func (m Mode) SpawnSeeded(rng *rand.Rand) (game.Gamer, error)

type Model

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

func ImportModel

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

func New

func New(w, h int) (Model, error)

func NewSeeded added in v1.3.0

func NewSeeded(w, h int, rng *rand.Rand) (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 Save

type Save struct {
	Grid        [][]bool `json:"grid"`
	InitialGrid [][]bool `json:"initial_grid,omitempty"`
	CursorX     int      `json:"cx"`
	CursorY     int      `json:"cy"`
	ModeTitle   string   `json:"mode_title"`
}

Jump to

Keyboard shortcuts

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