#include<dos.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
_AX=0x13;
geninterrupt(0x10);
clock_t T;
srand(time(NULL));
char far*Q=(char far*) 0xA0000000L;
char E,A[][12]={"000000111100",
"000020222000",
"000300033300",
"000400444000",
"000055055000",
"006600066000",
"000770077000"};
int B[]={6,2,10,7,3,0,11,8,4,1,9,5};
int N[]={1,2,11,12,13,14,22,23,24,25,34,35};
int e[49],i[275],C[12],D[12],Y[25];
int a,c,d,x,y,n=433,z=6,M=9,L;
for(c=49;c--;) e[c]=c/7*320+c%7;
for(L=y=0;y<25;y++,n+=2472)
for(Y[y]=y<2,x=0;x<11;x++,n+=8)
for(a=8*(!y||y>23||!x||x>9),i[++c]=n,d=49;d--;)
*(Q+n+e[d])=a;
Inicio:
printf("%c[5;28fLineas=%u",27,L);
printf("%c[3;28f Nivel=%u",27,10-M);
a=z;
z=rand()%7;
for(n=12;n--;)
for(x=17835+N[n]/11*2560+N[n]%11*8,d=49;d--;)
*(Q+x+e[d])=A[z][n]-48;
x=c=15;
while(++n<12)
if(C[n]=A[a][n]-48)
if(!*(Q+i[N[n]+c]))
for(d=49;d--;)
*(Q+i[N[n]+c]+e[d])=C[n];
else while(1) if(getch()==27) return 0;
T=clock();
while(x){while(E=kbhit()) getch();
do if(kbhit()) E=getch();
while(!E&&clock()-T<M);
if(E==27&&getch()==27) return 0;
if(E=='-') M+=M<10;
if(E=='+') M-=M>1;
if(E==77||E==75) x=c+E-76;
else if(E!=72) x=c+(E=11);
for(n=12;n--;D[n]=c-x?C[n]:C[B[n]])
for(d=C[n]?49:0;d--;)
*(Q+i[N[n]+c]+e[d])=0;
while(++n<12)
if(D[n]&&*(Q+i[N[n]+x])) break;
for(x*=n>11,c=x?x:c,n=12;n--;)
if(C[n]=x?D[n]:C[n])
for(d=49;d--;)
*(Q+i[N[n]+c]+e[d])=C[n];
if(E==11) T=clock();
else x=c;
}
y=c/11;
d=y>19?24:y+4;
for(y+=y<2;y<d;Y[y++]=a<9?a:0)
for(n=11*y,a=0,x=9;x--;)
if(*(Q+i[++n])) L+=++a>8;
while(--y)
if(!Y[x=y])
while(--x)
if(Y[x])
for(Y[x]=x<2,Y[y]=x>1,a=11*y,c=11*x,x=1,n=9;n--;)
if(*(Q+i[++a])+*(Q+i[++c]))
for(d=49;d--;*(Q+i[c]+e[d])=0)
*(Q+i[a]+e[d])=*(Q+i[c]+e[d]);
goto Inicio;
}