Page 1 of 1
Game of Love
Posted: Mon Jan 02, 2017 4:05 am
by joqmos
Hi!
I've been working on an implementation of Conway's Game of Life with
rjcobourn over the past few days. You can find the source code
here and the latest release
here.
Any feedback is appreciated :)
Re: Game of Love
Posted: Mon Jan 02, 2017 5:01 pm
by MasterGeek
The way you update the grid to the next state is allocating tables all over the place, even when LuaJIT does a great job optimizing the code is not good to have table allocation inside tight or recurrent loops. I mean specifically this line:
https://github.com/joqmos/game-of-love/ ... te.lua#L53
You could instead have two tables, one being the actual state and the other being the next one and you could keep alternating them so you generate one based on the other and viceversa.
Happy New Year btw.
Re: Game of Love
Posted: Mon Jan 02, 2017 6:17 pm
by joqmos
MasterGeek wrote:The way you update the grid to the next state is allocating tables all over the place, even when LuaJIT does a great job optimizing the code is not good to have table allocation inside tight or recurrent loops. I mean specifically this line:
https://github.com/joqmos/game-of-love/ ... te.lua#L53
You could instead have two tables, one being the actual state and the other being the next one and you could keep alternating them so you generate one based on the other and viceversa.
Happy New Year btw.
Yeah, I suppose it would be faster if only two tables are used. I'm going to try to implement it that way.
Thanks for the help, have a happy New Year too!
Re: Game of Love
Posted: Tue Jan 03, 2017 4:31 pm
by joqmos
I've released version 0.2, you can find it
here.
The algorithm has been optimized, and you can now adjust the speed of the game.