Because I just got one-upped. I thought writing a game in one page of source was good, but the last time I tried to write an RPG in one page of source, I concluded that it probably wasn’t possible.

But now the Temple of the Roguelike is having an ongoing competition for people to write Roguelikes in one kilobyte of source; that’s less than one-fourth the size of a one-page game. Most of the entries so far have been pretty simplistic, but now a true challenger has emerged, called A Journey to Hell.

Here’s the complete source code (compiled on Linux using GCC and curses):


#include <curses.h>
#define W(c)while(c)
#define F(v,h)for(v=0;v<h;v++)
#define D(i)F(y,S)F(x,T){i;}
#define G d[x][y]
#define M d[x+f][y+g]
#define Z(n)n<0?-1:(n>0?1:0)
#define r rand()
int x,y,S=24,T=60,c,d[90][90],L=1,b,k[]=L"$`*$.@?$?>",f,g,z,h,i,l=9,p=20,e=46,
v,u=96;m(f,g){G-64?M-64||(l-=G-u)>0||(M=e):(M^62||L++&&(L^7?N():(G=e)),M^u||(p
+=L,M=e),M^42||(l=p,M=e),M^36||(v+=x%9*L+L,M=e),M^63||(M=r%6?k[r&1]:97+L),M>u&
&--M);M-e?M-35||(g&&m(f,0),f&&m(0,g)):(M=G|256,G=e);}E(t){W(d[x=r%T][y=r%S]-e)
;G=t;}N(){D(G=35)x=y=9;F(b,S){f=r%58+1;g=r%22+1;W(f^x||g^y){G=e,r&1?(x+=Z(f-x)
):(y+=Z(g-y));}}F(b,10)E(k[b]);F(b,L*2)E(98+r%L);}main(){srand(initscr());
raw();start_color();F(c,8)init_pair(c,c,0);N();W(c-81){D(G-64||(f=x,g=y))
clear();D(b=1;W(G^k[b]&&b<7)b++;h=x;i=y;c=0;W(c++<u)(d[f+(z=(h-f)*c*.01)][g+(z
=(i-g)*c*.01)]-35)||(b=0);b&&mvaddch(y,x,G|COLOR_PAIR(b)))mvprintw(S,0,"HP:%d/
%d L:%d $%d %s",l,p,L,v,L^7?"":"WIN");c=getch();D(G>u&&G<123&&m(Z(f-x),Z(g-y))
)D(c<49||c>57||G-64||m((c-1)%3-1,1-(c-49)/3))D(G&=255)}endwin();}

Here’s a screenshot.

In this screenshot, the purple ‘@’ is the player (of course). The yellow ‘$’ represents money on the ground. The blue-green ‘?’ represents a chest. The white ‘b’ is a monster; the letter of the monster represents how hard it is to kill, from a (weakest) to z (flee in terror). The red quote mark represents a soul left behind by a monster I just killed; picking this up raises my maximum hit points.

Here’s what that 1K of source gets you:

* Guaranteed traversable levels
* Line-of-sight on the player
* Colored graphics
* Combat with monsters
* Ability to pick up gold and souls (dropped by defeated monsters; powers player up)
* Chests (which can contain gold, a monster or a soul)
* Ability to go down the stairs (generates a new level with tougher monsters)
* Win condition (beat the seventh level to win the game)

Of course his platform gives him a couple of advantages. My library to write colored graphics to the screen and poll the keyboard and mouse under Windows takes up almost 1K of code by itself; the curses library is much more space efficient. Also, GCC supports “default int” on both functions and parameters, meaning that Jakub can declare a function as “m(f,g)” and GCC will assume that ‘m’ is a function that takes two integer parameters, f and g, and returns an int itself. Visual C++ 2005 will not allow such shenanigans (though 2003 was not as strict).

Still, it’s an incredible amount of stuff for less code than it takes to initialize DirectX. I can only imagine what the author, Jakub Wasilewski, could do with the unending expanse a full page of source would provide him.