twod

package
v0.0.0-...-d36c20b Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UP    = Vector(1i)
	LEFT  = Vector(-1)
	DOWN  = Vector(-1i)
	RIGHT = Vector(1)

	UPRIGHT   = UP + RIGHT
	UPLEFT    = UP + LEFT
	DOWNRIGHT = DOWN + RIGHT
	DOWNLEFT  = DOWN + LEFT
)

Variables

View Source
var (
	DirectionNames = map[Vector]string{
		UP:    "up",
		LEFT:  "left",
		DOWN:  "down",
		RIGHT: "right",
	}
	FourDirections = []Vector{DOWN, RIGHT, LEFT, UP}
	AllDirections  = []Vector{DOWN, RIGHT, LEFT, UP, UPRIGHT, UPLEFT, DOWNRIGHT, DOWNLEFT}
)
View Source
var (
	RenderingEnabled = false

	RenderingMap = make(map[interface{}]color.Color)
)

Functions

func SetFPS

func SetFPS(rate int)

Types

type Map

type Map map[Vector]interface{}

func NewMapFromInput

func NewMapFromInput(input string) Map

NewMapFromInput set every character from the input string into a Map object based on its coordinate. Every vector in the map is positive, which means that the bottom left of the input will be at the origin of the Map.

func (Map) Clone

func (m Map) Clone() Map

func (Map) Djikstra

func (m Map) Djikstra(from, to Vector, scoreFunc func(curDir, nextDir Vector) int) (int, Path)

func (Map) DuplicateColumn

func (m Map) DuplicateColumn(x int) Map

func (Map) DuplicateLine

func (m Map) DuplicateLine(y int) Map

func (Map) Equal

func (m Map) Equal(m2 Map) bool

func (Map) Filter

func (m Map) Filter(matches ...interface{}) Map

func (Map) FilterOut

func (m Map) FilterOut(matches ...interface{}) Map

func (Map) Find

func (m Map) Find(matches ...interface{}) []Vector

func (Map) FindBottomFirstColumn

func (m Map) FindBottomFirstColumn() Vector

FindBottomFirstColumn returns a point that is the most bottom left point of the map. This point exists in the actual map.

func (Map) FindBottomLeft

func (m Map) FindBottomLeft() Vector

FindBottomLeft returns a point that represent the bottom left corner of a squared map only composed of the match values. This point might not exist on the actual map.

func (Map) FindBottomRight

func (m Map) FindBottomRight() Vector

FindBottomRight returns a point that represent the bottom right corner of a squared map only composed of the match values. This point might not exist on the actual map.

func (Map) FindNeighbors

func (m Map) FindNeighbors(fromPos Vector) map[string]Vector

func (Map) FindPattern

func (m Map) FindPattern(pattern Map, matchValue bool) []Vector

FindPattern looks for a pattern in a map and return a list of pattern start points.

func (Map) FindTopLeft

func (m Map) FindTopLeft() Vector

FindTopLeft returns a point that represent the top left corner of a squared map only composed of the match values. This point might not exist on the actual map.

func (Map) FindTopRight

func (m Map) FindTopRight() Vector

FindTopRight returns a point that represent the top right corner of a squared map only composed of the match values. This point might not exist on the actual map.

func (Map) GetUniqueTilesCount

func (m Map) GetUniqueTilesCount(from, to Vector, existingPath Path, scoreFunc func(curDir, nextDir Vector) int) int

func (Map) Height

func (m Map) Height() int

Height returns height of the map.

func (Map) InvertY

func (m Map) InvertY() Map

func (Map) IsColumnSame

func (m Map) IsColumnSame(startPoint Vector) bool

func (Map) IsLineSame

func (m Map) IsLineSame(startPoint Vector) bool

func (Map) Merge

func (m Map) Merge(m2 Map) Map

func (Map) Print

func (m Map) Print()

func (Map) Render

func (m Map) Render()

func (Map) RotateLeft

