Prototyping Game AI with HTML5 Canvas

I am working on a new game project with a friend of mine who has about 6 weeks until his next commitment takes up all of his time. Having more than a few pokers in the fire myself, I found myself wanting a quick tool for visualizing the behavior of the game AI without having to write a bunch of tools. Pop out Phos, and I have an effective tool for computing behaviors and displaying them in 2d without all of the distractions of the eventual 3d environment.

Since we are targeting the Unity3d engine, I can write my code in JavaScript and be certain to will work. The key bit is adding an Update() function in a setInterval timer, and coding everything to be retargetable to the transform API of the target platform. But where things stupidly easy, I can rely upon the browser debugging tools to allow me to edit and manipulate the live objects without running the full 3d editing environment.

Right now I am working on 6 types of AIs which all have their own emotional states and characteristic pathing methods. Each of these 6 types interact with the other AIs based on their emotional state and social interactions. They also have a reaction to both the player and items in the environment which influences their decisions. Finally they have a limited memory of where they have been and use that to influence future decisions.

These multiple levels of complexity mean I need a clear tool to explore their behaviors. I want to make sure hot spots are hot, cold spots are cold, and safe zones are safe. Using canvas, I can quickly blit sprites all over the map and have alpha mapped trials follow them. After a few minutes of running I end up with different areas quickly showing up as hot zones, and the empty areas are equally easy to spot. Saving the images to png data urls make it easy to screenshot each run and archive in a key value store. I can then combine the image maps to see progress over time.

While all of these things can be done using other tools, HTML5 canvas also makes it possible to share the simulation trivially with the other team members for their opinion. We can also use it to sketch up level designs and build the data sets which will eventually drive the actual game engine. Having built quite a few sim tools over the years, I have found the ability to quickly translate concept to working code to be the critical barrier. Any time spent not solving your particular problem is time wasted. While not 100% productive, the time I've spent in canvas land has produced much faster results than working in the target platform itself.