#include<time.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int i[250],Y[25],X[10]={20};
int main()
{
textmode(C40);
_setcursortype(_NOCURSOR);
clock_t T;
srand(time(NULL));
printf("%c[3;28f Nivel=1",27);
char far*q=1967+(char far*)0xB8000000;
char E,C[7][4][4],far*Q[250];
char B[4][4][7][4]={"0000","0000","0000","0000","0000","0000","0000",
"1111","0100","0010","0110","0110","0100","0110",
"0000","0111","1110","0011","1100","1110","0110",
"0000","0000","0000","0000","0000","0000","0000"};
int e[256],f[250],j[4],J[4],F[25],G[]={1,2,3,0};
int g,n,x,y,a=256,c=249,L=48,M=9,p=rand()%7;
while(a--) e[a]=10;
e[72]=e[4]=0;
e[75]=-1;
e[77]=1;
for(y=25;y--;F[y]=c+1,q-=60)
for(x=10;x--;f[c--]=y,q-=2)
if(*(q-1)=*(q+X[x]-1)=219)
*(Q[c]=q)=*(q+X[x])=y%24<1||!x?8:0;
for(g=4;g--;L=0)
for(a=7;a--;)
for(n=y=4;y--;)
for(x=4;x--;) if(B[g][y][a][x]=B[G[g]][x][a][3-y]-L)
C[a][g][--n]=F[y]+x;
Inicio:
for(g=n=0;n<4;i[J[n++]]++)
if(*Q[J[n]=C[a=p][0][n]+4]) break;
else if(*Q[J[n]]=a+1)
*(Q[J[n]]+502)=0;
while (n<4) if(getch()==27)
return 0;
p=rand()%7;
while(n--) if(*(q=Q[C[p][0][n]]+510)=p+1)
*(--q)=219;
c=4;
T=clock();
do{
while(E=kbhit()) getch();
do if(kbhit()) E=getch();
while(!E&&clock()-T<M);
if(E==27&&getch()==E) return 0;
if(E=='-') printf("%c[3;35f%u",27,10-(M+=M<10));
if(E=='+') printf("%c[3;35f%u",27,10-(M-=M>1));
x=c+e[E];
y=e[E]?g:G[g];
for(n=0;n<4;n++)
if(*Q[j[n]=C[a][y][n]+x]&&!i[j[n]]) break;
if(n<4) continue;
while(n--) if(++i[j[n]]<2)
*Q[j[n]]=a+1;
for(E=n=4;n--;J[n]=j[n])
if(--i[J[n]]<1) *Q[J[n]]=0;
c=x;
g=y;
T=clock();
}while(e[E]<10);
for(n=0;n<4;i[J[n++]]--)
Y[y=f[J[n]]]++;
do while(Y[x=y]>8)
do for(L+=x--==y,n=10;--n;)
*Q[F[x+1]+n]=x?*Q[F[x]+n]:0;
while(Y[x+1]=Y[x]);
while(Y[--y]);
printf("%c[5;28fLineas=%u",27,L);
goto Inicio;
}