How do I create a kinda 'genetic algorithm'

Get help using Construct 2

Post » Fri Dec 02, 2016 12:51 pm

Hi guys, I saw someting very interesting on Yt and i was thinking about C2 and if it's possible to create something similar to it.

*I think it's a little hard, maybe impossible to make such an algorithm with C2, maybe just to clone the movements and to transfer them in a algorithm in C2.
I would like to try to create one, maybe just a clone of it or something similary.

** Genetic Algorithm :

1) https://www.youtube.com/watch?v=Gl3EjiVlz_4

2) https://www.youtube.com/watch?v=5lJuEW-5vr8&t=211s

I would like to make one like the first, more like a physics-based one, not like car, which looks easier.
I will post here my creations, PM me if you have any ideas for it.

Thank you


https://en.wikipedia.org/wiki/Genetic_a ... ialization
https://en.wikipedia.org/wiki/Evolved_antenna
https://www.youtube.com/watch?v=p_H2TLG1cMo
https://www.youtube.com/watch?v=euFvRfQRbLI
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Fri Dec 02, 2016 7:08 pm

Nothing is impossible. There isn't a built in way to change the collision shape at runtime though so that may be another issue to tackle. Even that isn't impossible. You could look at yann's polygon plugin or deal with a physics engine directly with JavaScript through the browser plugin. Although I admit the latter is hard to do.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Fri Dec 02, 2016 7:33 pm

If you eliminate some requirements of physics such as weight, and mass, it's not that hard to create your own version of it.
The platform behavior for example.
Start by teaching it, and yourself gravity.
Image ImageImage
B
171
S
50
G
179
Posts: 8,392
Reputation: 113,478

Post » Fri Dec 02, 2016 10:29 pm

@R0J0hound
I was thinking about Js, but unfortunately, since I'm a little young i didn't learned Java and I can't deal with it.

@newt
I tried the version with the care and 4-5 'sensors' of collisions and it worked way better thank i expected, but on the phisics one, I don't know where to start, becouse as i saw, the shapes are kinda modelling to succed jumping, so it's fishy, maybe to hard for me.
I will definitely try to make one.
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Sat Dec 03, 2016 3:53 am

The algorithm itself looks pretty simple. The hard part would be coming up with how to design the creature so it can do something interesting. One way that seems useful to me is to make one creature and make it player controlled. If you can get it to kind of do what you want you can then take that and come up with a way to automate it.

With the physics one it looks like torque is being applied at the joints. I'm guessing its properties are when to apply the torque and the amount of torque to apply. That is probably per joint.

The initial values for the properties would be some reasonable random value. Like if it takes 1 second before the ball hits the creature then for the time to apply torque a value of random(0, 2) could be reasonable.

There are probably more complex ways to model the creature. Some ideas that comes to mind could be to only start the timer when the obstacle gets close, or somehow take into account the orientation of the creature. Giving the creature some sensory cues could be useful too.

I think it basically amounts to a bunch of tinkering and creativity.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Sat Dec 03, 2016 9:30 am

A nice challenge - thank you!

this is my approach... (platformer behavior but can changed to physic behavior)
This balls try to evaluate the perfect jump strength not to collide with the wafes.
They do not calculate but set the jump strength related to their success.

(no ball interaction so far).

(each ball can have different start values)

If you 'connect' the balls you get a more komplex looking object.

Image

demo
http://www.gameus.de/c2/learnjump

source
http://www.gameus.de/c2/learnjump/lrn2jmp.capx

the math of cause can be optimized to optimize the learning graph...
with the 'perfect' math it will result in a type of swarm intelligence :)
Image Image Image
B
43
S
22
G
15
Posts: 383
Reputation: 12,262

Post » Sat Dec 03, 2016 3:07 pm

@mercuryus
Nice one, I really liked it, I've tried 2 things, one with a car (which needs more work) and one with a 'phisics-worm',
you have the projects below.
I tried to make them more inteligent but I didn't had time, the one with the car I did it very interesting, adding some points to trace the first car, and the second car would go on these points but unfortunatelly i forgot to save.... so i let it unfinished :(
PROJECTS BELOW

@R0J0hound
I don't know nothing about joints in C2 but it sounds very interesting.

https://drive.google.com/file/d/0B2orsd ... sp=sharing
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Mon Dec 05, 2016 1:57 am

I don't think any of those are an application of the genetic algorithm. Mercuryus's example tweaks the jump as it goes but it's not following the algorithm. Radulepy's are more like ai examples.

I tried my hand at the algorithm and came up with this:
https://dl.dropboxusercontent.com/u/542 ... netic.capx
It does this:
1. simulates 100 objects moving with 5 seconds worth of random input
2. scores them
3. kills the lower 50
4. creates 50 new objects by combining two of the survivors and adding some random mutation
5. and finally repeat.

It doesn't converge very fast but given enough time it will converge on the objects moving as far along the path as possible. I imagine the scoring could be improved to help it converge faster but I'm probably done with this.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Mon Dec 05, 2016 5:26 pm

@R0J0hound
Very nice concept, i like it.
I read the code some times, but I didn't understant it's movement 100%.
It's very interesting, but it takes looong way until it hits the third or second goal ( + 30 gen).
Still awesome, Good Job !
B
11
S
3
Posts: 277
Reputation: 1,395


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 22 guests