You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server

Game of Lyfe[PC][Java][Processing]

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

0
b/PC, Mac & Vintage Computers publicado por u/semiprocoder February 17, 2017, 01:55:18 AM
So I kind of lost interest in programming for a while, but I can say that, at least for now, I am back(maybe?).
Anyways, I decided to make Conway's Game of Life, but with some modifications. So I originally meant to create a two player game in which each player either would try to snuff out the other or have more of "their own" cells or something along those lines after a certain time limit. However, I have completely changed my direction(might still try making a two player game) when I started to mess around with the physics of game of life.
If you don't know how the game works, I will just quote Wikipedia, as I am bad at explaining things:
QuoteThe universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, alive or dead, or "populated" or "unpopulated" (the difference may seem minor, except when viewing it as an early model of human/urban behaviour simulation or how one views a blank space on a grid). Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:
Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
Any live cell with two or three live neighbours lives on to the next generation.
Any live cell with more than three live neighbours dies, as if by overpopulation.
Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed—births and deaths occur simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the preceding one). The rules continue to be applied repeatedly to create further generations.

So, as I said, I decided to mess around with the rules a little bit. I decided to change the amount of living cells required to create a living cell, and I decided to change the amount of cells that a living cell can live with. Then I decided to add some color. The color is added by checking how many alive cells are near the cell BEFORE reproduction. I know this is weird, as it means that it is kind of outdated, and I am not sure whether adding color after reproduction will look better, but I am lazy to do that :P.

Anyways, the two attachments show the initial configuration for a system where the a cell can spawn if there are exactly 2 living cells next to it, and a cell can die if there are less than 2 or more that 6 living cells beside it. The color scheme is inverted to what I've generally seen, with dead cells being black, but I think this looks better. The initial configuration does have red lines, which signify walls, but I disabled walls for this game, so imagine them as nonexistent.

EDIT: I think this looks cool, despite a lot of quality being lost after conversions(obs record to mp4, then to mpeg in ffmpeg, then to gif in virtualdub): http://gph.is/2kYk3k3. This was done with the same + configuration, but cells come alive if there are 2-6 adjacent cells, and, as before, they stay alive with 2-6 adjacent cells.

SECOND EDIT: Added some more pictures that I think look pretty cool.
Last Edit: February 17, 2017, 06:56:03 PM by semiprocoder
Inicia sesión o crea una cuenta para dejar un comentario
u/alexgt February 17, 2017, 01:57:16 AM
Nice work! I made a Conway game for the prime but it was slow due to a bad algorithm xD
u/semiprocoder February 17, 2017, 02:48:44 AM
@alexgt what did you do? My code is pretty slow at resolutions of 800x800 cells. I rendered the shown images at 399x399, and the framerate is probably like 10-20. Still ok, but not super smooth.
u/alexgt February 17, 2017, 04:06:45 AM
well, if I remember right, I used two matrices and had the first be the base (1st generation), and I iterated through the first matrix, checking every index with the 8 adjacent squares and determining if it should live or die and then storing that to the same index on the 2nd matrix, alive or dead (1 or 0), and then finally setting the 1st matrix equal to the 2nd, clearing the second and repeat. I haven't come up with anything as simple that works faster (I haven't given it much though tbh tho) so I think you would have to make a pretty complicated algorithm to accomplish it faster, I will give it some thought though ;). Good luck!
u/semiprocoder February 17, 2017, 04:02:24 PM
That's essentially what I do, except I also record the number alive so I can set the colors for each square. Also I record state and playerState, but that is unimportant for my current program right now; I plan to use state, although playerState is only going to be used for a two player game.

Also I have decided to export my code as a java file, attached below. Just unzip the file, and it should have a settings folder and a jar. No readme yet, cause I am lazy, but one will probably be made soon. I do have some notes in the settings.txt file though, so that should help you.

And here is the source(yeah ik I could do something with github but I havent used it for so long and I don't feel like spending time learning how it works again):
https://github.com/awesommee333/LYFE/blob/master/LYFE-SOURCE.zip

EDIT: I think I may have uploaded an outdated version that didn't work, so I just reuploaded the LYFE.zip attachment.
Last Edit: February 17, 2017, 05:31:33 PM by semiprocoder
u/Snektron February 17, 2017, 04:15:58 PM
Processing eh? You can put it online at openprocessing.org and send us the link :)
u/semiprocoder February 17, 2017, 04:39:33 PM
@Snektron Well its not so simple. I have it running in eclipse, with java classes, so I can't really port it over to javascript, especially as I don't know javascript.
u/Snektron February 17, 2017, 04:47:48 PM
Isnt processingjs the same syntax? (I haven't done processing in a while so i wouldnt know)
u/Dream of Omnimaga February 17, 2017, 05:20:28 PM
This looks fun to mess around with, judging by how cool the generated pictures look like. :)

I'm gonna download this when I'm home
u/semiprocoder February 17, 2017, 06:08:23 PM
@DJ Omnimaga Tell me what you come up with! I haven't spent much time with this myself, but I already think that I've generated some cool images, despite really just learning about conway's game of life. I am going to try a black and white walrii as the initial configuration and see what it generates.

EDIT: Nothing too cool with a walrii :(.
Last Edit: February 17, 2017, 06:19:02 PM by semiprocoder
u/Dream of Omnimaga February 18, 2017, 07:42:21 PM
Yeah my idea was to try with a Walrii but only if I could import one since it would take a while to draw while I'm busy :P. But I might try with a few of my older sprites.
u/alexgt February 21, 2017, 05:16:02 AM
Nice progress, I how the multi player turns out well ;).
Start a Discussion

b/PC, Mac & Vintage Computers

Computer programming discussion and project showcase

132
Topics
Explore Board
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal