Documentation
¶
Overview ¶
Package shikaku implements the Shikaku rectangle-partition puzzle game.
Index ¶
- Variables
- func New(mode ShikakuMode, puzzle Puzzle) game.Gamer
- type Clue
- type KeyMap
- type Model
- func (m Model) GetDebugInfo() string
- func (m Model) GetFullHelp() [][]key.Binding
- func (m Model) GetSave() ([]byte, error)
- func (m Model) Init() tea.Cmd
- func (m Model) IsSolved() bool
- func (m Model) Reset() game.Gamer
- func (m Model) SetTitle(t string) game.Gamer
- func (m Model) Update(msg tea.Msg) (game.Gamer, tea.Cmd)
- func (m Model) View() string
- type Puzzle
- func (p *Puzzle) CandidateRectanglesForClue(clueID int) []Rectangle
- func (p *Puzzle) CellOwner(x, y int) int
- func (p *Puzzle) CluesInRect(r Rectangle) []*Clue
- func (p *Puzzle) FindClueAt(x, y int) *Clue
- func (p *Puzzle) FindClueByID(id int) *Clue
- func (p *Puzzle) FindRectangleForClue(clueID int) *Rectangle
- func (p *Puzzle) IsSolved() bool
- func (p *Puzzle) Overlaps(rect Rectangle, excludeClueID int) bool
- func (p *Puzzle) RemoveRectangle(clueID int)
- func (p *Puzzle) SetRectangle(rect Rectangle)
- func (p *Puzzle) ValidRectangleForClue(rect Rectangle, clueID int) bool
- type Rectangle
- type Save
- type ShikakuMode
Constants ¶
This section is empty.
Variables ¶
var DefaultKeyMap = KeyMap{ CursorKeyMap: game.DefaultCursorKeyMap, ShrinkUp: key.NewBinding( key.WithKeys("shift+up", "K", "W"), key.WithHelp("shift+↑", "Shrink up"), ), ShrinkDown: key.NewBinding( key.WithKeys("shift+down", "J", "S"), key.WithHelp("shift+↓", "Shrink down"), ), ShrinkLeft: key.NewBinding( key.WithKeys("shift+left", "H", "A"), key.WithHelp("shift+←", "Shrink left"), ), ShrinkRight: key.NewBinding( key.WithKeys("shift+right", "L", "D"), key.WithHelp("shift+→", "Shrink right"), ), Select: key.NewBinding( key.WithKeys("enter", "space"), key.WithHelp("enter/space", "Select/Confirm"), ), Delete: key.NewBinding( key.WithKeys("backspace"), key.WithHelp("bkspc", "Cancel/Delete"), ), }
var Definition = puzzle.NewDefinition(puzzle.DefinitionSpec{ Name: "Shikaku", Description: "Divide the grid into rectangles with set sizes.", Aliases: []string{"rectangles"}, Modes: ModeDefinitions, DailyModeIDs: puzzle.SelectModeIDsByIndex(ModeDefinitions, 1, 2), })
var Entry = gameentry.NewEntry(gameentry.EntrySpec{ Definition: Definition, Help: HelpContent, Import: game.AdaptImport(ImportModel), Modes: Modes, Print: PDFPrintAdapter, })
var HelpContent string
var ModeDefinitions = gameentry.BuildModeDefs(Modes)
var Modes = []game.Mode{ NewMode("Mini 5x5", "5x5 grid, gentle introduction.", 5, 5, 5), NewMode("Easy 7x7", "7x7 grid, straightforward puzzles.", 7, 7, 8), NewMode("Medium 8x8", "8x8 grid, moderate challenge.", 8, 8, 12), NewMode("Hard 10x10", "10x10 grid, requires careful planning.", 10, 10, 15), NewMode("Expert 12x12", "12x12 grid, maximum challenge.", 12, 12, 20), }
var PDFPrintAdapter = printAdapter{}
Functions ¶
Types ¶
type Clue ¶
type Clue struct {
ID int `json:"id"`
X int `json:"x"`
Y int `json:"y"`
Value int `json:"value"` // required rectangle area
}
Clue represents a numbered cell in the grid.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model implements game.Gamer for Shikaku.
func ImportModel ¶
ImportModel reconstructs a Model from saved JSON data.
func (Model) GetDebugInfo ¶
func (Model) GetFullHelp ¶
type Puzzle ¶
type Puzzle struct {
Width, Height int
Clues []Clue
Rectangles []Rectangle // player-placed
// contains filtered or unexported fields
}
Puzzle holds the full state of a Shikaku game.
func GeneratePuzzle ¶
GeneratePuzzle creates a Shikaku puzzle with random RNG.
func GeneratePuzzleSeeded ¶
GeneratePuzzleSeeded creates a Shikaku puzzle with a deterministic RNG.
func (*Puzzle) CandidateRectanglesForClue ¶ added in v1.7.0
CandidateRectanglesForClue returns every legal rectangle for the clue.
func (*Puzzle) CluesInRect ¶
CluesInRect returns all clues contained within the given rectangle bounds.
func (*Puzzle) FindClueAt ¶
FindClueAt returns the clue at position (x, y), or nil.
func (*Puzzle) FindClueByID ¶
FindClueByID returns the clue with the given ID, or nil.
func (*Puzzle) FindRectangleForClue ¶
FindRectangleForClue returns the rectangle placed for the given clue ID, or nil.
func (*Puzzle) IsSolved ¶
IsSolved reports whether the puzzle is complete: every cell is covered exactly once and each rectangle contains exactly one clue whose value equals the rectangle's area.
func (*Puzzle) Overlaps ¶
Overlaps reports whether the given rectangle overlaps any existing rectangle, optionally excluding the rectangle belonging to excludeClueID.
func (*Puzzle) RemoveRectangle ¶
RemoveRectangle removes the rectangle for the given clue ID.
func (*Puzzle) SetRectangle ¶
SetRectangle places or replaces the rectangle for a clue.
type Rectangle ¶
type Rectangle struct {
ClueID int `json:"clue_id"`
X int `json:"x"` // top-left
Y int `json:"y"`
W int `json:"w"` // dimensions
H int `json:"h"`
}
Rectangle represents a player-placed rectangle covering grid cells.
type Save ¶
type Save struct {
Width int `json:"width"`
Height int `json:"height"`
Clues []Clue `json:"clues"`
Rectangles []Rectangle `json:"rectangles"`
ModeTitle string `json:"mode_title"`
}
Save represents the serialized state of a Shikaku game.
type ShikakuMode ¶
func NewMode ¶
func NewMode(title, description string, width, height, maxRectSize int) ShikakuMode
