# Idle of life - idle game based on Conway's Game of Life

Hello, I am new here. I have a few ideas for the game and I would like to start working on some of them. This is my first game project ever. I am a .net developer. But I have always been interested in making games. So why don’t try it?

I was looking for some engines to use for my ideas. And Defold feels right. The community around and feel of the engine is simple yet powerful.

So that’s was my thoughts now, about the game engine and a little about myself.

I really like Conway’s Game of Life so I wanted to recreate it in some nice funny way. The game will not be a classical idle game. Your way of playing can very change how you are making money. The basics will be your board. On board you can add cells. Cells have simple rules “Game of life”.

Rules are:

1. Any live cell with fewer than two live neighbors dies, as if by underpopulation.
2. Any live cell with two or three live neighbors lives on to the next generation.
3. Any live cell with more than three live neighbors dies, as if by overpopulation.
4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

A game tick will be every second. On tick, there will be a count of every living cell, and then dying and born new cells according to rules. 1 living cell counted will generate 1 LC of money (LC LifeCoin).

So you start with an empty board. How to generate money? It’s easy, create your own life.
For example:

1. Player starts with board 16x16 and editor 3x3
2. In the editor you can prepare your pattern to spawn
2.1. One cell for spawn cost 1 LC
3. On board you can insert your pattern
4. The patter will live by rules and generate money (If your cells don’t all die)
5. If you create a moving pattern. Every cell that leaves board will generate 2x more money

1. Increase board size
2. Increase editor site
3. Increase money generated from 1 cell
4. Buy prepared Cell pattern (for example “Glider”)

So that’s the basic idea about the game I wanna create. I am open to your interesting ideas if you have some. But please take into consideration that this will be my weekend project.

BTW Sorry for my bad English.

7 Likes

Welcome!

(me too!)

Sounds fun! I look forward to seeing what you will create.

1 Like

Wow expanded CGoL shader looks amazing I plan only basic black and white

2 Likes

Hello,
I started making progress yaay. And also, few decisions.

1. The game main platform will be mobile phones, like most idle games
2. I installed a few extensions
2.1. Monarch - for navigation and pages
2.2. Gooey - for GUI
2.3. Orthographic camera - in-game cam, will be needed for better movement on bigger boards
2.4. Defold-Input - For better handling of player interactions

What is done:

2. Game window - ugly
3. Board 16x16 cells
3.1. It is tile map-based, but I found that I cannot expand tilemap so idk how to do it yet.
4. GoL logic - I hope is right
5. Counting alive cells before creating next generation
6. For test random spawn cells

This is in game

After a while randomly generated cells often ends in stable patterns (in this case after 500 generations), you can see also money on top of screen

What I will do next:

1. player moving with cam (zoom, drag x, drag y)
2. Spawn patterns on board
3. Some storage for created patterns and predefined patterns for buy
4. Editor for patterns

So that’s it, I hope you have a great day.
Thanks for your attention. Again if you have some idea or issue, I am open to everything.
Have a nice day!

6 Likes

Hello,
I hope you all are alright.
I am a little bit stuck
So I am working on a system of upgrading the board. So I wonder how to make it bigger because tilemap size is static.

Few ideas:

1. I wanted, when the player buys upgrade add 1 so from 3x3 board will be 4x4 etc.
• This is probably something I can’t do because tilemaps are static. And I can’t spawn for example 128x128 or more game objects, because of performance
2. So the second idea was board will be from 3x3 tilemaps, that will be spawn like game objects, it reduces the number of spawned game objects and is giving the user a little bit freehand, because he can create a board of different sizes
• But this idea has another flaw, the code for handling Game of Life on some pattern for example board shape of L I don’t know how to render and navigate in a pattern of L
3. Use of @britzl infinite_map as a hack. And use something like the background color of tiles that will not be available, because the player didn’t buy them.

So I am asking for help But in my eyes, the third option for tilemap and 1. option for buying system is the best way.

Again thanks for your attention. And I am open to every help, idea, issue and I appreciate it.

1 Like

