Hello, back in 2006 I made the 2KiB roguelike, the first of the really small roguelikes. I then left the roguelike world for a few years. A few weeks ago, I was making a search for my old code, and noticed that others have taken up the challenge, and there now are a few 1KiB roguelikes, half the size of the original. Not to be out done, I then endeavoured to make another halving, and create a roguelike that was less than 512 bytes of source code.
The task took two days, just like the original 2KiB game. So I present "Monster Caves":
Decend downwards, and kill as many monsters as you can. Beware! Hitting an already dead monster causes it to arise as a nearly unkillable Lich! How many monsters can you kill before your luck runs out, or you find the mysterious moving stairwell? Note that the game doesn't have enough bytes to remember (and print out) your kill total, so you'll have to do that yourself. You can use the numeric keypad (with num-lock on) to move about. Move into a monster to attack it, and move into a stairway to decend another level. If you get stuck in a disconnected part of a level, try pressing some other keys... you may just be able to teleport out.
Here is the source code, all 493 bytes of it: #include<stdlib.h> #define F(n)for(j=0;j<n;j++) #define r rand() int main(){int x,s=46,n,i,j,z=77,l[z];char m[z*s],h[z];initscr();raw ();F(z*s)j[ m]=35;F(s)for(j[l]=i=(r%4+3)*z+(n=r%17*z+r%s+z);n<=i;n+=z)for(x=n;x<=n +j/2;m[++ x]=s);F(9)l[j][m]=z,j[h]=2;m[*l]=64;*h=5;l[j][m]=62;F(z){x=n=l[i++,i %=9];if(i)! i[h]||*l^(n+=r%3+r%3*z+~z)||--*h?0:abort();else{F(25)mvaddnstr(j,i,m +j*z,z);j=s -getch();m[n+=j/3*z-j%3+153]^62||main();F(9)l[j+1]^n||--h[j+1]||n [m]--;}n[m]^s ||(m[l[i]=n]=x[m],x[m]=s);}}
To compile the source code use gcc -O2 source.c -o monster_caves - lcurses to link with the curses library. Note that one of the tricks used to shrink the source is to not include the curses header file. The functions called in the curses library are lucky enough to have the correct signature without it.
> Hello, back in 2006 I made the 2KiB roguelike, the first of the really > small roguelikes. I then left the roguelike world for a few years. A > few weeks ago, I was making a search for my old code, and noticed that > others have taken up the challenge, and there now are a few 1KiB > roguelikes, half the size of the original. Not to be out done, I then > endeavoured to make another halving, and create a roguelike that was > less than 512 bytes of source code.
> The task took two days, just like the original 2KiB game. So I > present "Monster Caves":
> Decend downwards, and kill as many monsters as you can. Beware! > Hitting an already dead monster causes it to arise as a nearly > unkillable Lich! How many monsters can you kill before your luck runs > out, or you find the mysterious moving stairwell? Note that the game > doesn't have enough bytes to remember (and print out) your kill total, > so you'll have to do that yourself. You can use the numeric keypad > (with num-lock on) to move about. Move into a monster to attack it, > and move into a stairway to decend another level. If you get stuck in > a disconnected part of a level, try pressing some other keys... you > may just be able to teleport out.
> Here is the source code, all 493 bytes of it: > #include<stdlib.h> > #define F(n)for(j=0;j<n;j++) > #define r rand() > int main(){int x,s=46,n,i,j,z=77,l[z];char m[z*s],h[z];initscr();raw > ();F(z*s)j[ > m]=35;F(s)for(j[l]=i=(r%4+3)*z+(n=r%17*z+r%s+z);n<=i;n+=z)for(x=n;x<=n > +j/2;m[++ > x]=s);F(9)l[j][m]=z,j[h]=2;m[*l]=64;*h=5;l[j][m]=62;F(z){x=n=l[i++,i > %=9];if(i)! > i[h]||*l^(n+=r%3+r%3*z+~z)||--*h?0:abort();else{F(25)mvaddnstr(j,i,m > +j*z,z);j=s > -getch();m[n+=j/3*z-j%3+153]^62||main();F(9)l[j+1]^n||--h[j+1]||n > [m]--;}n[m]^s > ||(m[l[i]=n]=x[m],x[m]=s);}}
> To compile the source code use gcc -O2 source.c -o monster_caves - > lcurses to link with the curses library. Note that one of the tricks > used to shrink the source is to not include the curses header file. > The functions called in the curses library are lucky enough to have > the correct signature without it.
> Hello, back in 2006 I made the 2KiB roguelike, the first of the really > small roguelikes. I then left the roguelike world for a few years. A > few weeks ago, I was making a search for my old code, and noticed that > others have taken up the challenge, and there now are a few 1KiB > roguelikes, half the size of the original. Not to be out done, I then > endeavoured to make another halving, and create a roguelike that was > less than 512 bytes of source code.
> The task took two days, just like the original 2KiB game. So I > present "Monster Caves":
> Decend downwards, and kill as many monsters as you can. Beware! > Hitting an already dead monster causes it to arise as a nearly > unkillable Lich! How many monsters can you kill before your luck runs > out, or you find the mysterious moving stairwell? Note that the game > doesn't have enough bytes to remember (and print out) your kill total, > so you'll have to do that yourself. You can use the numeric keypad > (with num-lock on) to move about. Move into a monster to attack it, > and move into a stairway to decend another level. If you get stuck in > a disconnected part of a level, try pressing some other keys... you > may just be able to teleport out.
> Here is the source code, all 493 bytes of it: > #include<stdlib.h> > #define F(n)for(j=0;j<n;j++) > #define r rand() > int main(){int x,s=46,n,i,j,z=77,l[z];char m[z*s],h[z];initscr();raw > ();F(z*s)j[ > m]=35;F(s)for(j[l]=i=(r%4+3)*z+(n=r%17*z+r%s+z);n<=i;n+=z)for(x=n;x<=n > +j/2;m[++ > x]=s);F(9)l[j][m]=z,j[h]=2;m[*l]=64;*h=5;l[j][m]=62;F(z){x=n=l[i++,i > %=9];if(i)! > i[h]||*l^(n+=r%3+r%3*z+~z)||--*h?0:abort();else{F(25)mvaddnstr(j,i,m > +j*z,z);j=s > -getch();m[n+=j/3*z-j%3+153]^62||main();F(9)l[j+1]^n||--h[j+1]||n > [m]--;}n[m]^s > ||(m[l[i]=n]=x[m],x[m]=s);}}
> To compile the source code use gcc -O2 source.c -o monster_caves - > lcurses to link with the curses library. Note that one of the tricks > used to shrink the source is to not include the curses header file. > The functions called in the curses library are lucky enough to have > the correct signature without it.
I like it better as well. However, if you try to shrink it to half of its size you'll find that the feature list probably needs to shrink also. With a limit of 1kib you can create a compact virtual machine, and then write the game itself in some sort of size-optimized byte- code. The byte-code lets you add heaps of features for very little size cost. That was my original plan for this... however, if you add up the overhead for the virtual machine implementation, there wasn't quite enough room at 512 bytes to include it and actually have a working game.
> On Sep 21, 12:28 pm, sfuerst <svfue...@gmail.com> wrote:
> > Hello, back in 2006 I made the 2KiB roguelike, the first of the really > > small roguelikes. I then left the roguelike world for a few years. A > > few weeks ago, I was making a search for my old code, and noticed that > > others have taken up the challenge, and there now are a few 1KiB > > roguelikes, half the size of the original. Not to be out done, I then > > endeavoured to make another halving, and create a roguelike that was > > less than 512 bytes of source code.
> > The task took two days, just like the original 2KiB game. So I > > present "Monster Caves":
> > Decend downwards, and kill as many monsters as you can. Beware! > > Hitting an already dead monster causes it to arise as a nearly > > unkillable Lich! How many monsters can you kill before your luck runs > > out, or you find the mysterious moving stairwell? Note that the game > > doesn't have enough bytes to remember (and print out) your kill total, > > so you'll have to do that yourself. You can use the numeric keypad > > (with num-lock on) to move about. Move into a monster to attack it, > > and move into a stairway to decend another level. If you get stuck in > > a disconnected part of a level, try pressing some other keys... you > > may just be able to teleport out.
> > Here is the source code, all 493 bytes of it: > > #include<stdlib.h> > > #define F(n)for(j=0;j<n;j++) > > #define r rand() > > int main(){int x,s=46,n,i,j,z=77,l[z];char m[z*s],h[z];initscr();raw > > ();F(z*s)j[ > > m]=35;F(s)for(j[l]=i=(r%4+3)*z+(n=r%17*z+r%s+z);n<=i;n+=z)for(x=n;x<=n > > +j/2;m[++ > > x]=s);F(9)l[j][m]=z,j[h]=2;m[*l]=64;*h=5;l[j][m]=62;F(z){x=n=l[i++,i > > %=9];if(i)! > > i[h]||*l^(n+=r%3+r%3*z+~z)||--*h?0:abort();else{F(25)mvaddnstr(j,i,m > > +j*z,z);j=s > > -getch();m[n+=j/3*z-j%3+153]^62||main();F(9)l[j+1]^n||--h[j+1]||n > > [m]--;}n[m]^s > > ||(m[l[i]=n]=x[m],x[m]=s);}}
> > To compile the source code use gcc -O2 source.c -o monster_caves - > > lcurses to link with the curses library. Note that one of the tricks > > used to shrink the source is to not include the curses header file. > > The functions called in the curses library are lucky enough to have > > the correct signature without it.
> seeing this is hosted on a commercial site, > how much would one have to pay to have the last Zangband cleaned up > and released ?
> T,
Fortunately for the world, Angband and its variants are under a non- commercial license. This means that no one can ever charge money for them. Unfortunately, that means that if you want your Zangband fix, you'll need to look at playing with the fork until I get more hobby time. :-(
On Sep 21, 12:28 pm, sfuerst <svfue...@gmail.com> wrote:
> To compile the source code use gcc -O2 source.c -o monster_caves - > lcurses to link with the curses library. Note that one of the tricks > used to shrink the source is to not include the curses header file. > The functions called in the curses library are lucky enough to have > the correct signature without it.
Could you explain how this works? Does #include<stdlib.h> somehow include the function prototypes for initscr(), raw(), mvaddnstr() and getch()?
Also: you recursively call main()? Whoa, I didn't even know that was possible. If you play the game long enough won't you end up with a stack overflow?
(Obviously this could be abused to write a deceptively small program. GCC rejected my attempt at a one-character roguelike (the one character was of course '@', which was to be redefined with -D) for being too short, but it will compile the complete program "int main() {}", which is only 12 characters long.)
I guess this raises an important issue with ultra-small coding challenges: What are you allowed to #include, and what command-line statements are allowed during the build process?
Fantastic job! I might try to do this.. I tried to write a small roguelike by line count, but it seemed to always require over 25 lines unless I was putting lines ontop of each other. But if you go by the bytes of the source, that seems like a much more reasonable metric than line number. Great job!
> On Sep 21, 2:21 pm, konijn_ <kon...@gmail.com> wrote:
> > On Sep 21, 12:28 pm, sfuerst <svfue...@gmail.com> wrote:
> > > Hello, back in 2006 I made the 2KiB roguelike, the first of the really > > > small roguelikes. I then left the roguelike world for a few years. A > > > few weeks ago, I was making a search for my old code, and noticed that > > > others have taken up the challenge, and there now are a few 1KiB > > > roguelikes, half the size of the original. Not to be out done, I then > > > endeavoured to make another halving, and create a roguelike that was > > > less than 512 bytes of source code.
> > > The task took two days, just like the original 2KiB game. So I > > > present "Monster Caves":
> > > Decend downwards, and kill as many monsters as you can. Beware! > > > Hitting an already dead monster causes it to arise as a nearly > > > unkillable Lich! How many monsters can you kill before your luck runs > > > out, or you find the mysterious moving stairwell? Note that the game > > > doesn't have enough bytes to remember (and print out) your kill total, > > > so you'll have to do that yourself. You can use the numeric keypad > > > (with num-lock on) to move about. Move into a monster to attack it, > > > and move into a stairway to decend another level. If you get stuck in > > > a disconnected part of a level, try pressing some other keys... you > > > may just be able to teleport out.
> > > To compile the source code use gcc -O2 source.c -o monster_caves - > > > lcurses to link with the curses library. Note that one of the tricks > > > used to shrink the source is to not include the curses header file. > > > The functions called in the curses library are lucky enough to have > > > the correct signature without it.
> > seeing this is hosted on a commercial site, > > how much would one have to pay to have the last Zangband cleaned up > > and released ?
> > T,
> Fortunately for the world, Angband and its variants are under a non- > commercial license. This means that no one can ever charge money for > them. Unfortunately, that means that if you want your Zangband fix, > you'll need to look at playing with the fork until I get more hobby > time. :-(
You may have missed this during your absence but Angband has successfully relicensed to the GPL. Some other variants are attempting to do so as well.
>On Sep 23, 2:40=A0am, sfuerst <svfue...@gmail.com> wrote: >>On Sep 21, 2:21=A0pm, konijn_ <kon...@gmail.com> wrote: >>>seeing this is hosted on a commercial site, >>>how much would one have to pay to have the last Zangband cleaned up >>>and released ? >>Fortunately for the world, Angband and its variants are under a non- >>commercial license. =A0 This means that no one can ever charge money for >>them. >You may have missed this during your absence but Angband has >successfully relicensed to the GPL.
In any case even the old Angband license would not prevent you from hiring a contractor to work on the source. -- David Damerell <damer...@chiark.greenend.org.uk> Distortion Field! Yesterday was Thursday, September. Today is Friday, September. Tomorrow will be Saturday, September - a weekend.
> >On Sep 23, 2:40=A0am, sfuerst <svfue...@gmail.com> wrote: > >>On Sep 21, 2:21=A0pm, konijn_ <kon...@gmail.com> wrote: > >>>seeing this is hosted on a commercial site, > >>>how much would one have to pay to have the last Zangband cleaned up > >>>and released ? > >>Fortunately for the world, Angband and its variants are under a non- > >>commercial license. =A0 This means that no one can ever charge money for > >>them. > >You may have missed this during your absence but Angband has > >successfully relicensed to the GPL.
> In any case even the old Angband license would not prevent you from hiring > a contractor to work on the source.
Thanks, that was what I meant. How much would a Maecenas need to pay to get it finished ?
> -- > David Damerell <damer...@chiark.greenend.org.uk> Distortion Field! > Yesterday was Thursday, September. > Today is Friday, September. > Tomorrow will be Saturday, September - a weekend.