NEATo – The Evolutionary AI Battle Simulator

Every year at Amazon there is virtual battle bot competition where engineers from all over the company create bots in JavaScript that fight in a 2D sandbox environment. It’s an optional event where you code the bots in your spare time and it’s a lot of fun. 

The battles are fought one-on-one over 2 minutes. The bots are circles shooting smaller circular bullets. Each bot is able to perform the actions move, rotate, and/or shoot every 75ms and knows the position of the enemy and all bullets every tick. The bots each have 5 lives and can have 5 bullets on screen at once. The tournament is single elimination and the prize is some token gifts and bragging rights.

This year instead of hand-coding a bot I decided to try my hand at writing an Evolutionary AI program, which I’d been fascinated with after seeing this AI learn to play Mario all by itself. Could I create and train a bot good enough to defeat the Human created bots?

Now I’m no AI expert, and this bot isn’t going to beat Alpha Zero any time soon. It’s pretty simple in it’s implementation. It’s a neural network that starts with some input nodes and output nodes, then randomly adds nodes, links between nodes, changes the weights for the links and disables/enables nodes. It’s based off the Evolving Neural Networks through Augmenting Topologies (NEAT) paper. Each neural network is called a genome and they are organized into species of similar genomes. When a genome performs well in battle it gets a high fitness rating and then goes on to have new child genomes with random mutations. If a genome performs poorly it is eliminated. The inputs to the neural network are the position of the walls, bullets, and opponent, and the outputs are the actions the bot should take.

You can train in headless mode and it will run hundreds of battles in parallel, scaling to as many CPU cores as your PC has. During training you can watch the latest generation fight it out in your browser. After making the bots train by fighting each other for a few hundred generations the bots are able to fight at a decent level. I entered a bot with around 600 generations of training into the tournament and it ended up making it through the first 2 rounds and being eliminated in the 3rd.

Rather than let that code go to waste I thought why not open source what I’ve made, and create a custom battle environment so others can learn how an Evolutionary Neural Network works and build their own AI’s. So I’ve done that as well as written an in depth explanation of how everything works in the README and thoroughly documented the code. You can check it out here. Enjoy training your own bot to use in your next game of battle bots and good luck!

 

2017 Year in Review

So it’s been a while eh. 16 months since my last update, that’s almost a record. I’ve been procrastinating writing my 2017 year in review for about 8 months now, because as you may have guessed, I didn’t accomplish many of the things I set out to do. I’ll have more to say about work ethic and reflecting on my reasons for failing to meet my expectations soon, but I must get this post out before midnight or I’ll be fined $50. I’ve found having a monetary fine has been one of the best ways to stick to my goals, even if it does cause me to rush at the last minute.

So what did I accomplish out of my monthly goals for 2017? and what am I planning to do in the future?

Paper Towers

I’m happy to report that this goal was completed and you can find the open source Tower Storm here. There’s still a LOT more I’d like to do with this game and codebase such as moving to ES6 instead of CoffeeScript, adding a map editor, removing the dependency on RethinkDB, and making it simpler to setup a server (a docker based setup would be sweet). I also want to release videos walking through the codebase (which I did record and put on Twitch, but it looks like they disappear after a few weeks?). I ended up keeping the name Tower Storm because I already owned the domain and social media pages and I still love the name.

Learn Spanish

This I also somewhat accomplished. I took lessons on italki for a while which were incredibly helpful and accelerated my skills far faster than Duolingo, though both together was a good combo. My girlfriend spent the summer of 2017 in Ecuador doing her masters thesis and I was able to visit for a week and somewhat navigate my way around with the Spanish skills I’d learnt. I could barely hold a simple conversation with someone who spoke slowly and clearly.

Krav Maga

I ended up doing Krav Maga for a year, and it was fun. I learnt a lot and feel like I could defend myself in a bar brawl, but would still have trouble against someone with any kind of weapon. The classes were intense and really pushed my body to the limits, including one I had to bail on half way through because I was close to passing out (probably shouldn’t have done it after not eating for 8 hours). The only downside was there was a long period where I could only take basic classes which was frustrating. There was some special training you had to do to take advanced classes where you actually spar’d with other people, and there were no classes for this coming up for months. I’ve stopped doing Krav Maga at the moment but I may pick it up again in the future.

Study Time

