crosswd

package module
v0.0.0-...-9ebfc8e Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2017 License: MIT Imports: 8 Imported by: 0

README

crosswd

crosswd is a terminal application for solving crossword puzzles in the .puz file format.

Documentation

Overview

Package crosswd provides a base for implementing crossword applications using data in the .puz format.

Index

Constants

View Source
const (
	Magic      = "ACROSS&DOWN\x00"
	CksumMagic = "ICHEATED"
	Blank      = '.'
	Empty      = '-'
)

.puz constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Coord

type Coord struct{ X, Y int }

Coord represents a 2D coordinate.

type Direction

type Direction int

Direction is a relative direction.

const (
	NoDir Direction = iota
	Up
	Down
	Left
	Right
)

Direction enumeration

func (Direction) Delta

func (d Direction) Delta() Coord

Delta returns a unit vector in the direction d.

func (Direction) Opposite

func (d Direction) Opposite() Direction

Opposite returns the opposite direction of d.

type Grid

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

Grid represents a 2D array stored contiguously.

func NewGrid

func NewGrid(width, height int) *Grid

NewGrid returns a new Grid of size width x height.

func (*Grid) At

func (g *Grid) At(p Coord) (byte, bool)

At returns the value at p if valid and whether p is valid.

func (*Grid) Set

func (g *Grid) Set(p Coord, c byte) bool

Set stores c at point p if valid and returns whether g was updated

func (*Grid) Size

func (g *Grid) Size() Coord

Size returns the grid dimensions.

func (*Grid) Valid

func (g *Grid) Valid(p Coord) bool

Valid returns whether a point is within the grid range.

type Header struct {
	Cksum       uint16
	Magic       [len(Magic)]byte
	HeaderCksum uint16
	MagicCksum  [8]byte
	Version     [4]byte
	Unused      [2]byte
	Unknown     [2]byte
	Reserved    [12]byte
	Width       uint8
	Height      uint8
	NumClues    uint16
	BitMask1    [2]byte // normally set to 0x0001
	BitMask2    [2]byte // 0x0004 = scrambled
}

Header holds .puz file header data

type Puzzle

type Puzzle struct {
	Header Header
	*Grid
	Solution  *Grid
	Title     string
	Author    string
	Copyright string
	Clues     []string
	Notes     string
	Extra     []byte
	// contains filtered or unexported fields
}

Puzzle holds the state of a crossword puzzle

func New

func New() *Puzzle

New creates a Puzzle instance

func (*Puzzle) Cksum

func (p *Puzzle) Cksum() uint16

Cksum calculates full checksum

func (*Puzzle) Clue

func (p *Puzzle) Clue(pos Coord, dir Direction) string

Clue returns the clue for the word that contains pos in direction dir, or an empty string if invalid.

func (*Puzzle) HeaderCksum

func (p *Puzzle) HeaderCksum() uint16

HeaderCksum calculates base checksum

func (*Puzzle) MagicCksum

func (p *Puzzle) MagicCksum() [8]byte

MagicCksum calculates magic checksum

func (*Puzzle) NextCell

func (p *Puzzle) NextCell(pos Coord, dir Direction, doSkip bool) Coord

NextCell returns the location one square from pos in dir direction. If doSkip is true, skip blank squares and wrap around the grid, otherwise, pos is returned unmodified.

func (*Puzzle) NextWord

func (p *Puzzle) NextWord(pos Coord, dir Direction) Coord

NextWord returns the position of the first cell of the word after the one that includes pos in direction dir, wrapping if necessary.

func (*Puzzle) Read

func (p *Puzzle) Read(r io.Reader) error

Read reads crossword data in .puz format

func (*Puzzle) Setup

func (p *Puzzle) Setup()

Setup initializes the puzzle.

func (*Puzzle) Solve

func (p *Puzzle) Solve()

Solve fills the working grid with the solution

func (*Puzzle) TextCksum

func (p *Puzzle) TextCksum(cksum uint16) uint16

TextCksum calculates checksum of text fields

func (*Puzzle) Verify

func (p *Puzzle) Verify() bool

Verify returns whether the working grid matches the solition.

func (*Puzzle) WordExtent

func (p *Puzzle) WordExtent(pos Coord, dir Direction) Coord

WordExtent returns the position of the last cell of the word that includes pos in direction dir.

func (*Puzzle) WordExtents

func (p *Puzzle) WordExtents(pos Coord, dir Direction) (Coord, Coord)

WordExtents returns the positions of the first and last cells of the word that includes pos along direction dir.

func (*Puzzle) WordID

func (p *Puzzle) WordID(pos Coord, dir Direction) int

WordID returns the ID number of the word that includes pos along direction dir.

func (*Puzzle) WordStart

func (p *Puzzle) WordStart(id int) (Coord, bool)

WordStart returns the position of the cell with ID id if valid and whether id is valid.

func (*Puzzle) Write

func (p *Puzzle) Write(w io.Writer) error

Write writes crossword data in .puz format

type Warning

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

Warning is a custom error type for warnings

func (Warning) Error

func (e Warning) Error() string

Error implements the error interface

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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