C, 727 [...] 596 581 556 517 496 471 461 457 chars
This is my first code golf, I think character count can get much lower, would be nice if experienced golfers can give me some hints.
The current version can handle playfields with different dimensions, too. The input can have linebreaks in both DOS/Windows and Unix format.
The code was pretty straightforward before optimization, the tetrominoes are stored in 4 integers that are interpreted as an (7*3)x4 bit array, the playfield is stored as-is, tiles are dropped and complete lines are removed at start and after each tile drop.
I wasn't sure how to count characters, so I used the filesize of the code with all unneccessary linebreaks removed.
EDIT 596=>581: Thanks to KitsuneYMG, everything except the %ls
suggestion worked perfectly, additionally, I noticed putch
instead of putchar
can be used (getch
somehow doesn't work) and removed all the parentheses in #define G
.
EDIT 581=>556: Wasn't satisfied with the remaining for
and the nested F
loops, so there was some merging, changing and removing of loops, quite confusing but definitely worth it.
EDIT 556=>517: Finally found a way to make a
an int array. Some N;
merged with c
, no break
anymore.
EDIT 496=>471: Playfield width and height fixed now.
EDIT 471=>461: Minor modifications, putchar
used again as putch
is no standard function.
EDIT: Bugfix, complete lines were removed before tile drop instead of after, so complete lines could be left at the end. Fix doesn't change the character count.
#define N (c=getchar())
#define G T[j%4]&1<w){t=C[c];x=N-86;
W(c){F(j,12)if(G&&X>1?a[X]-32:0)c=0;
F(j,12)if(G&&X>w&&!c)a[X-w]=35;x+=w;}N;
F(i,6){A=0;t=i*w;F(x,w)A|=(a[t+x]==32);
if(!A){s++;F(j,t)a[t+w-j]=a[t-j];
x=1;W(a[x]-93)a[x++]=32;}}}
F(i,91)putchar(a[i]);printf("%i0",s);}