mino

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2020 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GarbageDelay  = 1500 * time.Millisecond // 1.5 seconds
	ComboBaseTime = 2.4                     // Seconds
)
View Source
const (
	Monomino = "(0,0)"

	Domino = "(0,0),(1,0)"

	TrominoI = "(0,0),(1,0),(2,0)"
	TrominoL = "(0,0),(1,0),(0,1)"

	TetrominoI = "(0,0),(1,0),(2,0),(3,0)"
	TetrominoO = "(0,0),(1,0),(0,1),(1,1)"
	TetrominoT = "(0,0),(1,0),(2,0),(1,1)"
	TetrominoS = "(0,0),(1,0),(1,1),(2,1)"
	TetrominoZ = "(1,0),(2,0),(0,1),(1,1)"
	TetrominoJ = "(0,0),(1,0),(2,0),(0,1)"
	TetrominoL = "(0,0),(1,0),(2,0),(2,1)"

	PentominoF = "(0,0),(1,0),(1,1),(2,1),(1,2)"
	PentominoE = "(1,0),(2,0),(0,1),(1,1),(1,2)"
	PentominoJ = "(0,0),(1,0),(2,0),(3,0),(0,1)"
	PentominoL = "(0,0),(1,0),(2,0),(3,0),(3,1)"
	PentominoP = "(0,0),(1,0),(2,0),(0,1),(1,1)"
	PentominoZ = "(1,0),(2,0),(1,1),(0,2),(1,2)"
	PentominoI = "(0,0),(1,0),(2,0),(3,0),(4,0)"
	PentominoX = "(1,0),(0,1),(1,1),(2,1),(1,2)"
	PentominoV = "(0,0),(1,0),(2,0),(0,1),(0,2)"
	PentominoB = "(0,0),(1,0),(2,0),(1,1),(2,1)"
	PentominoN = "(1,0),(2,0),(3,0),(0,1),(1,1)"
	PentominoG = "(0,0),(1,0),(2,0),(2,1),(3,1)"
	PentominoS = "(0,0),(1,0),(1,1),(1,2),(2,2)"
	PentominoT = "(0,0),(1,0),(2,0),(1,1),(1,2)"
	PentominoU = "(0,0),(1,0),(2,0),(0,1),(2,1)"
	PentominoW = "(1,0),(2,0),(0,1),(1,1),(0,2)"
	PentominoY = "(0,0),(1,0),(2,0),(3,0),(2,1)"
	PentominoR = "(0,0),(1,0),(2,0),(3,0),(1,1)"
)
View Source
const (
	Rotation0 = 0
	RotationR = 1
	Rotation2 = 2
	RotationL = 3

	RotationStates = 4
)

Variables

View Source
var AllOffsets = []Point{{0, 0}, {-1, 0}, {1, 0}, {0, -1}, {-1, -1}, {1, -1}, {-2, 0}, {2, 0}}

Rotation offsets

View Source
var AllRotationPivotsCCW = [][]Point{
	PieceUnknown: {{0, 0}, {0, 0}, {0, 0}, {0, 0}},
	PieceI:       {{2, 1}, {-1, 00}, {2, 2}, {1, 3}},
	PieceO:       {{0, 1}, {0, 1}, {0, 1}, {0, 1}},
	PieceJ:       {{1, 1}, {0, 0}, {1, 2}, {1, 2}},
	PieceL:       {{1, 1}, {0, 0}, {1, 2}, {1, 2}},
	PieceS:       {{1, 1}, {0, 0}, {1, 2}, {1, 2}},
	PieceT:       {{1, 1}, {0, 2}, {1, 2}, {1, 2}},
	PieceZ:       {{1, 1}, {0, 0}, {1, 2}, {1, 2}},
}
View Source
var AllRotationPivotsCW = [][]Point{
	PieceUnknown: {{0, 0}, {0, 0}, {0, 0}, {0, 0}},
	PieceI:       {{1, -2}, {-1, 0}, {1, -1}, {0, 0}},
	PieceO:       {{1, 0}, {1, 0}, {1, 0}, {1, 0}},
	PieceJ:       {{1, -1}, {0, 0}, {1, 0}, {1, 0}},
	PieceL:       {{1, -1}, {0, 0}, {1, 0}, {1, 0}},
	PieceS:       {{1, -1}, {0, 0}, {1, 0}, {1, 0}},
	PieceT:       {{1, -1}, {0, 0}, {1, 0}, {1, 0}},
	PieceZ:       {{1, -1}, {0, 0}, {1, 0}, {1, 0}},
}
View Source
var Colors = [][]byte{
	BlockNone:         []byte("#000000"),
	BlockGarbage:      []byte("#999999"),
	BlockGhostBlue:    []byte("#6e7bc3"),
	BlockGhostCyan:    []byte("#6bbaba"),
	BlockGhostRed:     []byte("#ba6b6b"),
	BlockGhostYellow:  []byte("#b1b16b"),
	BlockGhostMagenta: []byte("#a16ba8"),
	BlockGhostGreen:   []byte("#6bb76b"),
	BlockGhostOrange:  []byte("#c3806c"),
	BlockSolidBlue:    []byte("#2864ff"),
	BlockSolidCyan:    []byte("#00eeee"),
	BlockSolidRed:     []byte("#ee0000"),
	BlockSolidYellow:  []byte("#dddd00"),
	BlockSolidMagenta: []byte("#c000cc"),
	BlockSolidGreen:   []byte("#00e900"),
	BlockSolidOrange:  []byte("#ff7308"),
}

