sudoku

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

Sudoku

Classic 9x9 number placement puzzle.

Sudoku gameplay

How to Play

Fill every empty cell with a digit from 1 to 9 so that each row, each column, and each 3x3 box contains every digit exactly once. Pre-filled cells (shown in bold) cannot be changed. Conflicting cells are highlighted in red.

Controls

Key Action
Arrow keys / WASD / hjkl Move cursor
Mouse left-click Focus a cell
1-9 Fill cell with digit
Backspace Clear cell
Ctrl+R Reset puzzle
Ctrl+H Toggle full help
Escape Return to main menu

Modes

Mode Clues Description
Beginner 45 Single Candidate / Scanning
Easy 38 Naked Singles
Medium 32 Hidden Pairs / Pointing
Hard 27 Box-Line Reduction / Triples
Expert 22 X-Wing / Y-Wing
Diabolical 17 Swordfish / XY-Chains

Quick Start

puzzletea new sudoku beginner
puzzletea new sudoku medium
puzzletea new sudoku diabolical

Documentation

Overview

Package sudoku implements the classic number-placement puzzle.

Index

Constants

This section is empty.

Variables

View Source
var DefaultKeyMap = KeyMap{
	CursorKeyMap: game.DefaultCursorKeyMap,
	FillValue: key.NewBinding(
		key.WithKeys("1", "2", "3", "4", "5", "6", "7", "8", "9"),
		key.WithHelp("1-9", "Fill"),
	),
	ClearCell: key.NewBinding(
		key.WithKeys("backspace"),
		key.WithHelp("bkspc", "Clear"),
	),
}
View Source
var Definition = puzzle.NewDefinition(puzzle.DefinitionSpec{
	Name:         "Sudoku",
	Description:  "Fill the 9x9 grid following sudoku rules.",
	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("Beginner", "45–52 clues. Single Candidate / Scanning.", 45),
	NewMode("Easy", "38–44 clues. Naked Singles.", 38),
	NewMode("Medium", "32–37 clues. Hidden Pairs / Pointing.", 32),
	NewMode("Hard", "27–31 clues. Box-Line Reduction / Triples.", 27),
	NewMode("Expert", "22–26 clues. X-Wing / Y-Wing.", 22),
	NewMode("Diabolical", "17–21 clues. Swordfish / XY-Chains.", 17),
}
View Source
var PDFPrintAdapter = printAdapter{}

Functions

func GenerateProvidedCells

func GenerateProvidedCells(m SudokuMode) []cell

GenerateProvidedCells generates a random sudoku puzzle with the number of provided cells determined by the mode's ProvidedCount.

func GenerateProvidedCellsSeeded added in v1.3.0

func GenerateProvidedCellsSeeded(m SudokuMode, rng *rand.Rand) []cell

func New

func New(mode SudokuMode, provided []cell) (game.Gamer, error)

Types

type KeyMap

type KeyMap struct {
	game.CursorKeyMap
	FillValue key.Binding
	ClearCell 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) IsProvidedCell

func (m Model) IsProvidedCell() bool

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      string       `json:"grid"`
	Provided  []exportCell `json:"provided"`
	ModeTitle string       `json:"mode_title,omitempty"`
}

type SudokuMode

type SudokuMode struct {
	game.BaseMode
	ProvidedCount int
}

func NewMode

func NewMode(title, description string, providedCount int) SudokuMode

func (SudokuMode) Spawn

func (s SudokuMode) Spawn() (game.Gamer, error)

func (SudokuMode) SpawnSeeded added in v1.3.0

func (s SudokuMode) 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