Unfortunately I barely started on Study Time, BUT I did have a big breakthrough in how this would work. For the longest time I’ve been wanting to build a peer to peer social network (it was in my bundle of ideas but didn’t make the top 10 list because I didn’t think I was skilled enough to pull it off). This social network would have no central servers, just everyone hosting some small portion of the data and sharing it with everyone else. Anyway I’ll delve into this deeper in another post but I found a network that is basically this called Scuttlebutt, and using this same technology I think it’ll be possible to build the API’s for the metadata about each lesson / course on top of this network. Then anyone will be able to load up the application, download metadata about courses off other students, and when viewing the videos stream them via torrents. I’m super excited about this and want to try and pull it off again soon, I feel like the pieces are available I just need to put them together.

Learn the Cello

I did this one! For 6 months I learnt the Cello last year, and it culminated in being able to play a (pretty crappy) rendition of the red wedding theme song from Game of Thrones. I stopped after 6 months because I wanted to dedicate time to other projects, but I would like to pick it up again one day.

Educational Honesty, Reverse giving charity, Build a Farmbot, Web Basic, Mass Reforestation

Unfortunately I didn’t even make a start on any of these projects (well, there was some research, but nothing created). Which is a bit of a disappointment. I feel like I got too distracted by my work at Amazon towards the end of the year (with AWS Cloud9 being released) and put everything on hold and slowly forgot about them.

I will be building a FarmBot later this year, I finally have balcony that gets enough sun that this is possible. I’m not sure about the rest of the projects, they’re things I would love to see in the world but don’t quite fit my optimum hedgehog intersection. I’ll be reviewing my ideas backlog and coming up with some further ideas for this year soon. I’ll also be utilizing this monetary fine mechanism to ensure I post more and share my ideas more on this blog, because they’re not going to happen when they’re tucked away in my private notes.

So I accomplished 4 out of 10 ideas I wanted to do last year, which isn’t bad, but I can do better. I’ll be creating my list of goals for the next year soon and taking all my lessons from the last 18 months into account when doing so. At the very least I learnt a ton, and that’s my motto for life: Always be Learning. It’s not about where you are but where you’re going and how fast you’re getting there. If you have ideas or feedback for me, let me know. Last of all: enjoy life, and don’t forget to be awesome.

 

Projects Status Update – April 2017

I unfortunately procrastinated the March status update so much that it has melded into the April update. Over the past 2 months I’ve been working on 4 of my 10 Projects for 2017. Those 4 are: Paper Towers, Spanish, Krav Maga, and learning the Cello. My current core focus is learning the Cello and I’m spending 3 – 4 hours a week on the rest.

Paper Towers (Now Tower Storm again)

Firstly I decided to stick with the name Tower Storm instead of re-branding this project as Paper Towers. I’m proud to say that Tower Storm is finally Open Source!. I spent around 30 hours in the last 2 months removing all copyrighted graphics and sounds from the game, and cleaning up the code so it’s easy for anyone to run and make modifications. I finally pulled the trigger a few hours ago and put it up on Github. I also did my first open source development stream, if you’re interested in seeing how I develop Tower Storm, how to mod it yourself, and my thoughts on programming in general you can follow me on Twitch.

Spanish

As of the 21st of April I was up to a 25 day streak on Duolingo doing at least 30 minutes of spanish a day (50xp per day). Unfortunately I lost that streak, but I will be continually learning Spanish on Duolingo over the next year. Alongside that I’ve been watching movies, LoL games and random Youtube videos in Spanish. I’ve also switched my PC and Phone to use Spanish as their default language. Every little bit of learning helps.

Krav Maga

I signed up for Krav Maga 2 weeks ago and so far have done 6 classes. I’ll probably continue this 3 times a week schedule. So far we’ve practiced basic punching, hammer fist, kicking, roundhouse kicks, getting out of chokes, and defending yourself when you’re on the ground. I’m really enjoying it so far, it’s useful, it’s a ton of fun fighting as hard as you can (into pads) and it’s a great workout. I hadn’t been punched in maybe 15 years and it’s an eye opening experience, and made me realize I have to toughen up a lot if I want to survive a real life fight.

Cello

To celebrate the open sourcing of Tower Storm and the down-winding of that project I went out and hired a Cello for 3 months. I’ve only had it a week now and haven’t had lessons yet. I bought a beginners book and have been teaching myself how to play with that and YouTube tutorials. I’m excited to report that I can already play the beginning of the Rains Of Castamere song! Albeit with a lot of squeaks and quite slowly. I can’t wait to learn more.

So that’s it. I’ll be continuing to focus on these 4 activities until at least the end of May whereupon I may start on another depending on my progress and time available.

 

One project every month

I constantly have ideas of software I want to build, skills I want to learn, sites I want to create. I’ve been writing these ideas into Evernote since 2009. The problem is I often start working on an idea but give up a week or two later when something else comes along. Life is too short for that, so now I’m going to get focused.

