What's this?

(or skip all this and go straight to the page that lets you tweak variables)

This is an ActionScript 3 port of an AI "trainer" I wrote for an unfinished Kendo game. It was originally written for a closed-source game engine and had been languishing on my hard drive (actually, my NAS backup :P) for almost 2 years. But a number of very cool Flash Genetic Algorithm demos have recently surfaced on the web, and I thought, "Hey...I could port mine!" It took a few days, and it's not an ideal port (collision detection in Flash isn't as good as in a dedicated game engine), but I'm basically pleased with it.

This demo combines a Genetic Algorithm along with a Neural Network. Each fighter has its own Neural Net, and every 100ms it applies "weights" to each of 11 different variables in the game (such as current positions, velocities, whether they're striking, etc). By weighting and relating each of those variables, the Neural Net generates "outputs" indicating what the fighter should do (such as new velocity and whether / which target to strike). Coming up with the weights (or "training") is the trickiest part of Neural Networking, but that's where the Genetic Algorithm comes in.

A Genetic Algorithm is basically a way to take lists of random numbers, somehow give them "meaning", and evaluate their suitability for a task. Lists that are given high marks are crossbred with other fit lists. The child lists are then evaluated and crossbred, and this continues on and on for generations. In theory, as long as the code evaluating a list's suitability (called the "fitness function") accurately punishes and rewards the desired behavior, the Genetic Algorithm will begin to approximate a solution.

Since a Neural Net's weights are just lists of numbers, and since this scenario allows me to pit two networks against each other in order to evaluate their fitness, I'm able to use a GA to evolve the weights.

If you want to play with some of the variables, and maybe export / import some weights, there's an advanced version of this page.

I don't get the Kendo Stuff

Successful strikes to the head / face are called "Men" strikes. Strikes to the wrist are called "Kote" strikes. Strikes to the abdomen are called "Do" strikes. The rules dictate that you must strike your opponent's target with Ki-Ken-Tai-Ichi..."Spirit-Sword-Body-One". The short definition of that means that you show great spirit when you strike, you show great control of your sword, and you show great control of your body. In app terms, a successful strike is only recorded when 1) "spirit" (shown in the fluctuating bar that roughly corresponds to the character's breathing) is higher than opponents and 2) the target is hit with the very end of the blade. As for body, that's largely being handled in the animations :)

And yes, I forgot to draw the Tare.

Contacting Me

If you want to offer feedback, feel free to do it there or email me at jason@jasonreid.com.