<p>What are the best algorithms (and explanations) for representing and rotating the pieces of a tetris game?  I always find the piece rotation and representation schemes confusing.</p>

<p>Most tetris games seem to use a naive "remake the array of blocks" at each rotation:</p>

<p><a href="http://www.codeplex.com/Project/ProjectDirectory.aspx?ProjectSearchText=tetris" rel="noreferrer">http://www.codeplex.com/Project/ProjectDirectory.aspx?ProjectSearchText=tetris</a></p>

<p>However, some use pre-built encoded numbers and bit shifting to represent each piece:</p>

<p><a href="http://www.codeplex.com/wintris" rel="noreferrer">http://www.codeplex.com/wintris</a></p>

<p>Is there a method to do this using mathematics (not sure that would work on a cell based board)?</p>

There is a limited amount of shapes, so I would use a fixed table and no calculation. That saves time.
But there are rotation algorithms.
Chose a centerpoint and rotate pi/2.
If a block of a piece starts at (1,2) it moves clockwise to (2,-1) and (-1,-2) and (-1, 2).
Apply this for each block and the piece is rotated.
Each x is the previous y and each y - the previous x. Which gives the following matrix:
```
```
[  0   1 ]
[ -1   0 ]
```
```
For counterclockwise rotation, use:
```
```
[  0  -1 ]
[  1   0 ]
```
```