A few months ago I started organizing all these ideas on a Trello board to figure out how I want to spend the next 5 years of my life.

I had 125 ideas in total, which I’ve whittled down to my 10 favourite. This year I’ll be spending 1-2 months building a prototype or learning the basics of each. Then at the end of the year I should know what I want to spend a few years focusing 100% of my energy on.

My top 10 ideas for 2017 are:

Paper Towers

This is the open source version of Tower Storm. My original vision for Tower Storm is a Tower Defense game with as much depth as DOTA. Unfortunately this scope is far too huge for an indie company. However it has one major strength: It’s a web game that doesn’t require compiling and is configured through JSON scripts. So if I open source it others can build their own TD games using this engine / framework. They can make maps, minions, towers, game modes and more and share them around and help each other, and it can turn into something much bigger and more fun than I could produce by myself. I’d love to see what the community creates once this is released.

Learn Spanish

I’m currently at a level where I can hold a basic conversation. I want to get to a level where I can start thinking in Spanish and be able to hold ongoing conversation consisting of more than introductions and small talk.

Krav Maga

This is mostly about self defense, and hopefully it’ll be a lot of fun too. My first lesson is this Monday.

Study Time

Think Popcorn Time for MOOC’s. Software where you can learn anything you desire and it’s completely peer to peer and streamed via torrents. This way knowledge and lessons can live on forever even when MOOC sites take down their courses or shut down.

Learn the Cello

I’ve learnt the Clarinet and Tenor Sax, but have yet to figure out a stringed instrument. I love the sound of a Cello and my goal is to play the Rains Of Castamere.

Educational Honesty

I’ve been reading Amusing ourselves to death, it was written in 1985 and is absolutely on point with how woefully unintelligent public discourse has become on topics that we should be taking seriously. I want to build a site focused on educating, not influencing. A place where intelligent debate is praised, and all opinions are considered. Twitter, Meme’s and the comment sections on most websites are what I consider “Information junk food”. We had a crisis with actual Junk food in the 70’s, 80’s and 90’s, but if you look around recently you’ll notice these trends are reversing, people are now eating healthier and taking better care of their bodies. We must now do the same with our brains. I believe with good information we can do just that and live healthier mental lives, just like how we fought back against real junk food.

Reverse giving charity

It’s well known in psychology that if you get given a gift you feel more obliged to give back in return, this is why food samples and waiters giving mints at the end of a meal work so well. I’d like to try a charity built around this idea. Imagine giving people free coffee from countries in Africa or South America, and included with that is information about the country it came from, the issues it faces, and how you can help fix those issues, via donations or spreading the word. I think you’d have much more success garnering support in this way than the usual begging on the street, and so want to try it out. I may join an existing charity or start my own (depending on difficulty).

Build a Farmbot

The Farmbot is one of the coolest pieces of technology I’ve ever seen in my life, and it’s completely open source! I’d like to try building one of these from scratch and helping refine their wiki with information on where to source parts and fixing bugs and issues with the documentation or software. Imagine if we could get Farmbot cheap enough and reliable enough that anyone can homestead and get the basic food they need to live completely free.

Web Basic

I recently read an article on how q-basic is still the best beginners programming language, and I have to agree. Q-Basic was the language I started with when I was 11 and it makes far more sense to non-coders than most other languages. But installing q-basic, compiling, and sharing programs is not so beginner friendly. So why not bring Q-Basic to the web. Imagine if you could create a new Cloud9 project and just start coding in Q-Basic, hit run, and the program is compiled to Javascript and rendered using Canvas. Kids could start learning and coding in seconds and send their projects to friends minutes later (just send them the preview link!). This social feedback loop could bring so much joy to kids and lowering that barrier to entry could entice many new kids to learn coding that had never considered it before.

Mass Reforestation

We’ve had mass deforestation for 100 years now and the effects have been devastating. Now we need to reverse this process, but how? With drones of course! Imagine if we could create a drone that surveys a piece of land, uses AI to figures out the perfect combination and density of trees and fauna to re-invigorate that land, and then goes ahead and does it all by itself. The technology is available now, we just need someone to compile the knowledge build the software. The mass reforestation site will share ideas and technology on the latest efforts to reforest the world so that everyone can take part. Eventually with enough people and drones out there we’ll be able to accomplish mass reforestation.

What about the other 115 ideas?

I still really want to see them happen, I’m just not particularly excited about doing them myself. So I’m going to share them here on this blog, please steal them as I post them and help make the world a better place 🙂