hitori

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 11 Imported by: 0

README

Hitori

Shade cells to eliminate duplicate numbers in every row and column.

Hitori gameplay

How to Play

The grid starts filled with numbers. Shade some cells black so that three rules are satisfied:

  1. No duplicates: No number appears more than once in any row or column among the unshaded (white) cells.
  2. No adjacent shading: No two shaded cells share an edge (diagonal is fine).
  3. White connectivity: All unshaded cells must form a single orthogonally connected region.

The puzzle is solved when all three rules hold simultaneously.

Controls

Key Action
Arrow keys / WASD / hjkl Move cursor
x Shade cell (toggle)
z Circle cell as confirmed white (toggle)
Backspace Clear cell to unmarked
Ctrl+H Toggle full help
Ctrl+E Toggle debug overlay
Ctrl+R Reset puzzle
Ctrl+N Return to main menu

Modes

Mode Grid Description
Mini 5x5 Gentle introduction
Easy 6x6 Straightforward logic
Medium 8x8 Moderate challenge
Tricky 9x9 Requires careful deduction
Hard 10x10 Advanced logic chains
Expert 12x12 Maximum challenge

Quick Start

puzzletea new hitori mini
puzzletea new hitori medium
puzzletea new hitori expert

Documentation

Overview

Package hitori implements the Hitori number puzzle game.

Index

Constants

This section is empty.

Variables

View Source
var DailyModes = []list.Item{
	Modes[1],
	Modes[2],
}

DailyModes is the subset of Modes eligible for daily puzzle rotation.

View Source
var DefaultKeyMap = KeyMap{
	CursorKeyMap: game.DefaultCursorKeyMap,
	ShadeCell: key.NewBinding(
		key.WithKeys("x"),
		key.WithHelp("x", "Shade"),
	),
	CircleCell: key.NewBinding(
		key.WithKeys("z"),
		key.WithHelp("z", "Circle"),
	),
	ClearCell: key.NewBinding(
		key.WithKeys("backspace", "delete"),
		key.WithHelp("bkspc", "Clear"),
	),
}

DefaultKeyMap provides the standard keybindings.

View Source
var HelpContent string
View Source
var Modes = []list.Item{
	NewMode("Mini", "5\u00d75 grid, gentle introduction.", 5, 0.32),
	NewMode("Easy", "6\u00d76 grid, straightforward logic.", 6, 0.32),
	NewMode("Medium", "8\u00d78 grid, moderate challenge.", 8, 0.30),
	NewMode("Tricky", "9\u00d79 grid, requires careful deduction.", 9, 0.30),
	NewMode("Hard", "10\u00d710 grid, advanced logic chains.", 10, 0.30),
	NewMode("Expert", "12\u00d712 grid, maximum challenge.", 12, 0.28),
}

Modes defines the available difficulty levels. Difficulty is controlled by grid size and the ratio of black cells. Smaller grids with fewer black cells are easier to deduce; larger grids with more black cells require deeper chains of logic.

Functions

func Generate

func Generate(size int, blackRatio float64) (grid, error)

Generate creates a Hitori puzzle of the given size. Returns the puzzle numbers grid or an error if generation fails after all attempts.

func GenerateSeeded

func GenerateSeeded(size int, blackRatio float64, rng *rand.Rand) (grid, error)

func New

func New(mode HitoriMode, numbers grid) (game.Gamer, error)

New creates a new Hitori game model.

Types

type HitoriMode

type HitoriMode struct {
	game.BaseMode
	Size       int
	BlackRatio float64
}

HitoriMode represents a specific difficulty configuration for Hitori.

func NewMode

func NewMode(title, desc string, size int, blackRatio float64) HitoriMode

NewMode creates a new Hitori game mode.

func (HitoriMode) Spawn

func (h HitoriMode) Spawn() (game.Gamer, error)

Spawn creates a new game instance for this mode.

func (HitoriMode) SpawnSeeded

func (h HitoriMode) SpawnSeeded(rng *rand.Rand) (game.Gamer, error)

type KeyMap

type KeyMap struct {
	game.CursorKeyMap
	ShadeCell  key.Binding
	CircleCell key.Binding
	ClearCell  key.Binding
}

KeyMap defines the keybindings for Hitori.

type Model

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

Model implements game.Gamer for Hitori.

func ImportModel

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

ImportModel reconstructs a Model from saved JSON data.

func (Model) GetDebugInfo

func (m Model) GetDebugInfo() string

func (Model) GetFullHelp

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

GetFullHelp implements game.Gamer.

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

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 {
	Size      int    `json:"size"`
	Numbers   string `json:"numbers"`
	Marks     string `json:"marks"`
	ModeTitle string `json:"mode_title"`
}

Save represents the serialized state of a Hitori game.

Jump to

Keyboard shortcuts

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