takuzu

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

Takuzu

Fill the grid with two symbols following three simple rules.

Takuzu gameplay

How to Play

Fill every empty cell with either a filled circle (●) or an open circle (○) so that the grid satisfies three rules:

  1. No triple: No three consecutive identical symbols in any row or column.
  2. Equal count: Each row and column must contain exactly N/2 of each symbol.
  3. Unique lines: No two rows may be identical; no two columns may be identical.

Pre-filled cells (shown in bold) cannot be changed. The puzzle is solved when every cell is filled and all three rules are satisfied.

Controls

Key Action
Arrow keys / WASD / hjkl Move cursor
Mouse left-click Move to a cell, or cycle the current editable cell
z / 0 Place ●
x / 1 Place ○
Backspace Clear cell
Ctrl+R Reset puzzle
Ctrl+H Toggle full help
Escape Return to main menu

Modes

Mode Grid Clues Techniques Required
Beginner 6x6 ~50% Doubles and sandwich patterns
Easy 6x6 ~40% Counting required
Medium 8x8 ~40% Moderate deduction
Tricky 10x10 ~38% Uniqueness rule needed
Hard 10x10 ~32% Long deduction chains
Very Hard 12x12 ~30% Deep logic required
Extreme 14x14 ~28% Maximum challenge

Quick Start

puzzletea new takuzu beginner
puzzletea new takuzu medium
puzzletea new takuzu extreme
puzzletea new binairo hard       # alias

Documentation

Overview

Package takuzu implements the binary (Binairo) puzzle game.

Index

Constants

View Source
const (
	EmptyCell = emptyCell
	ZeroCell  = zeroCell
	OneCell   = oneCell
)

Variables

View Source
var DefaultKeyMap = KeyMap{
	CursorKeyMap: game.DefaultCursorKeyMap,
	PlaceZero: key.NewBinding(
		key.WithKeys("z", "0"),
		key.WithHelp("z/0", "Place ●"),
	),
	PlaceOne: key.NewBinding(
		key.WithKeys("x", "1"),
		key.WithHelp("x/1", "Place ○"),
	),
	Clear: key.NewBinding(
		key.WithKeys("backspace", "delete"),
		key.WithHelp("bkspc", "Clear"),
	),
}
View Source
var Definition = puzzle.NewDefinition(puzzle.DefinitionSpec{
	Name:         "Takuzu",
	Description:  "Fill the grid with ● and ○. No 3 in a row.",
	Aliases:      []string{"binairo", "binary"},
	Modes:        ModeDefinitions,
	DailyModeIDs: puzzle.SelectModeIDsByIndex(ModeDefinitions, 2, 3),
})
View Source
var HelpContent string
View Source
var ModeDefinitions = gameentry.BuildModeDefs(Modes)
View Source
var Modes = []game.Mode{
	NewMode("Beginner", "6×6 grid, ~50% clues. Doubles and sandwich patterns.", 6, 0.50),
	NewMode("Easy", "6×6 grid, ~40% clues. Counting required.", 6, 0.40),
	NewMode("Medium", "8×8 grid, ~40% clues. Larger grid, moderate deduction.", 8, 0.40),
	NewMode("Tricky", "10×10 grid, ~38% clues. Uniqueness rule needed.", 10, 0.38),
	NewMode("Hard", "10×10 grid, ~32% clues. Long deduction chains.", 10, 0.32),
	NewMode("Very Hard", "12×12 grid, ~30% clues. Deep logic required.", 12, 0.30),
	NewMode("Extreme", "14×14 grid, ~28% clues. Maximum challenge.", 14, 0.28),
}
View Source
var PDFPrintAdapter = printAdapter{}

Functions

func CanPlaceInGrid added in v1.8.0

func CanPlaceInGrid(g [][]rune, size, x, y int, val rune) bool

func CheckConstraintsGrid added in v1.8.0

func CheckConstraintsGrid(g [][]rune, size int) bool

func CloneGrid added in v1.8.0

func CloneGrid(g [][]rune) [][]rune

func CountSolutionsGrid added in v1.8.0

func CountSolutionsGrid(g [][]rune, size, limit int) int

func CreateEmptyGrid added in v1.8.0

func CreateEmptyGrid(size int) [][]rune

func GenerateCompleteGrid added in v1.8.0

func GenerateCompleteGrid(size int) [][]rune

func GenerateCompleteGridSeeded added in v1.8.0

func GenerateCompleteGridSeeded(size int, rng *rand.Rand) [][]rune

func GeneratePuzzleFromComplete added in v1.8.0

func GeneratePuzzleFromComplete(complete [][]rune, size int, prefilled float64) ([][]rune, [][]bool)

func GeneratePuzzleFromCompleteSeeded added in v1.8.0

func GeneratePuzzleFromCompleteSeeded(complete [][]rune, size int, prefilled float64, rng *rand.Rand) ([][]rune, [][]bool)

func HasUniqueLinesGrid added in v1.8.0

func HasUniqueLinesGrid(g [][]rune, size int) bool

func New

func New(mode TakuzuMode, puzzle grid, provided [][]bool) (game.Gamer, error)

New creates a new Takuzu game model.

func RenderTakuzuPDFBody added in v1.8.0

func RenderTakuzuPDFBody(pdf *fpdf.Fpdf, data *pdfexport.TakuzuData)

func RenderTakuzuPDFBodyWithRules added in v1.8.0

func RenderTakuzuPDFBodyWithRules(pdf *fpdf.Fpdf, data *pdfexport.TakuzuData, rules []string)

Types

type KeyMap

type KeyMap struct {
	game.CursorKeyMap
	PlaceZero key.Binding
	PlaceOne  key.Binding
	Clear     key.Binding
}

type Model

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

Model implements game.Gamer for Takuzu.

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

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 {
	Size      int    `json:"size"`
	State     string `json:"state"`
	Provided  string `json:"provided"`
	ModeTitle string `json:"mode_title"`
}

Save represents the serialized state of a Takuzu game.

type TakuzuMode

type TakuzuMode struct {
	game.BaseMode
	Size      int
	Prefilled float64
}

func NewMode

func NewMode(title, desc string, size int, prefilled float64) TakuzuMode

func (TakuzuMode) Spawn

func (t TakuzuMode) Spawn() (game.Gamer, error)

func (TakuzuMode) SpawnSeeded added in v1.3.0

func (t TakuzuMode) 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