engine

package
v4.2.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2019 License: MIT Imports: 6 Imported by: 27

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DotsMaskBigHome = NewDotsMask([][]uint8{
	{1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1},
	{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1},
})
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 DotsMaskHome1 = 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 DotsMaskHome2 = NewDotsMask([][]uint8{
	{1, 1, 1, 0, 0, 1, 1, 1},
	{1, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 1, 0, 0, 1, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0},
	{1, 0, 1, 0, 0, 1, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 1},
	{1, 1, 1, 0, 0, 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 DotsMaskTunnel1 = NewDotsMask([][]uint8{
	{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
	{1, 1, 1, 1, 1, 1, 1, 1, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
})
View Source
var DotsMaskTunnel2 = NewDotsMask([][]uint8{
	{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
	{0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1},
	{1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0},
	{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
})

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 MustArea

func MustArea(width, height uint8) Area

func NewArea

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

func NewUsefulArea

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

func (Area) ContainsDot

func (a Area) ContainsDot(dot Dot) bool

func (Area) ContainsLocation

func (a Area) ContainsLocation(location Location) bool

func (Area) ContainsRect

func (a Area) ContainsRect(rect Rect) bool

func (Area) Dots

func (a Area) Dots() []Dot

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) String

func (a Area) String() string

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 HashToDot

func HashToDot(v uint16) Dot

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() uint16

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) DotCount

func (dm *DotsMask) DotCount() (count uint16)

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 ErrDirectionMarshal

type ErrDirectionMarshal struct {
	Err error
}

func (*ErrDirectionMarshal) Error

func (e *ErrDirectionMarshal) 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 ErrNavigation

type ErrNavigation struct {
	Err error
}

func (*ErrNavigation) Error

func (e *ErrNavigation) 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 HashToLocation

func HashToLocation(hashes []uint16) Location

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) Hash

func (l Location) Hash() []uint16

func (Location) Intersection

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

func (Location) Reverse

func (l Location) Reverse() Location

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

func (Rect) X

func (r Rect) X() uint8

func (Rect) Y

func (r Rect) Y() uint8

Jump to

Keyboard shortcuts

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