Yeah, the tilemap is currently static in size. But this is something we’ve discussed in the past.

What would it mean if we added a `tilemap.set_bounds(tilemap_url, x, y, w, h)`? We might run out of tiles (because you define max tile count in game.project). How should we handle this? Error?

I created a ticket to discuss this: https://github.com/defold/defold/issues/6328

I agree. The third solution with multiple spawned tilemap chunks (used for the infinite map you mentioned) is a nice solution.

Hello everyone,
so I am slowly progressing. It is a lot of fun, also it is totally different from .net and things I do at work. So let’s look at some new stuff, I have again a lot of things to say.

## NEWS

If a player has enough money, the system allows him to buy one row and one column of space. The price is rising at every level.

### 2. Pattern shop

Thanks to GUI library Gooey, I started working on a pattern shop. It’s simple. I have a module with some storage of patterns. So players don’t need to create their own patterns but can buy them. For now, it’s only a list with pattern name and preview, preview is generated with the Draw Pixels library.

## TODO NEXT

So now I would like to finish pattern shop, also with the functionality of clicking on the pattern and then placing the pattern on board by dragging.

### Open source vs Ads monetization

So I was thinking about making the game open source. But then I thought what if in the future I wanna use for example AdMob and be able to make money. Is it possible? Also what about some fairness with contributors? For example half money for me, half split between others, or how is this working in other projects?

Again thanks for your attention. And I am open to every help, idea, issue and I appreciate it from all of you.

6 Likes

Wow, I’m impressed by the progress you’ve made. Well done!

The two are not mutually exclusive by no means. You can monetize an open source game, but there is also nothing stopping anyone else from doing the same thing. If you do decide to monetize your open source game then I’d suggest that you are very open with where the money is going. As the creator and maintainer you probably have operational costs to cover. If the game ends up earning a lot of money you can decide to share the money with other regular contributors. But it is a luxury problem that I honestly don’t think you need to worry abut this early.

1 Like

Hi, thank you for your response. My main concern is when I make the game open source now, wouldn’t that be a problem in the future with adding ads. Also, there are other problems. Like copying my game and releasing the same because someone can, fairness of money, etc.

But for example money, there is not some solution for some fairness in the open-source world. It’s mostly based on free will to contribute. I think this is theme for another post

Hello there,
The next little update is here.

### PATTERN SHOP

So I was working on a pattern shop, how to provide players with buying new cells. So I made a new tilemap layer like “preview”. Where I am rendering a selected pattern that users wanna buy. So in the next video, you can see, how the shop is working, also placing patterns.

### PERFORMANCE

Also, I was trying to optimize a little bit GoL algorithm. Because It was really laggy also processed all cells on board, dead or alive, one by one, on bigger boards, it counts for 4 seconds. So I tried to remake it into processing only alive cells and counting dead cells for revival. So now I think it is a lot faster. But when I am placing pattern algorithm looks it slows down (you can see it in the video).

### TODO

So next I wanna add more patterns so I can really test my GoL algorithm. Then I try to make some system of making and spending money (Board upgrades, buying patterns)

Thank you much for your time and attention.
Again I appreciate every thought from you!

3 Likes

Hello, fast update about what TODO next.

So I played a little bit with the settings of the game and tried how big the board can be and how many cells I can have. I have found terrible, terrible performance. So I decided, first of all, I wanna learn something about Lua performance best practices and how to squeeze every bit of performance from Lua and my algorithm.

### Test

Easy test, simulating spawn of 250 000 cells on 1 000 x 1 000 board. The project was run by “ctrl+b”. I am sure you wonder how my game is running now this test.
I was forced to print info about every cell processed because the game froze for a long time.

START - 20:06:44
1000 - 20::07:32
2500 - 20: 08:34
5000 - 20:10:33

Then I let it run for a while.

I ended up waiting at 16118 cells at time 20:20:00

So next few posts here will be about analyzing the code and performance improvements that I made. Also about articles and materials that I found online (also with references)

Thank you much for your time and attention.
Again I appreciate every thought from you!

