Old School Maze Pascal to JavaScript

Zarko Gajic recently reposted Kostas Symeonidis’s Maze, this is an old code (2004) that generates a random maze using Prim’s algorithm and solves it.

I wondered how it would hold its own when compiled to JavaScript, and by that I mean compiling the old 2004 source… click on the picture to the right to run a version compiled with SmartMobileStudio. Works in all the usual desktop and mobile suspects. Click or touch the maze to solve between arbitrary locations.

The original source works on a large static array that is passed as var parameter and where the bytes are used in a bitwise fashion. All in all it does its job in a brute-force native-compiler friendly way, but is quite suboptimal for a JS execution. Anyway I compiled as close as possible to the original (update source zip, 6kB).

Very few changes were required to get it to compile:

  • changed the TObjectList to an “array of TCell
  • replaced Random() with RandomInt()
  • replaced the FillChar() with nested loops
  • mapped TCanvas to TW3Canvas

But the bulk of the code compiled without changes, and runs in Android, Chrome, IE9, etc. (only FireFox has a glitch, which is not related to the Maze code, but to the VJL and a Mozilla event name).

One thought on “Old School Maze Pascal to JavaScript

Comments are closed.