#include<dos.h>
#include<time.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int i[250],Y[25];
int main()
{
_AX=0x13;
geninterrupt(0x10);
clock_t T;
srand(time(NULL));
printf("%c[3;28f Nivel=1",27);
char far*q=61960+(char far*)0xA0000000;
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],D[49],F[25],G[]={1,2,3,0};
int a,g,n,x,y,b=256,c=249,d=49,L=48,M=9,p=rand()%7;
while(d--) D[d]=d/7*320+d%7;
while(b--) e[b]=10;
e[72]=e[4]=0;
e[75]=-1;
e[77]=1;
for(y=25;y--;F[y]=c+1,q-=2480)
for(x=10;x--;Q[c]=q,f[c--]=y,q-=8)
if(!x||y%24<1) for(d=49;d--;*(q+D[d])=8)
if(!x) *(q+D[d]+80)=8;
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;n++)
if(*Q[b=C[a=p][0][n]+4]) break;
else for(i[b]++,d=49;d--;*(Q[b]+D[d])=a+1)
*(Q[b]+D[d]+17048)=0;
while (n<4) if(getch()==27)
return 0;
p=rand()%7;
while(n--) for(b=C[p][0][n],d=49;d--;)
*(Q[b]+D[d]+17080)=p+1;
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[b=C[a][y][n]+x]&&!i[b]) break;
if(n<4) continue;
while(n--) if(++i[b=C[a][y][n]+x]<2)
for(d=49;d--;)
*(Q[b]+D[d])=a+1;
for(E=n=4;n--;) if(--i[b=C[a][g][n]+c]<1)
for(d=49;d--;)
*(Q[b]+D[d])=0;
c=x;
g=y;
T=clock();
}while(e[E]<10);
for(n=0;n<4;n++,i[b]--)
Y[y=f[b=C[a][g][n]+c]]++;
do while(Y[x=y]>8)
do for(L+=x--==y,n=10;--n;)
if(*Q[c=F[x]+n]!=*Q[b=c+10])
for(a=x?*Q[c]:0,d=49;d--;)
*(Q[b]+D[d])=a;
while(Y[x+1]=Y[x]);
while(Y[--y]);
printf("%c[5;28fLineas=%u",27,L);
goto Inicio;
}