engine

package
v3.1.0-rc+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2018 License: MIT Imports: 6 Imported by: 27

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DotsMaskCross = NewDotsMask([][]uint8{
	{0, 0, 0, 1, 0, 0, 0},
	{0, 0, 0, 1, 0, 0, 0},
	{0, 0, 0, 1, 0, 0, 0},
	{1, 1, 1, 1, 1, 1, 1},
	{0, 0, 0, 1, 0, 0, 0},
	{0, 0, 0, 1, 0, 0, 0},
	{0, 0, 0, 1, 0, 0, 0},
})
View Source
var DotsMaskCrossSmall = NewDotsMask([][]uint8{
	{0, 1, 0},
	{1, 1, 1},
	{0, 1, 0},
})
View Source
var DotsMaskDiagonal = NewDotsMask([][]uint8{
	{0, 0, 0, 0, 0, 0, 1},
	{0, 0, 0, 0, 0, 1, 0},
	{0, 0, 0, 0, 1, 0, 0},
	{0, 0, 0, 1, 0, 0, 0},
	{0, 0, 1, 0, 0, 0, 0},
	{0, 1, 0, 0, 0, 0, 0},
	{1, 0, 0, 0, 0, 0, 0},
})
View Source
var DotsMaskDiagonalSmall = NewDotsMask([][]uint8{
	{1, 0, 1},
	{0, 1, 0},
	{1, 0, 1},
})
View Source
var DotsMaskHome = NewDotsMask([][]uint8{
	{1, 1, 0, 1, 1},
	{1, 0, 0, 0, 1},
	{1, 0, 0, 0, 1},
	{1, 0, 0, 0, 1},
	{1, 0, 0, 0, 1},
	{1, 1, 1, 1, 1},
})
View Source
var DotsMaskLabyrinth = NewDotsMask([][]uint8{
	{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
	{1, 0, 0, 0, 1, 0, 0, 0, 0, 1},
	{1, 0, 1, 0, 0, 0, 1, 1, 0, 1},
	{1, 0, 1, 1, 1, 0, 1, 0, 0, 1},
	{0, 0, 1, 0, 1, 0, 1, 1, 1, 1},
	{0, 0, 1, 0, 0, 0, 0, 0, 1, 0},
	{1, 0, 1, 0, 1, 0, 1, 0, 0, 0},
	{1, 0, 1, 0, 1, 0, 1, 1, 0, 1},
	{1, 0, 0, 0, 1, 0, 0, 0, 0, 1},
	{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
})
View Source
var DotsMaskSquare2x2 = NewDotsMask([][]uint8{
	{1, 1},
	{1, 1},
})
View Source
var DotsMaskTank = NewDotsMask([][]uint8{
	{0, 1, 0},
	{1, 1, 1},
	{1, 0, 1},
})
View Source
var ErrRetriesLimit = errors.New("retries limit was reached")
View Source
var FindRetriesNumber = 32

Functions

func ValidDirection

func ValidDirection(dir Direction) bool

ValidDirection returns true if passed direction is valid

Types

type Area

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

func NewArea

func NewArea(width, height uint8) (Area, error)

func NewUsefulArea

func NewUsefulArea(width, height uint8) (Area, error)

func (Area) Contains

func (a Area) Contains(dot Dot) bool

func (Area) Height

func (a Area) Height() uint8

func (Area) MarshalJSON

func (a Area) MarshalJSON() ([]byte, error)

Implementing json.Marshaler interface

func (Area) Navigate

func (a Area) Navigate(dot Dot, dir Direction, dis uint8) (Dot, error)

Navigate calculates and returns dot placed on distance dis dots from passed dot in direction dir

func (Area) NewRandomDot

func (a Area) NewRandomDot(x, y uint8) Dot

NewRandomDot generates random dot on area with starting coordinates X and Y

func (Area) NewRandomRect

func (a Area) NewRandomRect(rw, rh, sx, sy uint8) (*Rect, error)

func (Area) Size

func (a Area) Size() uint16

Size returns area size

func (Area) Width

func (a Area) Width() uint8

type Direction

type Direction uint8

Direction indicates movement direction

const (
	DirectionNorth Direction = iota
	DirectionEast
	DirectionSouth
	DirectionWest
)

func CalculateDirection

func CalculateDirection(from, to Dot) Direction

CalculateDirection calculates direction by two passed dots

func RandomDirection

func RandomDirection() Direction

RandomDirection returns random direction

func (Direction) MarshalJSON

func (dir Direction) MarshalJSON() ([]byte, error)

Implementing json.Marshaler interface

func (Direction) Reverse

func (dir Direction) Reverse() (Direction, error)

Reverse reverses direction

func (Direction) String

func (dir Direction) String() string

type Dot

type Dot struct {
	X uint8
	Y uint8
}

func (Dot) DistanceTo

func (from Dot) DistanceTo(to Dot) (res uint16)

DistanceTo calculates distance between two dots

func (Dot) Equals

func (d1 Dot) Equals(d2 Dot) bool

Equals compares two dots

func (Dot) Hash

func (d Dot) Hash() string

func (Dot) MarshalJSON

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

Implementing json.Marshaler interface

func (Dot) String

func (d Dot) String() string

type DotsMask

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

func LocationToDotsMask

func LocationToDotsMask(location Location) *DotsMask

func NewDotsMask

func NewDotsMask(mask [][]uint8) *DotsMask

func NewZeroDotsMask

func NewZeroDotsMask(width, height uint8) *DotsMask

func (*DotsMask) Copy

func (dm *DotsMask) Copy() *DotsMask

func (*DotsMask) Empty

func (dm *DotsMask) Empty() bool

func (*DotsMask) Height

func (dm *DotsMask) Height() uint8

func (*DotsMask) Location

func (dm *DotsMask) Location(x, y uint8) Location

func (*DotsMask) TurnLeft

func (dm *DotsMask) TurnLeft() *DotsMask

func (*DotsMask) TurnOver

func (dm *DotsMask) TurnOver() *DotsMask

func (*DotsMask) TurnRandom

func (dm *DotsMask) TurnRandom() *DotsMask

func (*DotsMask) TurnRight

func (dm *DotsMask) TurnRight() *DotsMask

func (*DotsMask) Width

func (dm *DotsMask) Width() uint8

type ErrAreaNotContainsDot

type ErrAreaNotContainsDot struct {
	Dot Dot
}

func (*ErrAreaNotContainsDot) Error

func (e *ErrAreaNotContainsDot) Error() string

type ErrDelete

type ErrDelete struct {
	Err error
}

func (*ErrDelete) Error

func (e *ErrDelete) Error() string

type ErrDirectionMarshal

type ErrDirectionMarshal struct {
	Err error
}

func (*ErrDirectionMarshal) Error

func (e *ErrDirectionMarshal) Error() string

type ErrDotsOccupied

type ErrDotsOccupied struct {
	Dots []Dot // List of occupied dots
}

func (*ErrDotsOccupied) Error

func (e *ErrDotsOccupied) Error() string

type ErrInvalidAreaSize

type ErrInvalidAreaSize struct {
	Width  uint8
	Height uint8
}

func (*ErrInvalidAreaSize) Error

func (e *ErrInvalidAreaSize) Error() string

type ErrInvalidDirection

type ErrInvalidDirection struct {
	Direction Direction
}

func (*ErrInvalidDirection) Error

func (e *ErrInvalidDirection) Error() string

type ErrLocate

type ErrLocate struct {
	Err error
}

func (*ErrLocate) Error

func (e *ErrLocate) Error() string

type ErrLocated

type ErrLocated struct {
	Location Location
}

func (*ErrLocated) Error

func (e *ErrLocated) Error() string

type ErrNavigation

type ErrNavigation struct {
	Err error
}

func (*ErrNavigation) Error

func (e *ErrNavigation) Error() string

type ErrNotLocated

type ErrNotLocated struct {
	Location Location
}

func (*ErrNotLocated) Error

func (e *ErrNotLocated) Error() string

type ErrRelocate

type ErrRelocate struct {
	Err error
}

func (*ErrRelocate) Error

func (e *ErrRelocate) Error() string

type ErrRelocateAvailableDots

type ErrRelocateAvailableDots struct {
	Err error
}

func (*ErrRelocateAvailableDots) Error

func (e *ErrRelocateAvailableDots) Error() string

type ErrReverseDirection

type ErrReverseDirection struct {
	Err error
}

func (ErrReverseDirection) Error

func (e ErrReverseDirection) Error() string

type Location

type Location []Dot

Location is set of dots

func (Location) Add

func (l Location) Add(dot Dot) Location

func (Location) Contains

func (l Location) Contains(dot Dot) bool

contains returns true if object contains passed dot

func (Location) Copy

func (l Location) Copy() Location

func (Location) Delete

func (l Location) Delete(dot Dot) Location

Delete deletes dot from object

func (Location) Difference

func (l1 Location) Difference(l2 Location) Location

func (Location) Dot

func (l Location) Dot(i uint16) Dot

func (Location) DotCount

func (l Location) DotCount() uint16

func (Location) Empty

func (l Location) Empty() bool

func (Location) Equals

func (l1 Location) Equals(l2 Location) bool

func (Location) EqualsStrict

func (l1 Location) EqualsStrict(l2 Location) bool

func (Location) Intersection

func (l1 Location) Intersection(l2 Location) (intersection Location)

func (Location) Reverse

func (l Location) Reverse() Location

TODO: Remove this method (?) Reverse reverses dot sequence in object

type Rect

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

func NewRect

func NewRect(x, y, w, h uint8) Rect

NewRect creates rect

func (Rect) ContainsDot

func (r Rect) ContainsDot(d Dot) bool

func (Rect) ContainsRect

func (r1 Rect) ContainsRect(r2 Rect) bool

func (Rect) Dot

func (r Rect) Dot(i uint16) Dot

func (Rect) DotCount

func (r Rect) DotCount() uint16

func (Rect) Dots

func (r Rect) Dots() []Dot

func (Rect) Equals

func (r1 Rect) Equals(r2 Rect) bool

func (Rect) Height

func (r Rect) Height() uint8

func (Rect) Location

func (r Rect) Location() Location

func (Rect) MarshalJSON

func (r Rect) MarshalJSON() ([]byte, error)

Implementing json.Marshaler interface

func (Rect) Width

func (r Rect) Width() uint8

type Scene

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

Scene contains locations

func NewScene

func NewScene(width, height uint8) (*Scene, error)

NewScene returns new empty scene

func (*Scene) Delete

func (s *Scene) Delete(location Location) *ErrDelete

Delete deletes passed location from scene and returns error if there is a problem

func (*Scene) DotOccupied

func (s *Scene) DotOccupied(dot Dot) bool

func (*Scene) GetLocationByDot

func (s *Scene) GetLocationByDot(dot Dot) Location

func (*Scene) Height

func (s *Scene) Height() uint8

func (*Scene) Locate

func (s *Scene) Locate(location Location) *ErrLocate

Locate tries to create location to scene

func (*Scene) LocateAvailableDots

func (s *Scene) LocateAvailableDots(location Location) Location

func (*Scene) LocateRandomByDotsMask

func (s *Scene) LocateRandomByDotsMask(dm *DotsMask) (Location, error)

func (*Scene) LocateRandomDot

func (s *Scene) LocateRandomDot() (Location, error)

func (*Scene) LocateRandomRect

func (s *Scene) LocateRandomRect(rw, rh uint8) (Location, error)

func (*Scene) LocateRandomRectMargin

func (s *Scene) LocateRandomRectMargin(rw, rh, margin uint8) (Location, error)

func (*Scene) Located

func (s *Scene) Located(location Location) bool

func (*Scene) Navigate

func (s *Scene) Navigate(dot Dot, dir Direction, dis uint8) (Dot, error)

func (*Scene) Relocate

func (s *Scene) Relocate(old, new Location) *ErrRelocate

func (*Scene) RelocateAvailableDots

func (s *Scene) RelocateAvailableDots(old, new Location) (Location, *ErrRelocateAvailableDots)

func (*Scene) Size

func (s *Scene) Size() uint16

func (*Scene) Width

func (s *Scene) Width() uint8

Jump to

Keyboard shortcuts

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