Tetris, no tengo que explicarlo —-pero hay que llenar de palabras este párrafo—-, es un clásico lleno de clones y variantes; tantos que es difícil recordar el original. En esta ocasión les traigo una más de sus versiones entre las existentes para la línea de comandos: Micro Tetris. (La imagen que sigue no es de Micro Tetris, pero me encantó como una suerte de Tetris Arborescente.)

Instalación
Descarga los 8 K de la recién publicada versión 1.2.0.
wget ftp://ftp.vmlinux.org/pub/People/jocke/micro-tetris/tetris-1.2.0.tar.bz2
Descomprime.
tar jxvf tetris-1.2.0.tar.bz2
Ingresa al directorio y compila e instala —-claro, previamente es necesario que tengas instalado make, GCC y los archivos de cabecera esenciales de lenguaje C.
cd tetris-1.2.0
make && sudo make install
La historia detrás de Micro Tetris pueden leerla en el archivo README. Resulta que las 424 líneas de tetris.c están basadas en las 19 del ganador del concurso de código C ofuscado al mejor juego. De hecho, me permito presentárselas. Pueden copiarlas en un archivo .c y luego compilarlas. Les aseguro que funciona perfectamente.
<
pre lang=”c”>
long h[4];t(){h[3]-=h[3]/3000;setitimer(0,h,0);}c,d,l,v[]={(int)t,0,2},w,s,I,K
=0,i=276,j,k,q[276],Q[276],n=q,m,x=17,f[]={7,-13,-12,1,8,-11,-12,-1,9,-1,1,
12,3,-13,-12,-1,12,-1,11,1,15,-1,13,1,18,-1,1,2,0,-12,-1,11,1,-12,1,13,10,-12,
1,12,11,-12,-1,1,2,-12,-1,12,13,-12,12,13,14,-11,-1,1,4,-13,-12,12,16,-11,-12,
12,17,-13,1,-1,5,-12,12,11,6,-12,12,24};u(){for(i=11;++i<264;)if((k=q[i])-Q[i]
){Q[i]=k;if(i-++I||i%12<1)printf(“\033[%d;%dH”,(I=i)/12,i%122+28);printf(
“\033[%dm “+(K-k?0:5),k);K=k;}Q[263]=c=getchar();}G(b){for(i=4;i—;)if(q[i?b+
n[i]:b])return 0;return 1;}g(b){for(i=4;i—;q[i?x+n[i]:x]=b);}main(C,V,a)char
V,a;{h[3]=1000000/(l=C>1?atoi(V[1]):2);for(a=C>2?V[2]:”jkl pq”;i;i—)n++=i<
25||i%12<2?7:0;srand(getpid());system(“stty cbreak -echo stop u”);sigvec(14,v,
0);t();puts(“\033[H\033[J”);for(n=f+rand()%74;;g(7),u(),g(0)){if(c<0){if(G(x+
12))x+=12;else{g(7);++w;for(j=0;j<252;j=12(j/12+1))for(;q[++j];)if(j%12==10){
for(;j%12;q[j—]=0);u();for(;—j;q[j+12]=q[j]);u();}n=f+rand()%74;G(x=17)||(c
=a[5]);}}if(c==*a)G(—x)||++x;if(c==a[1])n=f+4**(m=n),G(x)||(n=m);if(c==a[2])G
(++x)||—x;if(c==a[3])for(;G(x+12);++w)x+=12;if(c==a[4]||c==a[5]){s=sigblock(
8192);printf(“\033[H\033[J\033[0m%d\n”,w);if(c==a[5])break;for(j=264;j—;Q[j]=
0);while(getchar()-a[4]);puts(“\033[H\033[J\033[7m”);sigsetmask(s);}}d=popen(
“stty -cbreak echo stop \023;sort -mnr -o HI - HI;cat HI”,”w”);fprintf(d,
“%4d from level %1d by %s\n”,w,l,getlogin());pclose(d);}
Uso
Simplemente ejecuta esto en tu línea de comandos:
tetris

Seis teclas serán tu mando de control a lo largo de varios niveles de dificultad.
Comentarios
Minimalista. Eficiente. Genial.
Imagen: Fotero










Llevo un rato con las “19 líneas dichosas” pero no soy capaz ajajja De primeras le faltan los #include, pero luego sigue dando errores y no me deja. ¿Tú lo has conseguido compilar? Es que ya me corroe la curiosidad :)
Muy interesante el articulo.
Si compila con ==> gcc -o tetris tetris.c
le puse estas librerías
include <stdio.h>
include <stdlib.h>
include <string.h>
y da 3 warnings :
tetris.c:22: warning: assignment makes integer from pointer without a cast tetris.c:23: warning: passing argument 1 of ‘fprintf’ makes pointer from integer without a cast tetris.c:23: warning: passing argument 1 of ‘pclose’ makes pointer from integer without a cast
lo estoy haciendo con mac no se con que ustedes y luego al ejecutar ./tetris funciona como dice el artículo
Holap:
No compila… :(
Alan, puedes revisar el código, porfa? Estoy ansioso por conocer el resultado… xD
Saludooos :P
Pues sí compila como dice Xampa, pero yo ni le he puesto los includes, simplemente gcc -o tetris tetris.c Y si existe un fichero con nombre HI que inicialmente esté vacío va almacenando las puntuaciones manteniéndolas ordenadas de mayor a menor puntuación.
El tetris que se descarga sí que va, pero el fichero de 19 líneas no compila:
t.c:1: warning: data definition has no type or storage class t.c:1: warning: cast from pointer to integer of different size t.c:1: error: initializer element is not constant t.c:1: error: (near initialization for ‘v[0]’) t.c: In function ‘u’: t.c:6: warning: incompatible implicit declaration of built-in function ‘printf’ t.c: In function ‘main’: t.c:16: warning: incompatible implicit declaration of built-in function ‘printf’ t.c:18: warning: incompatible implicit declaration of built-in function ‘fprintf’ t.c:19: warning: passing argument 1 of ‘fprintf’ makes pointer from integer without a cast t.c:19: note: expected ‘void *’ but argument is of type ‘int’ t.c:19: warning: format ‘%s’ expects type ‘char *’, but argument 5 has type ‘int’
Los warning dan igual, pero los error va a ser que no.
repito los errores (con doble salto de linea)
t.c:1: warning: data definition has no type or storage class
t.c:1: warning: cast from pointer to integer of different size
t.c:1: error: initializer element is not constant
t.c:1: error: (near initialization for ‘v[0]’)
t.c: In function ‘u’:
t.c:6: warning: incompatible implicit declaration of built-in function ‘printf’
t.c: In function ‘main’:
t.c:16: warning: incompatible implicit declaration of built-in function ‘printf’
t.c:18: warning: incompatible implicit declaration of built-in function ‘fprintf’
t.c:19: warning: passing argument 1 of ‘fprintf’ makes pointer from integer without a cast
t.c:19: note: expected ‘void *’ but argument is of type ‘int’
t.c:19: warning: format ‘%s’ expects type ‘char *’, but argument 5 has type ‘int’
genial, vamos a probarlo…..
El programa compila tal cual. Digamos que guardan el código en un archivo
minitetris.c. Yo compilaría con GCC así:gcc -o mt minitetris.cOlviden los mensajes. Sólo son warnings. Noten que ahora tienen un ejecutable en el directorio de compilación.
Ahora ejecuto
./mtY listo. Cuando salgan del juego verán que bash no regresa. No pasa nada grave. Sólo cierren la terminal y listo.
Disculpen la demora de mi respuesta, estuve desconectado del mundo por 24 hrs. y no estuve enterado de la positiva respuesta que tuvo este artículo. ¡Gracias! Estoy entusiasmado por escribir más sobre código ofuscado.