tris

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyPiece = Piece{}
	IPiece     = Piece{0x0F00, 0x4444, 0x00F0, 0x2222}
	JPiece     = Piece{0x1700, 0x6220, 0x0740, 0x2230}
	LPiece     = Piece{0x4700, 0x2260, 0x0710, 0x3220}
	OPiece     = Piece{0x6600, 0x6600, 0x6600, 0x6600}
	SPiece     = Piece{0x6300, 0x2640, 0x0630, 0x1320}
	TPiece     = Piece{0x2700, 0x2620, 0x0720, 0x2320}
	ZPiece     = Piece{0x3600, 0x4620, 0x0360, 0x2310}
)

A table that represents each piece from https://tetris.fandom.com/wiki/SRS in binary starting with 1 top left going per row, here in hexadecimal shorthand.

View Source
var K3CW = Kicks{
	0: {{X: 0, Y: 0}, {X: -1, Y: 0}, {X: -1, Y: -1}, {X: 0, Y: 2}, {X: -1, Y: 2}},
	1: {{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}, {X: 0, Y: -2}, {X: 1, Y: -2}},
	2: {{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: -1}, {X: 0, Y: 2}, {X: 1, Y: 2}},
	3: {{X: 0, Y: 0}, {X: -1, Y: 0}, {X: -1, Y: 1}, {X: 0, Y: -2}, {X: -1, Y: -2}},
}

Kics for all pieces except I and O pieces

View Source
var LCW = Kicks{
	0: {{X: 0, Y: 0}, {X: -2, Y: 0}, {X: 1, Y: 0}, {X: -2, Y: 1}, {X: 1, Y: -2}},
	1: {{X: 0, Y: 0}, {X: -1, Y: 0}, {X: 2, Y: 0}, {X: -1, Y: -2}, {X: 2, Y: 1}},
	2: {{X: 0, Y: 0}, {X: 2, Y: 0}, {X: -1, Y: 0}, {X: 2, Y: -1}, {X: -1, Y: 2}},
	3: {{X: 0, Y: 0}, {X: 1, Y: 0}, {X: -2, Y: 0}, {X: 1, Y: 2}, {X: -2, Y: -1}},
}

Long Bar (I piece) Kicks

View Source
var LockDelay = time.Second / 2
View Source
var Swapped bool

Functions

This section is empty.

Types

type Bag

type Bag []Piece

func NewBag added in v0.0.2

func NewBag() Bag

func (Bag) Next added in v0.3.0

func (b Bag) Next(n int) (Bag, Field)

func (Bag) Pick added in v0.0.2

func (b Bag) Pick() (Bag, Placement)

func (Bag) Randomize added in v0.0.2

func (b Bag) Randomize() Bag

func (Bag) Swap added in v1.0.0

func (b Bag) Swap(p Placement) (Bag, Placement)

type Field

type Field [][]int
var HoldBox Field

func NewField added in v1.0.0

func NewField(h, w int) Field

func (Field) Add added in v0.0.2

func (f Field) Add(p Placement) Field

Add merges the Field and Piece together

func (Field) H added in v1.0.0

func (f Field) H() int

func (Field) Lines added in v0.1.0

func (f Field) Lines() (int, Field)

Lines counts the number of lines that is completed and returns a Field with them removed

func (Field) String

func (f Field) String() (output string)

func (Field) W added in v1.0.0

func (f Field) W() int

type Kicks added in v0.1.0

type Kicks map[Rotation][]Point

As at the bottom of https://tetris.fandom.com/wiki/SRS but Y inverse because we start Y at the top

func (Kicks) Try added in v0.2.0

func (ks Kicks) Try(p, np Placement, f Field) Placement

Try all possible kicks

type Piece

type Piece [4]uint16

A piece contains a value per rotation

var HoldPiece Piece

type Placement added in v0.0.2

type Placement struct {
	X    int
	Y    int
	Rot  Rotation
	Lock time.Time
	// contains filtered or unexported fields
}

a placement is the combination of a piece and where it exactly is on the board we use this both for the actual piece and for checking hypothetical positions

func (Placement) Collide added in v0.0.2

func (p Placement) Collide(f Field) bool

Collide checks if any squares of the Placement and the Field overlap

func (Placement) Color added in v1.0.0

func (p Placement) Color() int

func (Placement) Field added in v0.0.2

func (p Placement) Field(h, w int) (Field, bool)

Field translates the Placement into a Field format When it gets out of the board, we return that to the caller with a bool

func (Placement) Floor added in v0.1.0

func (p Placement) Floor(f Field) bool

Floor checks if the piece touches something underneath it

func (Placement) Move added in v0.1.0

func (p Placement) Move(f Field, rot Rotation, x, y int) (np Placement, floor, topout bool)

Move tries the move indicated by the parameters, applies kicks to fix when it doesn't work, and returns if the piece is on the floor or topping out

func (Placement) Points added in v0.0.2

func (p Placement) Points() []Point

Points transforms the piece to a list of coordinates

type Point

type Point struct {
	X, Y int
}

func (Point) Add added in v0.1.0

func (p Point) Add(q Point) Point

Add adds two points together

type Rotation added in v0.0.2

type Rotation int
const (
	Spawn Rotation = iota
	Clockwise
	Flip
	CounterClockwise
)

Jump to

Keyboard shortcuts

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