Implementation Notes
return to main page

This page provides some notes about how the Karel simulator is implemented.

Design Goals

First, a few comments about my design goals for the project... I wanted to implement a Karel simulator that:

Technologies

"Third Party" Technologies used on this site include:

Core JavaScript Simulation Engine

To overcome the single threaded nature of the web browser environment as it relates to JavaScript execution, I developed a "simulator" that runs JavaScript one "step" at a time. This consists of a code generator (that starts with the parse trees generated by a PEG grammar) that creates a list of named steps, each with information about where to go "next"; and a "runtime engine" that can execute these steps one at a time, at variable speed or one at a time (as would be done when stepping through code).

Coordinate Systems

A critical aspect to the implementation of the simulator is that it 'knows about' two sets of coordinate systems. The first are 'world coordinates'. This is the coordinate system that Karel knows about; it is a 'logical' coordinate system. The bottom left corner of Karel's world is the intersection of 1st Avenue and 1st Street. X-axis values increase as you go right and y-axis values increase as you go up. The second set of coordinates are 'DOM-based coordinates'. This is the coordinate system that the code uses to model Karel's world in the page's DOM. In this coordinate system, (0, 0) is in the top left corner, x-axis values increase as you go right (same as in the world coordinate system), and y-axis values increase as you go down (different than in the world coordinate system).

Pictorially: COMING SOON