Wormloop Applet

For scripts to aid with computation or simulation in cellular automata.
Post Reply
pi_guy314
Posts: 88
Joined: July 21st, 2014, 9:45 pm

Wormloop Applet

Post by pi_guy314 » July 14th, 2016, 12:34 am

I wrote a python applet of the worm-loop rule. The reason why I did so was because I had a hard time fixing the mutation rate so that worms had an equal chance of becoming bigger or smaller. I wanted to see the actual outcome of the rule and know whether or not worms will truly become more complex overtime.

The performance on this applet is still a bit slow. It's because of the collision detection which takes up about 90% of the overall execution time.

Link to the repository: https://github.com/ThatSoundsFun/WormLoop/releases

Link to the CA rule (still buggy): viewtopic.php?f=11&t=2049#p30253
Last edited by pi_guy314 on July 26th, 2016, 6:21 pm, edited 2 times in total.

User avatar
Scorbie
Posts: 1692
Joined: December 7th, 2013, 1:05 am

Re: Wormloop Applet

Post by Scorbie » July 14th, 2016, 3:23 am

Hmm! I know nothing about pygame, but this tutorial says that updating only the changed parts makes it faster. Also, it may be faster if the main logic is rewritten in something like C, I think?

One of my big big big goals is to make a golly-like program, but with rules as script files (probably Lua) so that one could design the rule as they like...
Edit: with a c engine and pygame (or lua sdl) frontend.

pi_guy314
Posts: 88
Joined: July 21st, 2014, 9:45 pm

Re: Wormloop Applet

Post by pi_guy314 » July 14th, 2016, 5:07 pm

Scorbie wrote:Hmm! I know nothing about pygame, but this tutorial says that updating only the changed parts makes it faster.
I never knew updating the entire screen would slow down the applet down much, and it'll only take a few lines of codes to fix it. Thanks for the advise.
Scorbie wrote: Also, it may be faster if the main logic is rewritten in something like C, I think?
A python to c converter might be enough. I'm not sure how those work though.
Scorbie wrote:One of my big big big goals is to make a golly-like program, but with rules as script files (probably Lua) so that one could design the rule as they like...
Edit: with a c engine and pygame (or lua sdl) frontend.
That's an nice concept. It could allow for more interesting things like cells with motions, similar to the margolus neighborhood.

User avatar
Scorbie
Posts: 1692
Joined: December 7th, 2013, 1:05 am

Re: Wormloop Applet

Post by Scorbie » July 14th, 2016, 11:14 pm

pi_guy314 wrote:
I wrote:Also, it may be faster if the main logic is rewritten in something like C, I think?
A python to c converter might be enough. I'm not sure how those work though.
I think you would like Cython if you are using C inside python. (Seems like the least work to the user) Or pypy may make it fast enough without modifying the source. Still, it may be fast enough with only the pygame tweak.

Edit: Stupid me, there's also ctypes, and probably other plenty of ways to use c with python. You should probably google for more options if you are planning it seriously.
pi_guy314 wrote:That's an nice concept. It could allow for more interesting things like cells with motions, similar to the margolus neighborhood.
Yeah, I saw some rules that are pretty hard to simulate in Golly because of its nature (e.g. moving particles, collisions, neighborhood of range >2 etc.) Hence this idea. Still, considering my programming proficiency and the amout of time I could spare, I think it would be a long way to go.

pi_guy314
Posts: 88
Joined: July 21st, 2014, 9:45 pm

Re: Wormloop Applet

Post by pi_guy314 » July 16th, 2016, 10:14 pm

I updated the applet to v1.1.0. the screen will now only update the ends of each worm instead of the entire screen which helped improved performance by a lot. For some reason the link didn't show the latest version which I fixed.
Scorbie wrote:I think you would like Cython if you are using C inside python. (Seems like the least work to the user) Or pypy may make it fast enough without modifying the source. Still, it may be fast enough with only the pygame tweak.

