Shortest path finder in Processing

Simon created a wonderful project in Processing – a path finder that looks for the shortest path to reach the green cell, avoiding the obstacles. Every time the path finder fails, it tries again. Simon also built a counter for the number of tries. The next step is turning the grid into a game environment and training the path finder, Simon says, i.e. applying reinforcement learning. Simon thinks he should use the Q function in this stochastic environment, but is still very timid about its implementation. In the third video below, he explains how this project could help him take his first cautious steps in the direction of machine learning.

 

 

Advertisements

Problem with a Genetic Algorithm Game

Simon has been working very hard at making his version of the Citius Invaders game that Siraj Raval presented in Python during Week 9 of his “Math of Intelligence” course. It’s a simplified version that still incorporates a genetic algorithm. Simon’s plan is to code the same game in P5 during his next live tutorial (at 17:00 CET on 30 November). Unfortunately, after many lines of code in several files, when the game was nearly ready, he faced a problem he doesn’t know how to resolve. He tried getting some online help via the Coding Train Slack channel but didn’t get much feedback. The code is now on github at: https://github.com/simon-tiger/citius-invaders/

Here is how Simon describes the problem:

Hi! I’m working on a “Citius Invaders” game, and I have a problem.
In the game, there are enemies, a spaceship, and bullets that it shoots.
The parameters of the game are:
* The game starts with 6 enemies.
* The minimal amount of enemies is 4.
* The maximal amount of enemies is 100.
The rules of the game are:
* When a bullet collides with an enemy, the bullet and the enemy get deleted.
* If there are 4 enemies on the screen, you’re not allowed to shoot any bullets any more.
* If there are 100 enemies on the screen, you’ve lost the game.
* The enemies reproduce every 5 seconds (this amount of time decreases every generation).
The goal of the game is to stay as close to 4 enemies as possible.
The problem is that: After the 5 seconds, the enemies don’t stop crossing over! I think the order that I’m crossing them over is wrong.¬†They breed (cross over) forever and that makes the game pause forever. Maybe the algorithm in which I let them cross over is wrong. I have a `while` loop somewhere, maybe it became a forever loop. The `while` loop is at line 52 in `Population.pde`:

 while (!selectedEnemies1.isEmpty() || !selectedEnemies2.isEmpty()) {
 int index1 = int(random(selectedEnemies1.size()));
 int index2 = int(random(selectedEnemies2.size()));
 if (index1 == index2) {
 index2 = (index2 + 1) % selectedEnemies2.size();
 }

Below are a some videos showing Simon at different stages of the project. In the top video, he speaks of the difficulties he encountered with the frame rate and the genetic algorithm.

 

 

28 times 28

Simon programmed a presentation to explain why 28×28 is not the same as 20×20 + 8×8 geometrically. The code is quite complicated and involves some trigonometry and conditional statements: the grid is divided into different parts every time Simon clicks and depending on how many times he has already clicked. This is typical Simon – coming up with an inherently arduous and complex system to visualise the beauty of the world around him, even of the seemingly trivial things. By the way, the inspiration for the 28×28 grid came from Simon’s favourite math channel, 3Blue1Brown and its latest video on Neural Networks (the grid was used to explain computer vision).

Simon is doing quite a lot of sums in his head nowadays, looks like it’s a new trend. Today, while bathing in the fountain outside, he was calculating how long 1/16th of a minute lasted. And a couple days ago, while waiting for his appointment at the hospital, he calculated how long it would take someone to read a whole page of random numbers, taking an educated guess that one takes 4 seconds to read out one number and remembering Daniel Shiffman mentioned there were 100×5 numbers per page in his book.

Cannon Game in Processing

Simon shows the Cannon game he created in Processing (Java). He says he was inspired by the Stackoverflow forum, where he saw an example of the game and later wrote the code for a similar game himself. I saw him quickly write the code in a matter of perhaps two hours. Simon will post his code on GitHub once he has added a couple extra features.

Processing on RaspberryPi

Simon installed Processing on his RaspberryPi recently (using the terminal, which looked terribly sophisticated and scary as on Linux you’re forced to do everything through the terminal) and started preparing examples that he hoped to show during his own livestreams, but the RaspberryPi seems to have crashed, unable to bear the weight of so many examples…

dsc_19091456268463.jpgdsc_1908267889140.jpg