# Simon has created an “immortal” organism?

Simon opened up a genetic algorithm game he built about two years ago and made a fascinating discovery: one of the organisms seems to have become immortal! Simon has called his discovery “The Everlasting Vehicle” and saved the vehicle’s DNA.

Links to the game on GiHub:
Original code: https://github.com/simon-tiger/steering-behaviors-evolution
p5.js version: https://simon-tiger.github.io/Game_SteeringBehaviorsEvolution/SteeringBehaviours_EvolutionGame_p5/

Simon writes:
The last time I ran the program is a couple of hours ago. Everything died out, except for one vehicle.

Stats
I have programmed this with a genetic algorithm. They have a DNA with 4 genes.

Attraction/Repulsion to food
Attraction/Repulsion to poison
How far it can see food
How far it can see poison
They also have a health, which goes down over time. If they eat food, then their health goes up, if they eat poison, then their health suddenly goes down. A good health is 1, and a bad one is 0.

So what was The Everlasting Vehicle’s DNA and health?

Property Value
Attraction/Repulsion to food 1.9958444373034823
Attraction/Repulsion to poison 1.3554737395594456
How far it can see food 53.31017416626768
How far it can see poison 23.33902221893798
Average health ~397
So it attracts to poison, yet its health is approximately 397 times bigger than a very good health! And better yet, it even lasted for a couple of hours so far!!!

Credits:
Inspired by Daniel Shiffman’s Evolutionary Steering Behaviors Coding Challenge

# Flocking System Painting with Pixels

This is one Simon’s most beautiful projects recently! Simon saw the idea to link the webcam image to the boids of a flocking system in a video by Daniel Shiffman, but the code featured in this project Simon wrote himself. The Flocking code is based on Daniel Shiffman’s example from his book The Nature of Code. (Flocking is a steering behavior that consists of separation, alignment and cohesion – which are also steering behaviors – combined).

Simon’s sis also posed for the camera:

Simon is also about to make a JavaScript version of this fun project, because JavaScript allows to host it easily online, so that everyone can play with it. With JavaScript, he may even be able to write it in an online editor, so there won’t even be a need to host it. Check in later for an update to this post!

UPDATE: Simon encountered a problem trying to translate his Flocking System Painting with Pixels into JavaScript: P5 runs much slower than Processing after Simon added steering behavior. He doesn’t know how to solve this. Simon’s JavaScript code is online at https://codepen.io/simontiger/pen/ZJKBbN?editors=0011

# Evolutionary Steering Behaviors Game

Note: See the update at the bottom of this post!

We’ve had quite a dramatic situation here for the past couple of days, after Simon turned Daniel Shiffman’s Evolutionary Steering Behaviors Coding Challenge into a game in Processing (Java) and then also in JavaScript (with p5). After completing the game in JavaScript, Simon wanted to add a new feature – a checkbox he programmed using the p5.js library. The checkbox would give the player the option to play with or without the timer, adjust the timer and also had a “New game” button. In the end it turned out that the checkbox didn’t really work. Simon was very upset and it took me hours to talk him into putting the game online even though the checkbox didn’t function (he wanted everything to be perfect) and ask for advice. “I have got a problem with a p5 element: In my setup function, I defined my checkbox. In my reset function, my checkbox is undefined. Why?” – Simon asked in the “Share Work” section of the Coding Train Slack channel, where he has the opportunity to communicate with experienced programmers. He received quite a lot of help and was enthusiastic about it at first, but for some reason, he hasn’t tried the solutions he was suggested. Perhaps it’s his gut feeling that the bind function suggested is still too difficult at the moment. I have decided not to push anymore and trust him on this one, although it’s always a dilemma for me whether I should sometimes “force” him into taking instructions from others or let him solely rely on his fantastic intrinsic autodidact mechanisms. The second seems to work better in terms of the learning process, but I do push him into sharing his work.

Simon’s game is online at: https://simon-tiger.github.io/Game_SteeringBehaviorsEvolution/SteeringBehaviours_EvolutionGame_p5/

In the videos below Simon shows how he made the game. It’s an ecosystem type of genetic algorithm (with no generations), where the organisms (autonomous steering agents) clone themselves. The autonomous steering agents evolve the behavior of eating food (green dots) and avoiding poison (red dots). Simon added two invaders into the game, one giving food and the other randomly spreading poison. The player can control the “good” invader by moving him and making new food. The goal of the game is to make the agents survive for as long as possible.

The Processing (Java) version:

The thinking behind the game (Simon explains everything at the whiteboard):

The JavaScript version (now online):

In the last video, Simon talks about his problem with the p5 element.

Evolutionary Steering Behaviors game seek algorithm part 1. DESIRED equals TARGET minus POSITION:

Evolutionary Steering Behaviors game seek algorithm part 2. STEERING equals DESIRED minus VELOCITY:

