
As a result, T-spin when the T-piece is touching the bottom row becomes impossible. This changes the center of rotation for the T-piece for this one particular rotation scenario, and will ultimately prevent the rotation altogether as it will cause a collision with other, already-placed tetriminos.
#Tetris t spin code
It is in step 4 where the problem occurs: if a T-piece has been rotated such that its flat side is vertical and its left or right corner is touching the bottom of the bucket, and is then rotated once such that its flat side is now facing the bottom, the re-alignment code will push the T-piece down one row: it was touching the bottom of the bucket before rotation, so the re-alignment code makes the flat side of the T-piece touch the bottom of the bucket after rotation. If the tetrimino is now in collision with another block already in the bucket (meaning that it is occupying one or more squares in the bucket that are already occupied), the rotation is disallowed and the previous position and rotation restored.to stop pieces from moving up as a result of rotation at the bottom of the bucket when the rotation of a piece would leave one or more empty rows underneath it that were occupied in the previous rotation (otherwise, the player could keep rotating L-pieces forever, for example) to prevent pieces from becoming partially outside the bucket, and 2. We move it left so that the I-piece’s right-hand edge is at the right-hand edge of the bucket. It is now horizontal and sticking out of the right-hand side. Example: an I-piece is vertical at the right-hand edge of the bucket. For example, if the piece was touching the bottom and left of the bucket before rotation, re-align it after rotation so that it is still touching the bottom and left of the bucket.


For T-spins to work, the square which connects the three corner squares should always remain in the same place when the rotation is performed (ie. This is part of the array which contains the basic layouts of all the tetriminos in each of their possible rotation states. The first problem can be found in the actual data definition of the T-piece: Since the collision detection code that executes in SimpleTetris when a piece is rotated merely checks if the rotated piece is touching anything already in the bucket – crucially, not caring about whether the rotation was actually possible in the first place or not – this should have just worked, but it doesn’t.

This ‘impossible’ rotation of T-pieces where in real life the piece would be locked into place is the premise of the T-spin.įor those not in the know, the Tetris Wikia T-spin page has some excellent explanations and diagrams of what T-spins are namely, when you rotate a T-shaped Tetris piece in a way that would be impossible in real life (due to the corners being obstructed by other blocks) such that it fits snugly into a T or notch-shaped hole (see image). The orange-coloured T-piece here will fall 2 more rows, at which point it can be rotated such that it will complete the bottom 2 rows.