Dark color ghosts are 60% original overlaid #777777 Light color ghosts are 40% original overlaid #888888

Functions

func I

func I(x int, y int, w int) int

Types

type Bag

type Bag struct {
	Minos    []Mino
	Original []Mino

	*sync.Mutex
	// contains filtered or unexported fields
}

func NewBag

func NewBag(seed int64, minos []Mino, width int) (*Bag, error)

func (*Bag) GarbageHole

func (b *Bag) GarbageHole() int

func (*Bag) Next

func (b *Bag) Next() Mino

func (*Bag) Take

func (b *Bag) Take() Mino

type Block

type Block int
const (
	BlockNone Block = iota
	BlockGarbage
	BlockGhostBlue
	BlockGhostCyan
	BlockGhostRed
	BlockGhostYellow
	BlockGhostMagenta
	BlockGhostGreen
	BlockGhostOrange
	BlockSolidBlue
	BlockSolidCyan
	BlockSolidRed
	BlockSolidYellow
	BlockSolidMagenta
	BlockSolidGreen
	BlockSolidOrange
)

func (Block) Rune

func (b Block) Rune() rune

func (Block) String

func (b Block) String() string

type LockedMatrix

type LockedMatrix *Matrix

Type alias used during marshalling

type LockedPiece

type LockedPiece *Piece

type Matrix

type Matrix struct {
	W int `json:"-"` // Width
	H int `json:"-"` // Height
	B int `json:"-"` // Buffer height

	M []Block // Matrix
	O []Block `json:"-"` // Overlay

	Bag        *Bag `json:"-"`
	P          *Piece
	PlayerName string `json:"pn,omitempty"`

	Type MatrixType `json:"ty,omitempty"`

	Event chan<- interface{} `json:"-"`
	Move  chan int           `json:"-"`

	Combo              int       `json:"mc,omitempty"`
	ComboStart         time.Time `json:"-"`
	ComboEnd           time.Time `json:"-"`
	PendingGarbage     int       `json:"-"`
	PendingGarbageTime time.Time `json:"-"`

	LinesCleared    int `json:"lc,omitempty"`
	GarbageSent     int `json:"gs,omitempty"`
	GarbageReceived int `json:"gr,omitempty"`
	Speed           int `json:"sp,omitempty"`

	GameOver bool `json:"go,omitempty"`

	sync.Mutex `json:"-"`
	// contains filtered or unexported fields
}

func NewMatrix

func NewMatrix(w int, h int, b int, players int, event chan<- interface{}, draw chan event.DrawObject, t MatrixType) *Matrix

func NewTestMatrix

func NewTestMatrix() (*Matrix, error)

func (*Matrix) Add

func (m *Matrix) Add(mn *Piece, b Block, loc Point, overlay bool) error

func (*Matrix) AddPendingGarbage

func (m *Matrix) AddPendingGarbage(lines int)

func (*Matrix) AddTestBlocks

func (m *Matrix) AddTestBlocks()

func (*Matrix) AttachBag

func (m *Matrix) AttachBag(bag *Bag) bool

func (*Matrix) Block

func (m *Matrix) Block(x int, y int) Block

func (*Matrix) CalculateBonusGarbage

func (m *Matrix) CalculateBonusGarbage() int

func (*Matrix) CanAdd

func (m *Matrix) CanAdd(mn *Piece) bool

func (*Matrix) CanAddAt

func (m *Matrix) CanAddAt(mn *Piece, loc Point) bool

func (*Matrix) Clear

func (m *Matrix) Clear()

func (*Matrix) ClearFilled

func (m *Matrix) ClearFilled() int

func (*Matrix) ClearOverlay

func (m *Matrix) ClearOverlay()

func (*Matrix) ClearOverlayL added in v0.1.4

func (m *Matrix) ClearOverlayL()

func (*Matrix) Draw

func (m *Matrix) Draw()

func (*Matrix) DrawActivePieceL added in v0.1.4

func (m *Matrix) DrawActivePieceL()

func (*Matrix) DrawGhostPieceL added in v0.1.4

func (m *Matrix) DrawGhostPieceL()

