Documentation ¶
Index ¶
- Variables
- type Action
- type ActionContainer
- type Coordinate
- type Fall
- type Matrix
- func (m *Matrix) AddTetrimino(tet *Tetrimino) error
- func (m *Matrix) DeepCopy() *Matrix
- func (m *Matrix) GetHeight() int
- func (m *Matrix) GetSkyline() int
- func (m *Matrix) GetVisible() Matrix
- func (m *Matrix) RemoveCompletedLines(tet *Tetrimino) Action
- func (m *Matrix) RemoveTetrimino(tet *Tetrimino) error
- type NextQueue
- type RotationCompass
- type RotationSet
- type Scoring
- type Tetrimino
- func (t *Tetrimino) DeepCopy() *Tetrimino
- func (t *Tetrimino) IsAboveSkyline(skyline int) bool
- func (t *Tetrimino) IsOverlapping(matrix Matrix) bool
- func (t *Tetrimino) MoveDown(matrix Matrix) bool
- func (t *Tetrimino) MoveLeft(matrix Matrix) bool
- func (t *Tetrimino) MoveRight(matrix Matrix) bool
- func (t *Tetrimino) Rotate(matrix Matrix, clockwise bool) error
Constants ¶
This section is empty.
Variables ¶
var Actions = ActionContainer{ Unknown: Action{actionUnknown}, None: Action{actionNone}, Single: Action{actionSingle}, Double: Action{actionDouble}, Triple: Action{actionTriple}, Tetris: Action{actionTetris}, MiniTSpin: Action{actionMiniTSpin}, MiniTSpinSingle: Action{actionMiniTSpinSingle}, TSpin: Action{actionTSpin}, TSpinSingle: Action{actionTSpinSingle}, TSpinDouble: Action{actionTSpinDouble}, TSpinTriple: Action{actionTSpinTriple}, }
Actions is a global instance of ActionContainer that contains all possible values of type Action.
var RotationCompasses = map[byte]RotationCompass{
'I': {
{
{X: -1, Y: 1}, {X: 0, Y: 1}, {X: -3, Y: 1}, {X: 0, Y: 3}, {X: -3, Y: 0},
},
{
{X: 2, Y: -1}, {X: 0, Y: -1}, {X: 3, Y: -1}, {X: 0, Y: 0}, {X: 3, Y: -3},
},
{
{X: -2, Y: 2}, {X: -3, Y: 2}, {X: 0, Y: 2}, {X: -3, Y: 0}, {X: 0, Y: 3},
},
{
{X: 1, Y: -2}, {X: 3, Y: -2}, {X: 0, Y: -2}, {X: 3, Y: -3}, {X: 0, Y: 0},
},
},
'O': {
{
{X: 0, Y: 0},
},
{
{X: 0, Y: 0},
},
{
{X: 0, Y: 0},
},
{
{X: 0, Y: 0},
},
},
'6': {
{
{X: 0, Y: 0}, {X: -1, Y: 0}, {X: -1, Y: 1}, {X: 0, Y: -2}, {X: -1, Y: -2},
},
{
{X: 1, Y: 0}, {X: 0, Y: 0}, {X: 0, Y: -1}, {X: 1, Y: 2}, {X: 0, Y: 2},
},
{
{X: -1, Y: 1}, {X: 0, Y: 1}, {X: 0, Y: 2}, {X: -1, Y: -1}, {X: 0, Y: -1},
},
{
{X: 0, Y: -1}, {X: 1, Y: -1}, {X: 1, Y: -2}, {X: 0, Y: 1}, {X: 1, Y: 1},
},
},
}
RotationCompasses is a map of Tetrimino values to the coordinates used for rotation. Each slice should contain a coordinate for north, east, south, and west in that order. These are added to (clockwise) or subtracted from (counter-clockwise) the Tetrimino's position when rotating to ensure it rotates around the correct axis.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct {
// contains filtered or unexported fields
}
An Action performed by the user that corresponds to points.
func ParseAction ¶
ParseAction attempts to parse the given value into Action. It supports string, fmt.Stringer, int, int64, and int32. If the value is not a valid Action or the value is not a supported type, it will return the enums unknown value (unknownAction).
func (Action) EndsBackToBack ¶
func (Action) StartsBackToBack ¶
type ActionContainer ¶
type Fall ¶
func (*Fall) CalculateFallSpeeds ¶
func (*Fall) ToggleSoftDrop ¶
func (f *Fall) ToggleSoftDrop()
type Matrix ¶
type Matrix [][]byte
Matrix represents the board of cells on which the game is played.
func DefaultMatrix ¶
func DefaultMatrix() Matrix
func (*Matrix) AddTetrimino ¶
AddTetrimino adds the given Tetrimino to the Matrix. It returns an error if the Tetrimino is out of bounds or if the Tetrimino overlaps with an occupied mino.
func (*Matrix) GetSkyline ¶
GetSkyline returns the skyline; the highest row that the player can see.
func (*Matrix) GetVisible ¶
GetVisible returns the Matrix without the buffer zone at the top (ie. the visible portion of the Matrix).
func (*Matrix) RemoveCompletedLines ¶
RemoveCompletedLines checks each row that the given Tetrimino occupies and removes any completed lines from the Matrix. It returns an Action to be used for calculating the score.
func (*Matrix) RemoveTetrimino ¶
RemoveTetrimino removes the given Tetrimino from the Matrix. It returns an error if the Tetrimino is out of bounds or if the Tetrimino is not found in the Matrix.
type NextQueue ¶
type NextQueue struct {
// contains filtered or unexported fields
}
NextQueue is a collection of up to 14 Tetriminos that are drawn from randomly. The queue is refilled when it has less than 7 Tetriminos.
func NewNextQueue ¶
NewNextQueue creates a new NextQueue of Tetriminos.
func (*NextQueue) GetElements ¶
type RotationCompass ¶ added in v0.1.2
type RotationCompass [4]RotationSet
A RotationCompass contains a RotationSet corresponding to each of the four compass directions in the order N, E, S, W. These compass directions represent the four rotations of a Tetrimino.
type RotationSet ¶ added in v0.1.2
type RotationSet []*Coordinate
A RotationSet contains coordinates to be used for a single rotation/compass direction. If the first coordinate cannot be used the next will be attempted. This continues until there are no more coordinates to fall back on (in which case rotation is not possible). This is part of the Super Rotation System (SRS).
type Scoring ¶
type Scoring struct {
// contains filtered or unexported fields
}
func NewScoring ¶
func (*Scoring) AddHardDrop ¶
func (*Scoring) AddSoftDrop ¶
type Tetrimino ¶
type Tetrimino struct { // The value of the Tetrimino. This is the character that will be used to represent the Tetrimino in the matrix. Value byte Minos [][]bool // A 2D slice of cells that make up the Tetrimino. True means the mino is occupied by a Mino. Pos Coordinate // The top left mino of the Tetrimino. Used as a reference point for movement and rotation. CompassDirection int // The index of the current rotation in the RotationCompass (ie. North, South, East, West). RotationCompass RotationCompass }
A Tetrimino is a geometric Tetris shape formed by four Minos connected along their sides.
func GetEmptyTetrimino ¶
func GetEmptyTetrimino() *Tetrimino
GetEmptyTetrimino returns a tetrimino with no minos or value. To be used for the starting (empty) hold.
func GetTetrimino ¶
GetTetrimino returns the Tetrmino with the given value. Valid values include: I, O, T, S, Z, J, L.
func GetValidTetriminos ¶
func GetValidTetriminos() []Tetrimino
GetValidTetriminos returns a slice containing all seven valid Tetriminos (I, O, T, S, Z, J, L).
func (*Tetrimino) IsAboveSkyline ¶
IsAboveSkyline returns true if the entire Tetrimino is above the skyline. This can be helpful when checking for Lock Out.
func (*Tetrimino) IsOverlapping ¶
IsOverlapping checks whether the Tetrimino would be overlapping with an occupied Mino if it were on the Matrix. The Tetrmino should not yet be added to the Matrix, otherwise this will always return true as a Tetrimino is always overlapping with itself.
func (*Tetrimino) MoveDown ¶
MoveDown moves the tetrimino down one row. This does not modify the matrix. If the tetrimino cannot move down, it will not be modified and false will be returned.
func (*Tetrimino) MoveLeft ¶
MoveLeft moves the tetrimino left one column. This does not modify the matrix. If the tetrimino cannot move left false will be returned.