grid

package
v0.0.0-...-634b395 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package grid defines basic types and utility functions on those types

Index

Constants

View Source
const (
	// Grids larger than 14x14 are known to have no solutions
	MaxGridSize = 14
	// The largest squared distance between points on a maximum sized grid
	MaxSeparation = (MaxGridSize - 1) * (MaxGridSize - 1) * 2
)

Variables

This section is empty.

Functions

func CheckValidSolution

func CheckValidSolution(g Grid, p Placements) error

Checks that a proposed solution to the problem is valid

func IsInBounds

func IsInBounds(g Grid, p Point) bool

IsInBounds returns whether a Point is contained within a given Grid

func LessThan

func LessThan(p1, p2 Point) bool

func Separation

func Separation(p1, p2 Point) uint16

Separation is the squared distance between 2 grid points

Types

type Grid

type Grid struct {
	Size uint8
}

Grid represents an NxN square grid

func (Grid) Iter

func (g Grid) Iter() PointIterator

type Placements

type Placements []Point

Placements represents a set of stones placed on the grid

func (Placements) Sort

func (p Placements) Sort()

Sort sorts the Points in place.

type Point

type Point struct {
	Row uint8
	Col uint8
}

Point is the coordinate of a stone on a grid

func AdvanceStone

func AdvanceStone(g Grid, p Point) Point

AdvanceStone returns the next point in an ordered left to right, top to bottom traversal of the grid. The returned point is *not* guaranteed to be on the grid.

func (Point) String

func (p Point) String() string

type PointIterator

type PointIterator interface {
	// Next returns the next Point and whether or not it was valid
	Next() (Point, bool)
}

PointIterator allows iteration over a collection of points

Jump to

Keyboard shortcuts

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