func (m Map) RotateLeft() Map

func (Map) RotateRight

func (m Map) RotateRight() Map

func (Map) SetPositive

func (m Map) SetPositive() Map

func (Map) SortByDist

func (m Map) SortByDist(from Vector) []Vector

SortByDist will sort the sliced map by distance from the given position (lowest to max). If two points have the same distance the order will be based on radian angle (lowest to max).

func (Map) SortValuesByDist

func (m Map) SortValuesByDist(from Vector) []interface{}

func (Map) String

func (m Map) String() string

func (Map) ToSlice

func (m Map) ToSlice() []Vector

func (Map) Translate

func (m Map) Translate(move Vector) Map

func (Map) UpdatePosition

func (m Map) UpdatePosition(pos Vector, replacement interface{})

func (Map) Width

func (m Map) Width() int

Width returns width of the map.

type P

type P struct {
	Pos   Vector
	Speed Vector
	Steps int
	// contains filtered or unexported fields
}

func NewPoint

func NewPoint(position Vector, direction Vector) *P

func (*P) Clone

func (p *P) Clone() *P

func (*P) GetPositionAtDestination

func (p *P) GetPositionAtDestination(direction Vector, steps int) Vector

func (*P) IsOutOfMap

func (p *P) IsOutOfMap(m Map) bool

func (*P) IsOutOfMapLimits

func (p *P) IsOutOfMapLimits(m *Map, width, height *int) bool

func (*P) LongestPos

func (p *P) LongestPos(emptyPoints Map) (maxPos Vector, maxDist int)

func (*P) Move

func (p *P) Move(steps int)

func (*P) MoveDown

func (p *P) MoveDown(steps int)

func (*P) MoveLeft

func (p *P) MoveLeft(steps int)

func (*P) MoveRight

func (p *P) MoveRight(steps int)

func (*P) MoveUp

func (p *P) MoveUp(steps int)

func (*P) PathEstimatedCost

func (p *P) PathEstimatedCost(to astar.Pather) float64

PathEstimatedCost uses Manhattan distance to estimate orthogonal distance

func (*P) PathNeighborCost

func (p *P) PathNeighborCost(to astar.Pather) float64

PathNeighborCost returns the cost of the tube leading to Truck.

func (*P) PathNeighbors

func (p *P) PathNeighbors() []astar.Pather

func (*P) ShortestPathToPos

func (p *P) ShortestPathToPos(pos Vector, emptyPoints Map) (path []*P, distance float64, found bool)

func (*P) TurnLeft

func (p *P) TurnLeft()

func (*P) TurnRight

func (p *P) TurnRight()

type Path

type Path map[Vector]int

type Step

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

type Vector

type Vector complex128

func NewVector

func NewVector(x, y int) Vector

func (Vector) AngleFrom

func (v Vector) AngleFrom(from Vector) float64

func (Vector) C

func (v Vector) C() complex128

func (Vector) DistFrom

func (v Vector) DistFrom(from Vector) int

func (Vector) DistFromOrigin

func (v Vector) DistFromOrigin() int

func (Vector) EuclideanDistFrom

func (v Vector) EuclideanDistFrom(from Vector) float64

func (Vector) EuclideanDistFromOrigin

func (v Vector) EuclideanDistFromOrigin() float64

func (Vector) IsOutOfBounds

func (v Vector) IsOutOfBounds(W, H int) bool

func (Vector) ManhatanDistance

func (v Vector) ManhatanDistance(from Vector) int

func (Vector) Rotate

func (v Vector) Rotate(angle float64) Vector

func (Vector) RotateDegree

func (v Vector) RotateDegree(degrees int) Vector

func (Vector) ScalarMult

func (v Vector) ScalarMult(i int) Vector

func (Vector) X

func (v Vector) X() int

func (Vector) Y

func (v Vector) Y() int

type VisitedPoint

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

Jump to

Keyboard shortcuts

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