func (*Matrix) Empty

func (m *Matrix) Empty(loc Point) bool

func (*Matrix) HandleReceiveGarbage

func (m *Matrix) HandleReceiveGarbage()

func (*Matrix) HardDropPiece

func (m *Matrix) HardDropPiece()

func (*Matrix) LineFilled

func (m *Matrix) LineFilled(y int) bool

func (*Matrix) LowerPiece

func (m *Matrix) LowerPiece()

LowerPiece lowers the active piece by one line when possible, otherwise the piece is landed

func (*Matrix) MarshalJSON

func (m *Matrix) MarshalJSON() ([]byte, error)

func (*Matrix) MovePiece

func (m *Matrix) MovePiece(x int, y int) bool

func (*Matrix) Moved

func (m *Matrix) Moved()

func (*Matrix) ReceiveGarbage

func (m *Matrix) ReceiveGarbage()

func (*Matrix) Render

func (m *Matrix) Render() string

func (*Matrix) Replace

func (m *Matrix) Replace(newmtx *Matrix)

func (*Matrix) Reset

func (m *Matrix) Reset()

func (*Matrix) RotatePiece

func (m *Matrix) RotatePiece(rotations int, direction int) bool

func (*Matrix) SetBlock

func (m *Matrix) SetBlock(x int, y int, block Block, overlay bool) bool

func (*Matrix) SetGameOver

func (m *Matrix) SetGameOver()

func (*Matrix) SpawnLocation added in v0.1.1

func (m *Matrix) SpawnLocation(p *Piece) Point

func (*Matrix) TakePiece

func (m *Matrix) TakePiece() bool

func (*Matrix) ValidPoint added in v0.1.4

func (m *Matrix) ValidPoint(x int, y int) bool

type MatrixType

type MatrixType int
const (
	MatrixStandard MatrixType = iota
	MatrixPreview
	MatrixCustom
)

type Mino

type Mino []Point

func Generate

func Generate(rank int) ([]Mino, error)

Generate procedurally generates minos of a supplied rank.

func NewMino added in v0.1.2

func NewMino(points string) Mino

func (Mino) Canonical

func (m Mino) Canonical() Mino

func (Mino) Flatten

func (m Mino) Flatten() Mino

func (Mino) HasPoint

func (m Mino) HasPoint(p Point) bool

func (Mino) Len

func (m Mino) Len() int

func (Mino) Less

func (m Mino) Less(i, j int) bool

func (Mino) NewMinos added in v0.1.4

func (m Mino) NewMinos() []Mino

NewMinos returns a new mino for every new neighborhood point of a mino.

func (Mino) NewPoints added in v0.1.4

func (m Mino) NewPoints() []Point

NewPoints calculates the neighborhood of each point of a mino and returns only new points.

func (Mino) Origin

func (m Mino) Origin() Mino

func (Mino) Render

func (m Mino) Render() string

func (Mino) Size

func (m Mino) Size() (int, int)

func (Mino) String

func (m Mino) String() string

func (Mino) Swap

func (m Mino) Swap(i, j int)

func (Mino) Variations

func (m Mino) Variations() []Mino

type Piece

type Piece struct {
	Point    `json:"pp,omitempty"`
	Mino     `json:"pm,omitempty"`
	Ghost    Block `json:"pg,omitempty"`
	Solid    Block `json:"ps,omitempty"`
	Rotation int   `json:"pr,omitempty"`

	sync.Mutex `json:"-"`
	// contains filtered or unexported fields
}

func NewPiece

func NewPiece(m Mino, loc Point) *Piece

func (*Piece) ApplyReset

func (p *Piece) ApplyReset()

func (*Piece) ApplyRotation

func (p *Piece) ApplyRotation(rotations int, direction int)

func (*Piece) Rotate

func (p *Piece) Rotate(rotations int, direction int) Mino

Rotate returns the new mino of a piece when a rotation is applied

func (*Piece) SetLocation

func (p *Piece) SetLocation(x int, y int)

func (*Piece) String

func (p *Piece) String() string

type PieceType

type PieceType int
const (
	PieceUnknown PieceType = iota
	PieceI
	PieceO
	PieceJ
	PieceL
	PieceS
	PieceT
	PieceZ
)

type Point

type Point struct {
	X, Y int
}

func (Point) Neighborhood

func (p Point) Neighborhood() []Point

Neighborhood returns the Von Neumann neighborhood of a point

func (Point) Reflect

func (p Point) Reflect() Point

func (Point) Rotate180

func (p Point) Rotate180() Point

func (Point) Rotate270

func (p Point) Rotate270() Point

func (Point) Rotate90

func (p Point) Rotate90() Point

func (Point) String

func (p Point) String() string

type RotationOffsets

type RotationOffsets []Point

Jump to

Keyboard shortcuts

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