Anyone for a game of Space Invaders?

Background

I’ve been itching to do this AI experiment for a while, even if the idea is pretty unoriginal (see https://paperswithcode.com/sota/atari-games-on-atari-2600-space-invaders).

It’s such a classic and iconic game and was a huge success back in 1978 – $2.8 billion of revenue in today’s money from Japan alone!

The legend Tomohiro Nishikado, wrote the original game working for Taito Corporation in Intel 8080 assembler.

If you have read my “About me” page and are into chipsets, you will know that it is the predecessor of the z-80 that I learnt assembler for, aged 9. I knew it was meant to be when I found https://www.computerarcheology.com/Arcade/SpaceInvaders/, which has the 8080 original Space Invader source code disassembled! Thank you, Topher.

This project has been a labour of love. If you were beginning to think I’d given up posting, you’d be wrong – this has taken over a month of long hours at weekends and evenings to create. I hope you appreciate my attention to detail, and enjoy this post!

Goal achieved! I created an AI that can beat Space Invaders without deep learning, using just a small neural network.

Features:

  • A playable Space Invaders, reasonably faithful to the original (sprites/fonts, gameplay etc.)
  • A very configurable environment to train AI –
    • Three different inputs to train the AI
    • Two different output methods
    • Perceptron or random networks
    • Numerous activation functions
    • Control over mutation methods
    • Control over the elite, random and offspring percentages
    • Control over types of mutation, cell types and more,
    • Configurable fitness scoring
    • Save/load of “brains”
    • Graphing of progress

For those who cannot wait, my source code is in GitHub as usual.

The following is a recording of my AI getting nearly 10k, with just 10 hidden neurons. You will need to click [view raw] to download the .mp4 as GitHub hasn’t got a viewer for 22.4mb mp4 files(!).

https://github.com/aimlfun/space-invaders/blob/main/Space%20Invaders%20AI.mp4

That was an early version before I fixed a couple of bugs and enhanced the radar. It now runs without dying until you close the program down. Want proof? Download the source, run it, and click on the AI Play button to have the pre-trained AI play the game.

If you don’t know the rules of Space Invaders or need a refresher, check out this site – it provides a comprehensive summary. A few aspects in that summary are wrong, however, to be fair to the author(s) you would not necessarily know if you haven’t seen the source code.

After you’ve read this post, I hope it tempts you to investigate AI further and also be curious how much you can achieve with so few neurons!

Topics covered

  • Creating an environment
  • Training inputs, associating them with movement/firing
  • Choosing the neural network configuration
  • Getting a very high score
  • Summary/challenges

On the next page, we start with the environment.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *