Author Topic: ThePenguin77's Game of Life  (Read 9077 times)

0 Members and 1 Guest are viewing this topic.

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
ThePenguin77's Game of Life
« on: May 04, 2011, 10:51:30 pm »
Every thread needs a creative title.

Lately, between track and homework for the AP tests, I have had almost no time to program. So I decided to start programming during school in Mimas. I decided to do Conway's Game of Life because I saw the demo for the Prizm and it looked like it would be fun to use. So I've been working on this during school for about two weeks now and finally today, it actually worked. Although, I probably would have finished this way sooner if I could have used a debugger. It's pretty frustrating to just make changes and hope the program doesn't crash.

If you don't know what Conway's game of life is, here is the general idea: Every pixel is a cell acting independently, whether the cell lives or dies is decided by a set of rules:
1. If three of the eight cells surrounding a dead cell are living, it is born
2. If there are 0 or 1 cells surrounding a living cell, it dies of loneliness
3. If there are 2 or 3 cells surrounding a living cell, it lives on
4. If there are 4 or more cells surrounding a living cell, it dies of overpopulation

To make all this happen, I use most of the extra ram page (13,608 bytes) as well as about 900 bytes of hard-coded routines to do all the checks for every bit. I use the concept of active and not active cells to speed up my simulation (if none of the cells around a cell are alive, it won't do anything next round either). I also make extensive use if IX.

Some stats:
  • 160 x 160 board
  • goal 16 fps (it typically does this until about 200 active cells)


Controls:
  • 2nd - toggle pixel
  • Y= - clear board and recenter
  • Zoom - step
  • Graph - start/stop
  • Clear - quit


Here is the game, I've been using it all day, so it works. I'll get the source later, it was written in Mimas after all. And I think my favorite part of this game is that while the actual game is only 1,042 bytes, it expands to about 1,900 bytes of code and uses 14,000 bytes of ram.

Ironically, my name makes a pretty awesome design.
« Last Edit: May 04, 2011, 10:52:37 pm by thepenguin77 »
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: ThePenguin77's Game of Life
« Reply #1 on: May 04, 2011, 10:55:25 pm »
Nice, I like this game :D

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline ralphdspam

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 841
  • Rating: +38/-1
  • My name is actually Matt.
    • View Profile
Re: ThePenguin77's Game of Life
« Reply #2 on: May 04, 2011, 11:03:37 pm »
Wow!  Looks great! :)

Stop making epic programs. Give someone else a chance >:(
ld a, 0
ld a, a

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: ThePenguin77's Game of Life
« Reply #3 on: May 04, 2011, 11:36:22 pm »
That is pretty darn fast. Great work ^^
In-progress: Graviter (...)

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: ThePenguin77's Game of Life
« Reply #4 on: May 05, 2011, 02:58:07 am »
Is that at 15MHz? Also, I never understood the game of life :(

Nice job, though, using Mimas to code games looks cool, I only use it to learn.

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: ThePenguin77's Game of Life
« Reply #5 on: May 05, 2011, 08:23:24 am »
I use mimas all the time  :)
I'm not a nerd but I pretend:

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: ThePenguin77's Game of Life
« Reply #6 on: May 05, 2011, 05:16:39 pm »
That is pretty darn fast. Great work ^^

That was my primary goal in writing it. I wanted this thing to go as fast as possible. Although, I did get it down to about 4 fps with a space filler that filled the entire 160x160 with zebra stripes. It collapsed in on itself and the entire board was in chaos running at 4 fps.

Is that at 15MHz? Also, I never understood the game of life :(

Nice job, though, using Mimas to code games looks cool, I only use it to learn.

Yes, it's at 15MHz. There's no reason to use 6MHz because of my huge RAM requirements. I just added in a save state today, so now I'm up to 19KB.

I prefer not to use Mimas because I feel the small screen will end up leading me to make small games, but if you don't have time at a computer, it works great. I put out like 3kb of code in 4 hrs on chess, whereas this thing is only up to 1kb after 3 weeks.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline tr1p1ea

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 647
  • Rating: +110/-0
    • View Profile
Re: ThePenguin77's Game of Life
« Reply #7 on: May 05, 2011, 10:40:18 pm »
I am very impressed! Very small and fast and i love the idea of a larger game field!

Wondering what tricks you have used in coding, and are your rules customizable at all?
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."


Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: ThePenguin77's Game of Life
« Reply #8 on: May 05, 2011, 11:12:37 pm »
Thanks.

As for coding tricks. My buffer is laid out like this. <Active byte> <real byte> <future active byte> <future real byte> Where the active byte is just flags to tell me which pixels I need to check and the real byte is what is actually alive. The future bytes are for calculations.

When I go to calculate it, I first search the buffer for any bytes that are active, I have this loop down to 4 t-states per empty pixel, so there's some speed. Then, when it finds an byte with active pixels in it, it calls a subroutine that throws the location in IX and puts the location of a JP table in HL. (LABEL) It then works through each bit of (IX) while increasing HL by 3 each time. When it encounters an active bit, it RET's into HL which JP's it to one of my 8 bit checking routines. These routines check the necessary 8 bits around the pixel with IX and tally up the number of living cells. When they JP back to the finishing routine. They have D = bit mask as well as E = (bit * 3). The game then sees how to handle this cell, and if it deems it alive, it OR's D into (IX + 3), sets D = $80, and JP's to DE. Which of course, JP's to a routine that sets the 8 bits around the current one as active. This all returns back to LABEL where it finishes off the byte.

When that's all done, I use a stack hack to pop and push the future bytes into the current ones and zero the futures.


My rules are currently not customizable. If I can find an efficient way to make them customizable I will though.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: ThePenguin77's Game of Life
« Reply #9 on: May 05, 2011, 11:16:24 pm »
No one steal this, but I've been working on wireworld. (Read: Cellular Automata, but different) :P Axe's Arbitrary buffers are so useful! It's going to use px-test a lot :P

Nice GOL! I like the scrolling screen, but I can't use it in mine with my current method. :P

Here's an easy way to customize it, if your code is like this: Assuming your code does a sum of the pixels near it, the numbers which it checks for are variables. As in:
If Cell = Dead
If sum = a:
Birth
End
End

If Cell = Alive
If sum = b:
StayAlive
End
End

But I don't know how yours works.
« Last Edit: May 05, 2011, 11:18:37 pm by willrandship »

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: ThePenguin77's Game of Life
« Reply #10 on: May 06, 2011, 11:20:43 pm »
Wow, this looks incredible.  I think it's the best (and quickest) game of life I've seen. ;D

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: ThePenguin77's Game of Life
« Reply #11 on: May 06, 2011, 11:51:10 pm »
Willrandship, that isn't the slow part, that's actually the really easy part. :D

Here's my code: (commented for the non asm'ers.)
Code: [Select]


bitFinal: ;label
ld a, c ;variable transfer, A now equals the number of live cells around the current one
jr nz, checkDeath ;if it's living, go to checkDeath
;>>asm: most often, we will come through here with a non-living pixel
; so the fall through for jr is the fastest way to do this
cp 3 ;act like we are subtracting 3 from A
jp nz, activeRet ;if A != 3, go find the next pixel
;>>asm: most often will not be birthing a new cell, so jp is fastest
jp setIt ;go to setIt
checkDeath:
cp 2 ;act like we are subtracting 2 from A
jp c, activeRet ;if A < 2, go find the next pixel
;>>asm: this is first because most pixels that won't survive will have
; 0 or 1, not >= 4
cp 4 ;act like we are subtracting 4
jr nc, activeRet ;if A >= 4, go find the next pixel
;>>asm: 2 and 3 are more likely than 4+
setIt:
ld a, d ;if you don't know asm, stop reading
or (ix+3)
ld (ix+3), a
push hl
ld hl, activeRet
ex (sp), hl
ld d, setJPHigh
push de
ret

This is the fastest way to do these checks. There is one spot where I could shave off 10 t-states, but that would involve duplicating the setIt routine. And 10 t-states doesn't really apply here because most paths through that routine right there average to about 40 t-states, the routine that leads here takes on average 300 t-states, and the routine it runs if it is setting a live pixel is 200 t-states.

So 550 t-states is pretty good for a worst case scenario where we are making a live cell. At that worst rate, I can handle about 27,000 pixels per second.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: ThePenguin77's Game of Life
« Reply #12 on: May 07, 2011, 08:54:26 am »
Aw man wow this is cool! (Now I really want a TI-84+)

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: ThePenguin77's Game of Life
« Reply #13 on: May 07, 2011, 09:04:45 am »
I'd say buy it. The casio part of the omni community is really, really focused on Prizm. I see that you every time get disappointed because the projects here are all TI-8x/NSpire. The Prizm is coming up, but there is hardly any casio fx-xxxx development.
I'm not a nerd but I pretend:

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: ThePenguin77's Game of Life
« Reply #14 on: May 07, 2011, 09:29:53 am »
The Prizm is coming up, but there is hardly any casio fx-xxxx development.
Hey, the Prizm is technically an fx- calc too :P
It's named fx-CG10 or fx-CG20 depending on your region.