crossword

package module
v0.0.0-...-1e3ba93 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 11 Imported by: 0

README

crossword

The crossword package provides functions for reading crossword puzzles in the AcrossLite PUZ file format.

The cmd subdirectory contains some applications that use the crossword package:

  • playpuz is a GTK+ program for playing a crossword puzzle

  • puz2pdf is a command-line program that formats PUZ files into PDF for printing

Documentation

Overview

Package crossword provides functions to read crossword puzzles in the AcrossLite PUZ file format and render them as PDF files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PuzzleBytes

func PuzzleBytes(s string) []byte

func PuzzleString

func PuzzleString(s string) string

Types

type Checksums

type Checksums struct {
	Global    uint16
	Scrambled uint16
	Magic     uint64
}

type Clue

type Clue struct {
	// Clue numbers in increasing order.
	Numbers []int
	// Reverse map from clue number to index in Numbers.
	Indexes map[int]int
	// Clues indexed by their number.
	Clues IndexedStrings
	// Answers indexed by their number.
	Answers IndexedStrings
	// Positions[n] is the position of the square with number n.
	Positions IndexedPositions
	// Words[n] is the Word for answer number n, in left-right or top-down order.
	Words IndexedWords
	// Start[y][x] is clue number for the word that passes through square (x, y).
	// May be zero for uncrossed words in unusual puzzles.
	Start Grid
}

Per-direction clue information.

type Direction

type Direction int
const (
	Across Direction = 0
	Down   Direction = 1
)

func (Direction) String

func (dir Direction) String() string

type Grid

type Grid [][]uint8

func NewGrid

func NewGrid(w, h int) Grid

func (Grid) Contents

func (g Grid) Contents() []byte

func (Grid) String

func (g Grid) String() string

func (Grid) Write

func (g Grid) Write(w io.Writer)

type IndexedPositions

type IndexedPositions map[int]Position

type IndexedStrings

type IndexedStrings map[int]string

type IndexedWords

type IndexedWords map[int]Word

type Key

type Key []uint8

Key stores a 4-digit decimal key in big-endian order, one digit per byte.

func NewKey

func NewKey() Key

func NewKeyFromInt

func NewKeyFromInt(k int) (Key, error)

func (Key) Int

func (key Key) Int() int

func (Key) Next

func (key Key) Next() bool

Next increments key in place, and returns true if it did not overflow.

type Layout

type Layout struct {
	NumColumns int
	PointSize  float64
	Score      LayoutScore
}

type LayoutScore

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

func (LayoutScore) IsBetterThan

func (a LayoutScore) IsBetterThan(b LayoutScore) bool

func (LayoutScore) Scalar

func (a LayoutScore) Scalar() float64

Scalar calculates a single "goodness" score from the LayoutScore components.

func (LayoutScore) String

func (a LayoutScore) String() string

type Layouts

type Layouts []Layout

func (Layouts) Len

func (v Layouts) Len() int

sort.Interface for Layouts using NumColumns as sort key.

func (Layouts) Less

func (v Layouts) Less(i, j int) bool

func (Layouts) Swap

func (v Layouts) Swap(i, j int)

type Position

type Position struct {
	X int
	Y int
}

func NewPosition

func NewPosition(x, y int) Position

func (Position) String

func (pos Position) String() string

type Puzzle

type Puzzle struct {
	Header   []byte
	Checksum Checksums

	Version string

	Author    string
	Copyright string
	Title     string
	Notepad   string

	Width  int
	Height int

	NumClues  int
	AllClues  []string
	Scrambled bool

	// Clue information indexed by direction.
	Dir []Clue
	// contains filtered or unexported fields
}

func Decode

func Decode(puz []byte) (*Puzzle, error)

func Read

func Read(file string) (*Puzzle, error)

func (*Puzzle) Answer

func (p *Puzzle) Answer(x, y int) byte

func (*Puzzle) IsBlack

func (p *Puzzle) IsBlack(x, y int) bool

func (*Puzzle) IsCircled

func (p *Puzzle) IsCircled(x, y int) bool

func (*Puzzle) MakeGrid

func (p *Puzzle) MakeGrid() Grid

func (*Puzzle) NewRenderContext

func (p *Puzzle) NewRenderContext(pdf *gofpdf.Fpdf) *RenderContext

func (*Puzzle) PositionNumber

func (p *Puzzle) PositionNumber(pos Position) int

PositionNumber(pos) is the number for the square at position pos, or 0.

func (*Puzzle) Solution

func (p *Puzzle) Solution() string

func (*Puzzle) SolutionBytes

func (p *Puzzle) SolutionBytes() []byte

func (*Puzzle) SquareNumber

func (p *Puzzle) SquareNumber(x, y int) int

SquareNumber(x, y) is the number for square (x, y), or 0.

func (*Puzzle) Unlock

func (p *Puzzle) Unlock() (int, error)

func (*Puzzle) UnlockWithKey

func (p *Puzzle) UnlockWithKey(k int) error

type RenderContext

type RenderContext struct {
	Layouts    []Layout // in order of increasing NumColumns
	BestLayout int
	// contains filtered or unexported fields
}

func (*RenderContext) Render

func (r *RenderContext) Render()

func (*RenderContext) RenderAll

func (r *RenderContext) RenderAll()

type Word

type Word []Position

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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