Given a list of Tetris moves, return the number of completed lines
C, 401 392 383 378 374 351 335 324 320 318 316 305 bytes

d[99]={'3Z3Z',983177049,513351321,1016270793,970073931,~0},*L=d+5,V,s;char c;main(x){B:for(c=0;c[++L]|V;V&gt;&gt;=4)c-=(L[c]=*L|(V&amp;15)&lt;&lt;x)&gt;1022;s-=c;if(scanf("%c%1d%d,",&amp;c,&amp;V,&amp;x)&gt;2)for(V=c^79?d[c/4%5]&gt;&gt;24-V*8:27,V=c^73?V/64%4&lt;&lt;8|V/8%8&lt;&lt;4|V%8:V&amp;32?15:4369;;--L)for(c=4;c--;)if(L[c]&gt;&gt;x&amp;V&gt;&gt;c*4&amp;15)goto B;return s;}


Takes comma-separated input on stdin, returns the score in the exit status.

Requires char to be signed (which is the default for GCC) and requires '3Z3Z' to be interpreted as 861549402 (which is the case for GCC on little endian machines, at least).



Usage example:

echo "O00,T24,S02,T01,L00,Z03,O07,L06,I05,I19" | ./tetris; echo "$?";




High-level explanation:

All shapes except the line can fit in a 3x3 grid with one corner missing:

6 7 -
3 4 5
0 1 2


That means it's easy to store them in a byte each. For example:

- - -         0 0 -
- # -   --&gt;   0 1 0   --&gt;   0b00010111
# # #         1 1 1


(we align each piece to the bottom-left of the box to make dropping it easier)

Since we get at least 4 bytes to an int, this means we can store all 4 rotations of each piece in a single integer, with a special case for the line. We can also fit each row of the game grid into an int (only needs 10 bits), and the currently falling piece into a long (4 lines = 40 bits).



Breakdown:

d[99]={             // General memory
  '3Z3Z',           //  Shape of "S" piece (multi-char literal, value = 861549402)
  983177049,        //  Shape of "T" piece
  513351321,        //  Shape of "Z" piece
  1016270793,       //  Shape of "J" piece
  970073931,        //  Shape of "L" piece
  ~0                //  Bottom of game grid (solid row)
},                  //  Rest of array stores lines in the game
*L=d+5,             // Working line pointer (start &gt;= base of grid)
V,                  // Current piece after expansion (also stores rotation)
s;                  // Current score (global to initialise as 0)
char c;             // Input shape identifier (also counts deleted lines)
main(x){            // "x" used to store x location
  B:                                // Loop label; jumps here when piece hits floor
  for(c=0;c[++L]|V;V&gt;&gt;=4)           // Paint latest piece &amp; delete completed lines
    c-=(L[c]=*L|(V&amp;15)&lt;&lt;x)&gt;1022;
  s-=c;                             // Increment score
  if(scanf("%c%1d%d,",&amp;c,&amp;V,&amp;x)&gt;2)  // Load next command
    for(V=c^79?                     // Identify piece &amp; rotation
          d[c/4%5]&gt;&gt;24-V*8          //  Not "O": load from data
        :27,                        //  Else "O": always 27
        V=c^73?                     // If not "I" (line):
          V/64%4&lt;&lt;8|V/8%8&lt;&lt;4|V%8    //  expand shape to 16-bits
        :                           // Else we are a line:
          V&amp;32?                     //  "I" coincides with "J"; use this to check
               15:4369;             //  horizontal/vertical
        ;--L)                       // Loop from top-to-bottom of grid
      for(c=4;c--;)                 //  Loop through rows of piece
        if(L[c]&gt;&gt;x&amp;V&gt;&gt;c*4&amp;15)       //   If collides with existing piece:
          goto B;                   //    Exit loops
  return s;                         // Return score in exit status
}




-4, -1 thanks to @Titus, and -23, -11 with inspiration from their answer