First try for the 1KB competition

37 views
Skip to first unread message

purplearcanist

unread,
Sep 22, 2009, 11:06:46 PM9/22/09
to
import java.io.*;import java.util.*;class hello{String
i;BufferedReader I = new BufferedReader(new InputStreamReader
(System.in));Random r = new Random();int X=0,Y=0;hello(){try{Byte[] x
= new Byte[24*78];byte[] y = new byte[24*78];r.nextBytes(y);do {for
(int z=0; z<24; z++) {System.out.println();for(int Z=0; Z<78; Z++){x
[z*Z]=new Byte(y[z*Z]);System.out.print((X==Z)&&(Y==z)?'@':x
[z*Z].intValue()%2==1?'#':' ');}}i=I.readLine();X+=a("a")?-1:a("d")?
1:0;Y+=a("w")?-1:a("s")?1:0;}while(!a("q"));}catch(IOException e){}}
public boolean a(String v){return i.equals(v);}public int b(Byte n)
{return n.intValue();}public static void main(){hello h = new hello
();}}

Move using wasd, and press enter, quit using q, and press enter. All
you can do is move through the clouds that are randomly generated. It
will play on the terminal.

I chose to see if I could try doing a rougelike with just core input,
random java libraries, but all you can do now is move through the
clouds, represented by #. The final file came out at 657 bytes. Can
someone tell me what other features it needs to have, as I am new to
the competition.

Gelatinous Mutant Coconut

unread,
Sep 23, 2009, 1:06:19 AM9/23/09
to
I was also inspired to try my hand at a tiny RL. We might as well keep
all of these in one thread, eh? :) Mine's not a full game yet anyways.

Here's the code so far, coming out to 365 characters. (382 counting
the terminal command to compile it.) Paste it into "rl.c" and compile
with "gcc rl.c -lcurses".
//
#define R ((r=69069*r+1234567)<0?~r:r)
#define L i=a+1;while(--i)
#define _ m[i]
int main(){initscr();raw();int r=380116160,w=80,h=22,a=w*h,m
[a],u=99,c=7,i;do{i=49-c?50-c?51-c?52-c?54-c?55-c?56-c?57-c?u:u-w-1:u-
w:u-w+1:u-1:u+1:u+w-1:u+w:u+w+1;u=_-35?i:u;L{_=i-u?i>w&&i<a-w&&i%w&&
(i-1)%w?46:35:64;}L{i%w?addch(_):mvaddch(i/w,0,_);};}while((c=getch
())-27);endwin();}
//

It's pretty simple at this point: You're an @ in an empty rectangular
room surrounded by walls on all sides, and can move around by pressing
1 2 3 4 6 7 8 or 9, until you get bored. Press escape to quit.

I'm really pleased with the R macro, the random number generator.
(Despite the fact that I don't use it yet!) It's stolen from the
Congruential Generator documented in (http://www.bobwheeler.com/
statistics/Password/MarsagliaPost.txt), but instead of using an
unsigned long (too many characters) I use a regular int and twiddle
bits to make the macro always evaluate positive. Even when I do use it
it costs me more characters than if i had just gotten rand() from
#include <stdlib.h>, but I like it anyways.

Slash

unread,
Sep 24, 2009, 8:05:54 AM9/24/09
to
On Sep 23, 12:06 am, Gelatinous Mutant Coconut

Is this an official <1KBRL Challenge?

--
Slashie

Gelatinous Mutant Coconut

unread,
Sep 24, 2009, 2:28:18 PM9/24/09
to
On Sep 24, 8:05 am, Slash <java.ko...@gmail.com> wrote:
> Is this an official <1KBRL Challenge?

Heh, I don't know if anyone has made it official.

Slash

unread,
Oct 4, 2009, 11:03:59 AM10/4/09
to

Ok, first off, this doesnt work as it doesnt have a valid main
method :)

Second, I dont know how useful this is, but I couldnt help myself and
made some basic modifications, result is 619 bytes

import java.io.*;import java.util.*;class h{String i;BufferedReader I


= new BufferedReader(new InputStreamReader(System.in));Random r=new

Random();int X=0,Y=0;{try{Byte[] x=new Byte[24*78];byte[] y=new byte


[24*78];r.nextBytes(y);do{for (int z=0;z<24;z++) {System.out.println

();for (int Z=0;Z<78;Z++){x[z*Z] = new Byte(y[z*Z]);System.out.print


((X==Z)&&(Y==z)?'@':x[z*Z].intValue()%2==1?'#':' ');}}i=I.readLine();X

+=a("a")?-1:a("d")?1:0;Y+=a("w")?-1:a("s")?1:0;}while(!a("q"));}catch
(IOException e){}}boolean a(String v){return i.equals(v);}int b(Byte n)
{return n.intValue();}public static void main(String[]s){new h();}}

--
Slashie

purplearcanist

unread,
Oct 5, 2009, 11:47:56 PM10/5/09
to

Thanks Slashie. I like some of the changes you made, and saw the
things that were unnecessary.

I think I am going to get started with roguelike programming. I have
tons of ideas, some that may even spawn a new 7DRL.
Anyways, I will try to program something in java, with short code, but
enemies ;).

Reply all
Reply to author
Forward
0 new messages