world

package
v0.0.0-...-537c833 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ExploreBatch = 200

Variables

View Source
var DeadEndNode = &Node{}

DeadEndNode represent constant reference for termination of dead end paths in search graphs

Functions

This section is empty.

Types

type Bitmap

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

func (Bitmap) CheckBit

func (b Bitmap) CheckBit(p Pos) bool

func (Bitmap) HashBytes

func (b Bitmap) HashBytes() []byte

func (Bitmap) List

func (b Bitmap) List() []Pos

func (*Bitmap) SetBit

func (b *Bitmap) SetBit(p Pos)

type BoxMove

type BoxMove struct {
	BoxIndex  int
	Direction MoveDirection
}

type Map

type Map struct {
	Width  int
	Height int
	StartX int
	StartY int
	Tiles  [][]Tile
}

func ReadMap

func ReadMap(r io.Reader) (Map, error)

func (Map) At

func (m Map) At(x, y int) Tile

func (Map) AtPos

func (m Map) AtPos(p Pos) Tile

func (Map) InitialBoxPositions

func (m Map) InitialBoxPositions() []Pos

func (Map) IsInside

func (m Map) IsInside(p Pos) bool

func (Map) StartPos

func (m Map) StartPos() Pos

func (Map) String

func (m Map) String() string

type MetricCalculator

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

func NewMetricCalculator

func NewMetricCalculator(m Map, deadzones MoveDomain) MetricCalculator

func (MetricCalculator) Evaluate

func (mc MetricCalculator) Evaluate(s State) (int, error)

func (MetricCalculator) String

func (mc MetricCalculator) String() string

type MoveDirection

type MoveDirection int
const (
	MoveUp MoveDirection = iota
	MoveRight
	MoveDown
	MoveLeft
)

func FindDirections

func FindDirections(domain MoveDomain, from, to Pos) ([]MoveDirection, error)

func (MoveDirection) MarshalJSON

func (d MoveDirection) MarshalJSON() ([]byte, error)

func (MoveDirection) RotateCCW

func (d MoveDirection) RotateCCW() MoveDirection

func (MoveDirection) RotateCW

func (d MoveDirection) RotateCW() MoveDirection

func (MoveDirection) String

func (d MoveDirection) String() string

type MoveDomain

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

func NewMoveDomain

func NewMoveDomain() MoveDomain

func NewMoveDomainFromMap

func NewMoveDomainFromMap(m Map, boxPositions []Pos, start Pos) MoveDomain

NewMoveDomainFromMap generate move domain from Map (considering only walls), box positions and starting position TODO: refactor to create state with predefined moves

func (*MoveDomain) AddPosition

func (md *MoveDomain) AddPosition(pos Pos)

func (*MoveDomain) HasPosition

func (md *MoveDomain) HasPosition(pos Pos) bool

func (MoveDomain) HashBytes

func (md MoveDomain) HashBytes() []byte

func (*MoveDomain) ListPosition

func (md *MoveDomain) ListPosition() []Pos

func (MoveDomain) String

func (md MoveDomain) String() string

type Node

type Node struct {
	ID     int64
	Metric int
	Hash   uint64
	Fail   NodeFail
	State
	// Parent node for easy backward traverse
	Parent *Node
	// Moves represent possible moves from current state with pointer to corresponding states
	Moves map[BoxMove]*Node
}

func NewNode

func NewNode(s State) *Node

func (Node) MarshalJSON

func (n Node) MarshalJSON() ([]byte, error)

type NodeFail

type NodeFail int
const (
	NodeOK NodeFail = iota
	NodeDuplicate
	NodeInvalid
)

type Pos

type Pos struct {
	X int
	Y int
}

func SortedPositions

func SortedPositions(pos []Pos) []Pos

func (Pos) Diagonals

func (p Pos) Diagonals() []Pos

func (Pos) Mirror

func (p Pos) Mirror(center Pos) Pos

func (Pos) MoveAgainstDirection

func (p Pos) MoveAgainstDirection(d MoveDirection) Pos

func (Pos) MoveInDirection

func (p Pos) MoveInDirection(d MoveDirection) Pos

func (Pos) Neighbours

func (p Pos) Neighbours() []Pos

func (Pos) String

func (p Pos) String() string

type Solver

type Solver struct {
	Map

	Done bool
	// contains filtered or unexported fields
}

func NewSolver

func NewSolver(m Map) *Solver

func (Solver) GetDebug

func (s Solver) GetDebug() SolverDebug

func (Solver) GetPath

func (s Solver) GetPath() ([]MoveDirection, error)

func (Solver) GetTree

func (s Solver) GetTree(max int) []*Node

func (*Solver) Solve

func (s *Solver) Solve(c context.Context) error

type SolverDebug

type SolverDebug struct {
	DeadZones []Pos            `json:"dead_zones"`
	Metrics   []map[string]int `json:"metrics"`
}

type State

type State struct {
	MoveDomain
	BoxPositions []Pos
}

func (State) Hash

func (s State) Hash() uint64

type Tile

type Tile int
const (
	TileEmpty Tile = iota
	TileWall
	TilePlayerStart
	TilePlayerOnGoal
	TileBox
	TileBoxOnGoal
	TileGoal
)

Jump to

Keyboard shortcuts

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