diff --git a/content/post/tetris-1.md b/content/post/tetris-1.md index 7da6a51..cd13ac9 100644 --- a/content/post/tetris-1.md +++ b/content/post/tetris-1.md @@ -37,6 +37,23 @@ The number of blocks a mino has is also known as its rank. Tetris is played on an [X-Y grid](https://en.wikipedia.org/wiki/Cartesian_coordinate_system), so we will store minos as slices of points. +``` + + + + + + + + + + + + \/\/\/\/\/ +``` + +*Example coordinate positions in 10x10 playfield* + {{< highlight go >}} type Point struct { X, Y int @@ -97,7 +114,17 @@ Origin returns a translated mino located at `0,0` and with positive coordinates only. A mino with the coordinates `(-3, -1), (-2, -1), (-1, -1), (-2, 0)` would be -translated to `(0, 0), (1, 0), (2, 0), (1, 1)`. +translated to `(0, 0), (1, 0), (2, 0), (1, 1)`: + +``` + | | + | |X +--X-|----- -> ----XXX--- + XXX| | + | | +``` + +*Translating a mino to `(0,0)`* {{< highlight go >}} func (m Mino) minCoords() (int, int) { @@ -132,6 +159,13 @@ func (m Mino) Origin() Mino { Another transformation is applied not only to help identify duplicate minos, but also to retrieve their initial rotation, as [pieces should spawn flat-side down](https://tetris.wiki/Super_Rotation_System). +``` +XXX X + X -> XXX +``` + +*Flattening a mino* + Flatten calculates the flattest side of a mino and returns a flattened mino. {{< highlight go >}} @@ -188,6 +222,14 @@ func (m Mino) Flatten() Mino { Variations returns the three other rotations of a mino. +``` + X X X +XXX -> XX XXX XX + X X X +``` + +*Variations of a mino* + {{< highlight go >}} func (m Mino) Variations() []Mino { v := make([]Mino, 3) @@ -237,6 +279,13 @@ func (m Mino) Canonical() Mino { Starting with a monomino (a mino with a single point: `0,0`), we will generate additional minos by adding neighboring points. +``` + X XX X X X XX XX +X -> XX -> XXX XX -> XXXX XX XXX XXX XXX XX XX +``` + +*Mino generation* + Neighborhood returns the [Von Neumann neighborhood](https://en.wikipedia.org/wiki/Von_Neumann_neighborhood) of a point. {{< highlight go >}}