OctopAI
An obstacle avoidance game to test AI
Prelude
My fascination towards octopus comes from a three-pronged attack of the intellectual, the fantastical, and the personal.
- The cognitive capabilities of the cephalopods in general and the octopus in particular, are fascinating. My pet hypothesis is that, if only the octopus had evolved to live a social life and live longer, they would be ruling the underwater.
- The tentacles from the sea have captivated human imaginations and my favourite horror story write H.P.Lovecraft's cosmic horror comes in the form of an octopus headed abomination.
- As a scuba diver, I have had my share of encounters with the octopus that even went on to have one of them hitching a ride on my palms for a few minutes.
So when I wanted to write a game that would have the ambition of training a moving object (preferably a living being) using AI, I immediately chose an octopus.
The inspiration: Flappy Bird AI
The idea of this AI-enable octopus rests squarely on the Flappy Bird AI tutorial that I saw on YouTube at the Tech with Time Channel. The tutorial uses the Python programming language, something I have been diving deeper into. Further, it uses Pygame for the game environment (something I'm using for the Monty Python RPG project). It uses NEAT as the
So I followed the tutorial without referring to his code on github and coded the Flappy Bird AI. Except for a couple of minor issues, it worked well out of the box.
But I realized I did not want a Flappy Bird. And I also realized that I don't need to restrict the game to whatever simple stuffs we see. The idea of an Octopus came up and I decided to flex a bit of my sketching skills to develop the graphics.
AI-enabled Octopus
The present version of OctopAI (as of 03-Feb-2021) has three files
octopAI.py
octopAI_display_accessories.py
config-feedforward.txt
The octopAI_display_accessories.py
contains the components necessary for the game, including the classes that form the basis of the game (Octopus
, Obstacle
, Base
) and other functions. The octopAI.py
contains the main function and also the invoking of the AI.
A couple of screenshots from the game would give an idea of how things look:
In the second screenshot, we see multiple octopi because the NEAT is a genetic algorithm and tries different instances of the octopus (with different parameters) and improves their performance over different generations. The configuration file decides on these aspects (the number of instances, how the mutation happens, etc.)
The way ahead
This project is hosted on Github as OctopAI. The current code as of January 2021 is working, but also differs very little from the tutorial except for the use of my own visuals. My idea is to effectively the separate the AI part and the visualization part so that I can work on them independently.
I however plan to refine the entire project slowly whenever I have time. The following are the ideas I want to do.
- The visualization part
- Bring in a larger screen and more complex obstacles.
- Apart from obstacles, we can also have specific objectives such as reaching a particular place. This might be a bit difficult in terms of the visualization. However, I can take inspiration from the PyRat game.
- I can provide different types of organisms. That is, these organisms would have certain restrictions that are more closer to their real scenario. For example, an octopus versus shark (higher speed than octopus). The AI can try to train an ensemble of these different organisms (of course, I'm doing this because octopus will win against everyone because of their flexibility).
- AI part
- My main motivation is to learn how to tune neural networks automatically. To this end I plan to learn and try several of them.
- NEAT is the starting point. I would try to look at ways to incorporate multi-criterion version of NEAT for this case (when I expand the game).
- Reinforcement learning is something that I'm very interested in. Especially Q-learning.
- I'm interested to understand if I can use implicit layers in the neural network model to make a better performing AI overall.