User:Ryan heise

The current definition of TGM wall kicks (from the wiki)
TGM pioneered the use of wall kicks, with simple but effective kick rules. These rules were unchanged until TGM3, remaining constant across TGM, TA, TAP, and Sakura Tetris. Up to 3 locations are tried, in this order, before rotation will fail:


 * Basic rotation
 * 1 space right of basic rotation
 * 1 space left of basic rotation

In addition to these rules, there are some extra exceptions where certain wall kicks are not allowed:


 * The I tetromino will never kick.
 * L, J, and T tetrominoes will not rotate in the situations illustrated below if the XTet.png marked block is occupied.


 * However, L tetrominoes will rotate clockwise and J tetrominoes counterclockwise in the situations illustrated below if both the XTet.png marked blocks are occupied.

My (broken) proposal
This was my attempt to discover a simple definition than the one above. While a good guess, it was not quite right. See the next section for Zaphod77's description of TGM's true algorithm.

(My theory) A wall kick is possible with L, J, T, S and Z tetrominoes and may be triggered only by those parts of the tetromino that intersect with the following "kick mask":

For example, if an L tetromino is rotated into the orientation shown on the left, only the squares shown on the right can be used to trigger a wall kick:

The general procedure is as follows.


 * Perform a basic rotation
 * Apply the kick mask to determine the trigger squares
 * If any of the trigger squares have not landed on a free cell, then:
 * If there is space, move one column to the right.
 * Otherwise, if there is space, move one column to the left.

If, after this procedure, the tetromino has not succeeded in moving into free space, the entire procedure is reversed and no rotation happens.

This definition gives rise to slightly different behaviour than the original definition. For example, given the following setup:

The original definition says that an anti-clockwise rotation will fail, but the second definition says that a right wall kick will occur:

As confirmed by Kitaru, the right kick should occur, and so this is one case that was missing from the original definition.

Zaphod77's description of TGM's true algorithm
The "is kicking allowed" test is very simple.

It goes from upper left to lower right on the bounding box, one row at a time. it stops when it finds the first overlap.

If the first overlap is center column, rotation is prevented.

Otherwise, try kicks.