(Note: if the heroku server is down, it's probably because it exceeded quota. You can still run it by cloning the git repo)

Inspiration

I've always loved the idea of writing an AI bot to challenge or fight others. I think it's a super fun way to learn to program and feels empowering. I always wanted to host a "St. Olaf vs Carleton Bot Wars" sort of thing, but none of the available tools really make it easy. That's mainly because:

  • You can't challenge individual people or groups. You can only upload your code to fight in the global leaderboards.
  • You can't easily play the game as a human, or play against your own bot as a human player.
  • Most games are grid-based. (Which is ideal for developing AI, but is often not what the real world looks/feels like)

So I set out to make something that should be: simple, flexible and tangible. I wanted something that does not obscure the process of writing code. No one writes a perfect algorithm from scratch on their first try. Programming is an iterative process. It's very important for beginners to see that to understand how talented programmers do what they do and how they got to where they are. * My tool will be highlighting, rather than obscuring, the process of writing code.*

What it does

Airena (pronounced Eye-reen-a) is a multiplayer game, a teaching tool and a (prototype of a) platform. It's a space shooter that you can play as a human. You can immediately click on the code button to write up your bot and watch it take over. Joining the game is as easy as opening the link.

http://i.imgur.com/QFCeb4A.gif http://i.imgur.com/Umh1XM2.gif

How I built it

I used CreateJS for manipulating the canvas and vector graphics. I used CodeMirror for the in-browser code editor. I'm using NodeJS with Socket.io for the networking. The game runs the Javascript code you supply it in an isolated container so you can't interfere with the game itself. All you can do is return which key to press next. You have access to some data about the world, such as your position and the positions of other players.

Challenges I ran into

Not having really done a proper multiplayer/networking game before definitely made it a challenge to figure out how to connect and sync multiple users across the world. It was even more challenging to figure out how to allow anyone to run their own AI bot on the fly.

I also spent a lot of time thinking about a game that would be simple enough to implement but still provide enough interesting challenge/strategy to be played by humans and AI.

Accomplishments that I'm proud of

  • This is definitely the easiest and fastest way to write code for an AI bot and see immediate results (all within a browser!)
  • Variables and state information persist even though the code gets recompiled at every keystroke!
  • The server keeps track of every player's code and state in its own isolated container, separate from the global state.
  • The live-coding-server logic is more or less decoupled, making it easy to repurpose for any other game or simulation for teaching purposes. (Imagine it being as easy as: import the plugin, define which function you want users you to be able to live-edit, and a code button pops up that allows users to play with the code in real time!)

Despite how simple this game is, this would actually be pretty close to a real setting where you might implement AI because of the game state is continuous (not grid based). If we wanted to teach people about techniques such localization, we could omit sending the current player's position and have them use the common techniques to locate themselves on the map.

What I learned

I learned a lot about writing networked code, and thinking about decisions such as what logic goes on the server and what can be kept on the client. I also learned about how Javascript can be executed as a separate process within Nodejs (using the VM built in library) and about all the different ways of capturing and isolating an environment. (I'm currently taking a Programming Languages class so it felt highly relevant here!)

I had also never used CreateJS before. I could have used Phaser, which is a library specifically built for games, and it probably would have been a lot easier, but I decided to use CreateJS because I hadn't used it before and because it's built to be more general (to support any rich interactive content on the web, not just games) I thought it would be a good tool to know.

What's next for Airena

I want to do two main things:

One is to further develop the game to make it more fun and interested to write AI for. One thing I'd love to add is the ability to release "minions", so you're no longer able to play very effectively as a single human. Then you can feel/see the power of programming. Perhaps a way to store and share code snippets that do various kinds of behaviors.

The other is to clean up and publish the live coding server as a standalone, to encourage more people to experiment with this idea, because I very much believe in learning by doing, I think by making it easy to implement this we could improve learning materials and show more people how fulfilling and exciting writing code really is!

Source: https://github.com/OmarShehata/Airena

+ 16 more
Share this project:
×

Updates