3 Welcome to Micro Tetris, based on an original implementation by John Tromp,
4 initiated by Freek Wiedijk. Currently maintained by Joachim Nilsson.
6 I decided to call this game Micro Tetris because it is very small and only
7 utilizes ANSI escape sequences to draw the board. Hence it is very suitable
8 for todays small embedded devices.
10 The game is available from as a Git source control archive from GitHub:
12 http://github.com/troglobit/tetris
14 See the file AUTHORS for contact information.
16 -- Joachim Nilsson <troglobit@gmail.com>
31 The following game description is from the original IOCCC entry, taken from
32 John's home page at http://homepages.cwi.nl/~tromp/tetris.html
34 An ofbuscated tetris, 1989 IOCCC Best Game
36 This program plays the familiar game of `TETRIS' with the following features:
38 * outputs vt100-like escape-sequences for:
40 o normal/reverse video
41 in curses like fashion (minimal output for screen updates)
42 * continuously increasing speed (except in pause)
43 * start speed selectable by giving n as first argument, where n is the
44 number of drops per second (default=2).
45 * controls also selectable by giving as the second argument a string
46 consisting of the following 6 charachters: left, rotate, right,drop,
47 pause, quit (default="jkl pq")
48 * the screen is blanked during the pause and the score is shown
49 * finally, the program maintains a high-score table. giving a full path
50 name for the table will result in a system-wide hiscore allowing a
51 competition between users.
53 Obfuscation has been achieved by:
55 * making effects of signals hard to trace
56 * implicit flushing by getchar()
57 * tricky cursor-parking
58 * minimizing code length
59 * hard coding include-file constants
60 * faking include-file structures
61 * throwing portability out of the window
63 For more on the 1989 IOCCC entry, see http://www.ioccc.org/1989/tromp.hint
65 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
66 =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,
67 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,
68 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,
69 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]
70 ){Q[i]=k;if(i-++I||i%12<1)printf("\033[%d;%dH",(I=i)/12,i%12*2+28);printf(
71 "\033[%dm "+(K-k?0:5),k);K=k;}Q[263]=c=getchar();}G(b){for(i=4;i--;)if(q[i?b+
72 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*
73 *V,*a;{h[3]=1000000/(l=C>1?atoi(V[1]):2);for(a=C>2?V[2]:"jkl pq";i;i--)*n++=i<
74 25||i%12<2?7:0;srand(getpid());system("stty cbreak -echo stop u");sigvec(14,v,
75 0);t();puts("\033[H\033[J");for(n=f+rand()%7*4;;g(7),u(),g(0)){if(c<0){if(G(x+
76 12))x+=12;else{g(7);++w;for(j=0;j<252;j=12*(j/12+1))for(;q[++j];)if(j%12==10){
77 for(;j%12;q[j--]=0);u();for(;--j;q[j+12]=q[j]);u();}n=f+rand()%7*4;G(x=17)||(c
78 =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
79 (++x)||--x;if(c==a[3])for(;G(x+12);++w)x+=12;if(c==a[4]||c==a[5]){s=sigblock(
80 8192);printf("\033[H\033[J\033[0m%d\n",w);if(c==a[5])break;for(j=264;j--;Q[j]=
81 0);while(getchar()-a[4]);puts("\033[H\033[J\033[7m");sigsetmask(s);}}d=popen(
82 "stty -cbreak echo stop \023;sort -mnr -o HI - HI;cat HI","w");fprintf(d,
83 "%4d from level %1d by %s\n",w,l,getlogin());pclose(d);}
85 -- John Tromp <tromp@cwi.nl>