Jump to content

Recommended Posts

It occured to me today that I'd never coded the game of life, so for a bit of fun I threw one together today.

 

After realising how simple it was I wondered how short I could get it and eventually came up with this written in my fav FastBasic:

 

z=1000:di.s(5000):m.0,adr(s)+z+z,z:n=-z:a=z+z:do:l=0:f.i=z+z+n to2959+n:e=(s(i+1)>0)+(s(i+40)>0)+(s(i+41)>0)+(s(i+39)>0)+(s(i-1)>0)+(s(i-40)>0)+(s(i-39)>0)+(s(i-41)>0):y=((e=2ore=3)ands(i)>0)+(s(i)=0ande=3):s(i+a)=y:p.dpeek(88)+l,y:incl:n.:a=-a:n=-n:l.

 

It's not pretty, it's slow, and there's only one seed, but it works.

 

ABBUC has ended, 10 liners hasn't been announced, so I'm putting a challenge down :)  Can anyone come up with an interesting 1 liner written in BASIC (256 character max) I recommend FastBasic.

life.xex

  • Like 7

Share this post


Link to post
Share on other sites

Hi!

4 hours ago, Preppie said:

It occured to me today that I'd never coded the game of life, so for a bit of fun I threw one together today.

 

After realising how simple it was I wondered how short I could get it and eventually came up with this written in my fav FastBasic:

 

z=1000:di.s(5000):m.0,adr(s)+z+z,z:n=-z:a=z+z:do:l=0:f.i=z+z+n to2959+n:e=(s(i+1)>0)+(s(i+40)>0)+(s(i+41)>0)+(s(i+39)>0)+(s(i-1)>0)+(s(i-40)>0)+(s(i-39)>0)+(s(i-41)>0):y=((e=2ore=3)ands(i)>0)+(s(i)=0ande=3):s(i+a)=y:p.dpeek(88)+l,y:incl:n.:a=-a:n=-n:l.

 

Smalls optimizations:

- Using a byte array is faster, just add "b." after the DIM var.

- Using z=960 works, and the source is smaller.

- Instead of "s(x)>0", it is faster to do "s(x)<>0", but the source gets too big. So, you can rely on the last bit set and use "s(x)&1", this is faster and does not needs the parenthesis.

 

The program now is only 227 characters:

z=960:di.s(5*z)b.:m.0,adr(s)+z,z:n=-z:do:a=-n-n:l=0:f.i=z+z+n to3*z+n:e=s(i+1)&1+s(i+40)&1+s(i+41)&1+s(i+39)&1+s(i-1)&1+s(i-40)&1+s(i-39)&1+s(i-41)&1:y=((e=2ore=3)ands(i))+(s(i)=0ande=3):s(i+a)=y:p.dpeek(88)+l,y:incl:n.:n=-n:l.

 

Have Fun!

life.a.xex life.xex

  • Like 3

Share this post


Link to post
Share on other sites

You now have about 29 characters to enhance/embellish with :)

3% more! that's quite a bit in Atariville!

 

Edited by _The Doctor__
  • Like 1

Share this post


Link to post
Share on other sites

Cellular automaton are really fun, for example this is the code 600 rule from http://mathworld.wolfram.com/TotalisticCellularAutomaton.html , you can change the generated sequence by changing the array "R()".

 

DI.S(33)B.:DA.R()B.=0,2,0,1,1,2,0:DA.C()B.=32,111,20,32:S(15)=1:P.752,1:R.:N=0:FORI=1 TO31:Q=S(I-1):PUTC(Q):S(I-1)=N:N=R(Q+S(I)+S(I+1)):N.:?:U.KEY()

 

Attached is the XEX, press any key to exit.

 

cel-line.xex

  • Like 1

Share this post


Link to post
Share on other sites
8 hours ago, _The Doctor__ said:

You now have about 29 characters to enhance/embellish with :)

3% more! that's quite a bit in Atariville!

 

Yeah, I tried to put a basic editor in but was 9 characters too long.  I might have another shot later.

 

I did adjust it so the cells are now '0' instead of '!' and put a random seed in.  Due to emulators starting the prog immediatly, and therefore using same rand seed every time, you now have to press a key to start it.  Exactly 256 characters :)

 

z=960:di.s(5*z)b.:w.key()=0:we.:f.w=0toz:s(rand(z)+z)=1:n.:n=-z:do:a=-n-n:l=0:f.i=z+z+n to3*z+n:e=s(i+1)&1+s(i+40)&1+s(i+41)&1+s(i+39)&1+s(i-1)&1+s(i-40)&1+s(i-39)&1+s(i-41)&1:y=((e=2ore=3)ands(i))+(s(i)=0ande=3):s(i+a)=y:p.dpeek(88)+l,y*16:incl:n.:n=-n:l.

 

life1.3.xex

  • Like 2

Share this post


Link to post
Share on other sites

I found this to be fun so I wrote a 1 line snake but I'm not happy with it.

 

Is there a shorter way to read the stick than this?

 

s=stick(0):s=((s=13)-(s=14))*40+(s=7)-(s=11)

Given that I need +/-1 left&right and +/-40 up & down.

 

I have this, which is 5 characters shorter,  but it gives 8-way movement and I need 4-way

 

s=stick(0):s=(s&1-s&2/2)*40+s&4/4-s&8/8

 

I know these are just daft little things, but I've learned some nice techniques for when the 10 liners competition is announced.

  • Like 1

Share this post


Link to post
Share on other sites

ok, I give up.  Gonna post these so I can get on and do something proper.

 

First one has a wrap around screen but the left/right wrap doesn't work properly.  Neat bit in this code is that the random food drop is started by the snake eating the cursor :)

 

n=960:dimx(n):d=dpeek(88):x(0)=d:h=0:r=1:r.:s=stick(0):s=((s=13)-(s=14))*40+(s=7)-(s=11):r=s+(s=0)*r:f=x(h)+r:f=f+((f<d)-(f>d+n))*n:h=h+1-(h=n)*n:x(h)=f:y=peek(f):p.f,3:g=y:w.g:z=d+rand(n):g=peek(z):v=g=0:p.z,g+v:t=t-v:we.:p.x(t),0:t=t+1-(t=n)*n:pa.5:u.y=3

 

Second one has a border instead of a wrap screen and better graphics lol but the random food drop had to be replaced with the food being used to delete the tail, so you end up chasing your tail all the time. 

 

n=960:dimx(n):d=dpeek(88):ms.d,n,128:f.i=1to22:ms.d+i*40+9,22,0:n.:x(1)=d+90:p.d+93,80:h=1:r=1:r.:s=stick(0):s=((s=13)-(s=14))*40+(s=7)-(s=11):r=s+(s=0)*r:f=x(h)+r:h=h+1-(h=n)*n:x(h)=f:y=peek(f):p.f,84:t=t-(y>0):p.x(t),(y>0)*80:t=t+1-(t=n)*n:pa.5:u.y>80

 

I couldn't get the random food drop code in along with a proper screen wrap or a border, so neither of these is a satisfying version of snake I guess.

 

I did learn a few things, like v=g=0 is viable in FastBasic instead of v=(g=0) and also that POKE num,-1 is the same as POKE num,255 (although I ended up not using this in either version).  It does say in the manual that POKE will use the modulo 256 as the value but I wasn't sure it would work with neg numbers.

 

 

snake1.xex snake2.xex

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...