1 Like

My question is how you are working with your board of cells? Are you using a Lua table as the data source or do you use tilemap.get_tile() to check the state of cells?

It will be much more efficient to represent the board as a Lua table and only update the tilemap cells that have changed between two ticks in your simulation.

Thank you for your response. So I have a Lua table of cells alive, every cell is a table with only x,y of their position.
This is how I add cells to next gen.

``````table.insert(next_gen_grid, {x = v.x, y = v.y})
``````

And yes I am using for pairs(table) and table.insert. For me, it is better. It is closer to LINQ from C#.

Then I have a separate piece of code. Where I am calculating actual cells to display on tilemap. Similar to your infinite map example.

Ok, that’s a good start then! Iterating over a large amount of cells 10k or more will mean that there is some performance to gain from really optimising the code in the loop. There may even be fractions of a millisecond to save by caching functions:

``````-- cache the insert function in a local variable to avoid constant table lookups for the function
local insert = table.insert

for _,cell in pairs(all_cells) do
if foo then
insert(next_gen_grid, {x = v.x, y = v.y})
end
end
``````

But what is more costly is the creation of tables, such as this one:

``````{x = v.x, y = v.y}
``````

Is there some way that you can reuse these tables and not create new ones each time?

`v.x` and `v.y` are those from a vmath.vector3()? Creating a lot of vector3’s each frame also has a cost.

Is there some way that you can reuse these tables and not create new ones each time?

`v.x` and `v.y` are those from a vmath.vector3()? Creating a lot of vector3’s every frame also has a cost.

Actualy it is not vmath.vector3 object. It is like this for example:

``````for k, v in pairs(dead_for_revive) do
if v.count == 3 and 1 <= v.x and v.x <= self.cells.width and 1 <= v.y and v.y <= self.cells.height then
table.insert(next_gen_grid, {x = v.x, y = v.y})
end
end
``````

Ahaaa it is an object of the cell, that I create again from table to table. OMG now I see it

Also, can I ask you is there something in Lua like Stopwatch in .net? I found os.clock() but I don’t know if it is an accurate time. Like in Stopwatch I normally do Start and Stop and then read of milliseconds.

Edit: Probably solution

``````for k, v in pairs(dead_for_revive) do
if v.count == 3 and 1 <= v.x and v.x <= self.cells.width and 1 <= v.y and v.y <= self.cells.height then
table.insert(next_gen_grid, v)
end
end
``````

If you can find a way to reuse those tables somehow you’d get a decent speed-up for sure!

The best precision timer you have access to is socket.gettime(). You can create your own stopwatch/timer module:

``````-- stopwatch.lua
local M = {}

local scopes = {}

local gettime = socket.gettime

function M.start(scope)
scopes[scope] = gettime()
end

function M.stop(scope)
if not scopes[scope] then return 0 end
local time = scopes[scope]
scopes[scope] = nil
return gettime() - time
end

return M
``````

Use it:

``````-- some.script

local stopwatch = require("stopwatch")

local function do_stuff()
stopwatch.start("dostuff")
for i=1,123456 do
-- do stuff
end
print(stopwatch.stop("dostuff"))
end
``````

Wow, amazing. Did you have the code somewhere prepared? Or did you write it right now? Because that’s genial

I will try it! Right now.

1 Like

It is working, so it is basicaly, 0.16 seconds, 0.13 etc…

Excellent! This should help you to pinpoint where you are spending most of your time. There’s also a Lua profiler that you can use to get line by line measurements (https://gist.github.com/perky/2838755). Note: it will slow down all code execution by quite a bit, but the overall measurements are still accurate.

1 Like

I will look into it.

So I posted before, was a little bit wrong. 0.13 seconds after detaching debugger. When I run just build it looks like this:

With my failure with recreating every cell table
And like this:

After @britzl excellent idea with recycling cells.
It is 0.01 sec faster. That’s great in this amount of cells . In total it means 2 500 seconds less to process 250 000 cells.

Next tunning coming

1 Like