GitHubНачать

Справочник API собран из Go doc-комментариев в исходном коде и написан на английском языке.

package placement

import "github.com/nsgo-dev/game/pkg/placement"

Обзор

Package placement is experimental: its API and documented formats may change in a minor release. See the API stability policy. provides deterministic square-grid footprint placement.

Указатель

Типы

type Cell struct{ X, Y int }

Cell identifies a square grid coordinate.

type Failure struct {
	Cell   Cell
	Reason string
}

Failure explains why one footprint cell cannot be placed.

type Footprint struct {
	ID    string
	Cells []Cell
}

Footprint lists occupied cells relative to a placement origin.

func Rotate(f Footprint, quarterTurns int) Footprint

Rotate rotates a footprint clockwise in 90-degree increments around its origin.

type Grid[T comparable] struct {
	Width, Height int
	// contains filtered or unexported fields
}

Grid stores values occupying a bounded square grid.

func New[T comparable](width, height int) *Grid[T]

New returns an empty grid with the given dimensions.

func (g *Grid[T]) At(c Cell) (T, bool)

At returns the value occupying c.

func (g *Grid[T]) CanPlace(f Footprint, at Cell) []Failure

CanPlace reports every out-of-bounds or occupied cell for a footprint.

func (g *Grid[T]) Place(f Footprint, at Cell, value T) error

Place stores value in every cell of a footprint, or returns its first failure.

func (g *Grid[T]) Remove(f Footprint, at Cell)

Remove clears every cell occupied by a footprint.