Edit: Stupid me, there's also ctypes, and probably other plenty of ways to use c with python. You should probably google for more options if you are planning it seriously.
There still some performance issues with the applet itself whenever there's a lot of worms. I believe it's coming from checking collisions. I could try one of those methods to speed it up. I could also try dividing the screen into subsections so worms will check within their own subsections for collisions.

User avatar
Scorbie
Posts: 1692
Joined: December 7th, 2013, 1:05 am

Re: Wormloop Applet

Post by Scorbie » July 17th, 2016, 5:57 am

pi_guy314 wrote:I updated the applet to v1.1.0. the screen will now only update the ends of each worm instead of the entire screen which helped improved performance by a lot. For some reason the link didn't show the latest version which I fixed.
Good to hear that. I'll try to see that after I get more time:)

User avatar
Scorbie
Posts: 1692
Joined: December 7th, 2013, 1:05 am

Re: Wormloop Applet

Post by Scorbie » July 18th, 2016, 9:01 am

Edit: I get this error:

Code: Select all

Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Users\Scorbie\Life\WormLoop-1.1.0>main.py
Traceback (most recent call last):
  File "C:\Users\Scorbie\Life\WormLoop-1.1.0\main.py", line 22, in <module>
    Game.init_screen(width, height)
TypeError: unbound method init_screen() must be called with Game instance as first argument (got int instance instead)
Windows 10, 32bit, installed the latest pygame(1.9.1, I think.) I installed both python 2 and 3 but the error doesn't say "module pygame not found" so I am pretty sure python version issues are irrelevant.

pi_guy314
Posts: 88
Joined: July 21st, 2014, 9:45 pm

Re: Wormloop Applet

Post by pi_guy314 » July 18th, 2016, 5:07 pm

Scorbie wrote:Edit: I get this error:

Code: Select all

Error
Windows 10, 32bit, installed the latest pygame(1.9.1, I think.)
I think one possibility is that your using the wrong version of pygame. Here's the link to the latest versions of pygame:
https://bitbucket.org/pygame/pygame/downloads. (3.4 version)

Other than that, I don't know what could be causing it nor can I reproduce the error. If this error still occurs, I think it would maybe be better to move it here if possible:
https://github.com/ThatSoundsFun/WormLoop/issues

I think I should probably consider py2exe so installing the latest versions of python and pygame wouldn't be necessary.

User avatar
Scorbie
Posts: 1692
Joined: December 7th, 2013, 1:05 am

Re: Wormloop Applet

Post by Scorbie » July 20th, 2016, 11:07 am

Just installed pygame with pip as the pygame msi installer doesn't work for some reason. (I think it couldn't find python3 in my home directory.)

Edit: (offtopic) the python3 windows installer now defaults to installing only for me (@ the home directory) So I think these 3rd party python installers should do something about that...)

And wow! You have a decent app right there! I am pretty amazed that it's fast enough to watch. Nice to see the log file too.
Different colors mean different species, right?
Last edited by Scorbie on July 21st, 2016, 1:16 am, edited 1 time in total.

pi_guy314
Posts: 88
Joined: July 21st, 2014, 9:45 pm

Re: Wormloop Applet

Post by pi_guy314 » July 20th, 2016, 9:40 pm

Scorbie wrote:Just installed pygame with pip as the pygame msi installer doesn't work for some reason. (I think it couldn't find python3 in my home directory.)
I believe in order for those to work, the python directory has to be C:\Python35 for python 3.5 and etc. I'm not 100% sure on that.
Scorbie wrote:And wow! You have a decent app right there! I am pretty amazed that it's fast enough to watch. Nice to see the log file too.
Different colors mean different species, right?
Thanks, I appreciate you enjoying my applet . Yes, different colors means different species. Any additions or deletions of a turning genes will result in a different species. There's still some more features and optimizations left to be added in the future.

pi_guy314
Posts: 88
Joined: July 21st, 2014, 9:45 pm

Re: Wormloop Applet

Post by pi_guy314 » July 26th, 2016, 6:29 pm

Updated the applet to v1.2. The change-log for this version is long and is found at the repository.
The biggest change I believe is that JSON is used instead of pickling which makes sharing save files safer.

Post Reply