Hi! I want to build a program in which a class is constructed and then randomly adds, to itself, one of the various functions available in processing’s API. The result would be drawn to the screen (if in fact it calls a function that draws anything at all, and is filled with the proper variables…), and then some fitness algorithm (maybe based on pixel contrast or something) would decide if that class is mutated (by again adding a new function, or switching values in its current function, etc), or if it dies. The idea would be that, over time, /something/, however boring, would develop on screen based on the contingent mutation of the class.
So, my question- is there a way, on each draw loop, to randomly integrate a function in the Processing API into a class ? I’m very much a beginner when it comes to genetic stuff, so forgive me if I’m not using any language properly. I’m certainly not fully aware of how API’s are structured, so even some conceptual help on how to approach this would get me well on my way.
I’m surely the last person that should say this, as i planned to do the exact same thing some months ago, but i can tell you that it is quite… complicated… especially if you just started out. Though not impossible… But you would need many things.
First of all, you need to make sure that the resulting code does not cause any errors that would cause the program to freeze. This can be done by testing the result in a thread. (Though there still might be problems…)
And after that… well, start with even getting a class to run a foreign method…
On the other hand, if you don’t want something fancy, you could just create some base Methods for your class and let them be executed in a random order/manner. Thats a lot easier and shouldn’t cause too many problems.
He’s basically trying to create a Class, composed of random functions… And then execute the class inside draw with some of its methods. If then something is drawn on the canvas, the fitness function would increase and the class is better than one without a drawn output. And then the better class gets additional methods and removes the ones unused, and also changes a bit which methods are drawn. Like you would expect from a generic algorithm… at least, thats what i understood…
Exactly. I think your suggestion of just constructing some methods at first might be the best way to feel out the project. Funny that we both arrived at the same idea- I was thinking of it in terms of processing being a ‘universe’ itself, and allowing it to randomly assemble as it will, over time.
The issue of crashing and the need to test in threads is what I imagined a more complex version of this might get into…yikes.
If the fitness function is simply how many pixels are draw onto the screen I seriously doubt the end result will be interesting. Better use call to random() in a for loop to get the same result…
Yup, there are already some who try to create such self developing programs. Some time ago i came across a program that constructs a game on its own… But i don’t remember the name.
Well, that sure is better to get the same result, but the underlying program and setup is more important than the result in this case. Like an AI that recognises if a number is 0 or 1 and a handwritten program that just selects which one is written is basically the same, but the approach is different. (might not be the best example, but you get the point^^)
You might wanna take a look at this wikipedia page. It talks about the concept itself of self-modifying code. Which can then be used to make such things as self improving games/codes in general.