Thursday, October 12, 2006

JavaScript Path Finder with A Star

Last post talks about a stupid tris game and while I was writing that code I've thought about a way to create a better script (more intelligent).
Since tris game, as many others, is based on a grid, I've looked for one A * JavaScript implementation but hey, I didn't find them !

I remember Alessandro did a path finder for ActionScript and as you know AS is ECMA and its A Star implementation should work on JavaScript too.
However, Flash has a dedicated virtual machine (Flash Player) and its source is byteencoded, then AStar is fast enought but not so fast used with JavaScript.

That's why I've decieded to create a generic AStar function quite optimized for JavaScript (but it probably should be better too) and usable with ActionScript 1.0 too.

Here there's a simple application example while in this page you can read about the function and view the source code too.

Example uses a MemTronic version to reduce AStar size into 1,4 Kb.

Finally, this is the "old" Alessandro implementation where you can find more informations about A Star algorithm :)

No comments:

Post a Comment