UPDATE: When Simon saw Daniel Shiffman’s comment on Slack this morning (Daniel saying Simon did a fantastic job and that he might even include Simon’s game in the next Live Stream), he sat down and applied the bind function as suggested by his older peers above – without any incentive on my behalf! And it worked! I think we’ve hit a true milestone again. Simon has this growing feeling that he’s got friends out there, his tribe, who understand and who are ready to help.

One day later: Simon had another chat with his friends on Slack and got a lot of help with the last remaining small bug in his game (the New Game button didn’t start a new game if the player had chosen to play with no timer but jumped to Game Over instead). In the video below, Simon shows how that problem got solved:

# Train Simulation: Seek and Flee Steering Behaviors. Simon’s own code.

Simon’s sketch is available online at https://alpha.editor.p5js.org/simontiger/sketches/B1GtGlDGb

This train simulation is Simon’s own code using the seek and flee steering behaviors…

and a slider:

# Neural Networks. Perceptron and Preception Seeking in JavaScript

Simon has translated Examples 10.1 (Perceptron) and 10.2 (Perceptron Steering) from Daniel Shiffman’s Nature of Code book, Chapter 10 (Neural Networks) into JavaScript in Codepen.io. Both projects are available online, you can play with them and see the code if you go to Simon’s Neural Networks collection page at https://codepen.io/collection/DbBqJj/

Simon plans to place more JavaScript translations of neural networks examples from Daniel Shiffman’s book on the same page in the course of this week.

The first of the videos below shows Simon talking about his translation of the Perceptron. In the second video, he is showing the Perception Steering project, a combination of steering behaviours and neural network (the autonomous agent in the program get a “brain” with one “neuron” that allows him to seek the target closest to the moving circle).

# Autonomous Agents. Steering Behaviors. Flocking.

Simon’s full-screen take on Flocking, based on Chapter 6 from The Nature of Code (Autonomous Agents). The code comes from Daniel Shiffman’s tutorial Combining Behaviors: Flocking.

In Simon’s words, Autonomous Agents need to have action/ selection, steering (for example, for Flocking you need Separation, Alignment, Cohesion programmed using the neighbours, desired and current velocity) and locomotion (position, velocity, acceleration, “own vector stuff” or a physics library).

# Steering Behaviors: flow field, dot product, scalar projection

Simon’s big project the last couple of days was about making a steering behaviors database, complete with a navigation menu (in Cloud9):

He managed to finish the first two examples – “Seek and Flee” and “Pursuit and Evasion” – and worked on the Flow Field Following and Path Following.

As recommended by Daniel Shiffman, Simon largely relied on the paper called Steering Behaviors For Autonomous Characters (written by Craig W. Reynolds from Sony). As Simon told me, he tried to guess the code to make the static drawings in the paper come to life. For instance, for the “Seek and Flee” example, Simon animated this drawing:

Simon also made a “Seek” example in the language called Lua (from the Codea app):

The second example was about Pursuit and Evasion:

Simon also explained to me how Flow Field Following worked:

Another steering behavior he scrutinized was Path Following. For Path Following, he first had to learn what the “dot product” was. In math, the dot product or scalar product is an algebraic operation that takes two equal-length sequences of numbers (usually coordinate vectors) and returns a single number.

The way Simon learns is usually by studying (deconstructing) and memorizing the formulas (even if he doesn’t fully understand them in the beginning). After he comes back to the formula later on he seems to have grasped the meaning of it.  I often observe him actually apply different formulas in real life. When it comes to the “dot product”, Simon is in the beginning of the learning curve:

The formula for scalar projection is:

or the way Simon put it:

# Steering Behaviors Coding Challenge

Following along Daniel Shiffman’s Steering Behaviors Coding Challenge: extracting font path points from text in p5.js with p5.Font.textToPoints() and rendering the text as particles with steering behaviors that react to the mouse.

# Looping through an array lecture

In these videos Simon explains looping through an array and adding while simultaneously removing things from that array. He recorded this presentation while working on an evolution simulation (Evolutionary Steering Behaviors, see previous post).

# Simulating Evolution: Evolutionary Steering Behaviors

On Wednesday Simon went on with playing god (evolution simulation) and translated Daniel Shiffman’s Evolutionary Steering Behaviors Coding Challenge from JavaScript to Java.  The goal of the challenge is to create a system where autonomous steering agents (smart rockets) evolve the behavior of eating food (green dots) and avoiding poison (red dots).

This challenge is part of the spring 2017 “Intelligence and Learning” course at NYU’s Tisch School of the Arts Interactive Telecommunications Program. Simon was especially happy to find out that Daniel Shiffman left a couple of personal comments praising Simon’s progress and offering help in pushing his code to Danniel’s GitHub repo.

Here is Simon’s translation on GitHub: https://github.com/simon-tiger/steering-behaviors-evolution

The rockets have their own DNA consisting of four genes:

The challenge step by step: