+###
+Interface rules (not yet implemented):
+
+0. Initially in mode STOP
+
+1. If you click a command, the command should be added to the list
+STOP: enter mode PLAY
+
+exception A: not during TURNAROUND or PLAYREV
+exception B: list is full, show error sparks on command list
+
+2. If you click play, playback should reset and enter mode PLAYFWD
+
+3. If you click undo, last command should be removed from the list,
+   playback reset and fast-forwarded to the new last command, enter mode STOP
+
+4. At the start of a command cycle
+PLAY: advance to next command, if no more commands, STOP
+STOP: nothing
+PLAYFWD: advance to next command, if no commands, STOP,
+         if no more commands (and any commands), TURNAROUND
+TURNAROUND: PLAYREV
+PLAYREV: advance to previous command, if no more commands, STOP
+
+5. @show_current_command is the currently executing command (i.e. the command
+   currently animating), this is the highlighted command
+5a. @show_current_command is set to the length of the commands array (an
+   invalid command index) when in TURNAROUND
+
+6. @next_command is the next command to be run, once it is run increment it. It
+   is the length of the total array (invalid index) when no more commands are
+   left to be executed in PLAY or PLAYFWD, respectively -1 in PLAYREV
+
+###
+
+
 level_cnv = document.getElementById('level')
 
 prog_cnv = document.getElementById('program')

# stepLevelSimulation?
moveCommand = (level) ->
  switch level.mode
    when levelMode.PLAYING, levelMode.FULLPLAYING
      level.bot.xi += @dir.dx
      level.bot.yi += @dir.dy
      level.bot.dir = @dir.theta
    when levelMode.REVPLAYING
      dir = reverseDir(@dir)
      level.bot.xi += dir.dx
      level.bot.yi += dir.dy

  #console.log("mode = " + @mode + " animMode = " + @animation_mode)

  if @animation_mode == levelAnimMode.READY
    step_ok = false

    switch @mode
      when levelMode.PLAY
        if @next_command < @commands.length
          step_ok = true
        else
          @mode = levelMode.STOP

      when levelMode.PLAYFWD
        if @next_command < @commands.length
          step_ok = true
        else if @commands.length > 0
          @mode = levelMode.TURNAROUND
          step_ok = true
        else
          @mode = levelMode.STOP

      when levelMode.TURNAROUND
        @next_command = @commands.length-1
        @mode = levelMode.PLAYREV

      when levelMode.PLAYREV
        if @next_command >= 0
          step_ok = true
        else
          @mode = levelMode.STOPDONE

    @bot.showxi = @bot.xi
    @bot.showyi = @bot.yi
    @bot.showdir = @bot.dir

    if step_ok
      step_command = @next_command

      next_move_control =
        start: (t: t, x: @bot.xi, y: @bot.yi, dir: @bot.dir)
        duration: 1/bot_speed
      if @step()
        @move_control = next_move_control
        @animation_mode = levelAnimMode.MOVING
        @show_current_command = step_command

  # immediately run this if we switched to MOVING above
  if @animation_mode == levelAnimMode.MOVING
