ChompMan Commands

This document explains how each command works in the game script. Some of these commands have associated buttons, which may behave slightly differently from the scripted version, hopefully in reasonable ways (as explained). Some of these commands can only be used in a script. With a few obvious exceptions, most of these commands also can be typed in the Command entry and executed directly -- but of course they also enter into the script.

Contents:

Nibbler Navigation

Right
Down
Left
Up
Ahead
Cwise = Clockwise
Acwise = Anti-clockwise

Variables

Let
Expressions

Game Control

Reset
DoAll
Slow
Fast
Skill
Save
Reload
LogIn

Sequence Control

Repeat
Next
Exit
If
Else

I/O

See (wall or pill)
Smell (pills)

Build Maze

Wall
Pill
Start
Spiral

Nibbler Navigation

These commands correspond to the four arrow buttons in the lower right corner of the game panel.

Right

This command takes a single non-negative number as a parameter, then turns the nibbler to face right (east, if you think of the top as north) then moves as many steps in that direction (possibly zero) as specified, or until the nibbler hits a wall. Steps to the right are shown as '0' in the pending nibbler queue at the bottom of the game board, when that is visible. Any pills along the path travelled are consumed and the score increased accordingly. The button is always a single step.

Down

This command takes a single non-negative number as a parameter, then turns the nibbler to face down (south, if you think of the top as north) then moves as many steps in that direction (possibly zero) as specified, or until the nibbler hits a wall. Steps down are shown as '1' in the pending nibbler queue at the bottom of the game board, when that is visible. Any pills along the path travelled are consumed and the score increased accordingly. The button is always a single step.

Left

This command takes a single non-negative number as a parameter, then turns the nibbler to face left (west, if you think of the top as north) then moves as many steps in that direction (possibly zero) as specified, or until the nibbler hits a wall. Steps to the left are shown as '2' in the pending nibbler queue at the bottom of the game board, when that is visible. Any pills along the path travelled are consumed and the score increased accordingly. The button is always a single step.

Up

This command takes a single non-negative number as a parameter, then turns the nibbler to face up (north, if you think of the top as north) then moves as many steps in that direction (possibly zero) as specified, or until the nibbler hits a wall. Steps up are shown as '3' in the pending nibbler queue at the bottom of the game board, when that is visible. Any pills along the path travelled are consumed and the score increased accordingly. The button is always a single step.

Ahead

This command takes a single non-negative number as a parameter, then moves the nibbler that many steps in whatever direction it was facing, or until the nibbler hits a wall. Any pills along the path travelled are consumed and the score increased accordingly.

Cwise = Clockwise

This command takes a single non-negative number as a parameter, then turns the nibbler to face 90o to the right (clockwise) of where it was previously facing then moves as many steps in that direction (possibly zero) as specified, or until the nibbler hits a wall. Any pills along the path travelled are consumed and the score increased accordingly. Note that the resulting direction depends on which direction the nibbler is facing when this command is executed. If there are pending nibbler steps, the nibbler will advance through them before deciding which new direction to go.

Acwise = Anti-clockwise

This command takes a single non-negative number as a parameter, then turns the nibbler to face 90o to the left (counter-clockwise) of where it was previously facing then moves as many steps in that direction (possibly zero) as specified, or until the nibbler hits a wall. Any pills along the path travelled are consumed and the score increased accordingly. Note that the resulting direction depends on which direction the nibbler is facing when this command is executed. If there are pending nibbler steps, the nibbler will advance through them before deciding which new direction to go.

Game Control

These commands correspond to the five buttons in the upper right corner of the game panel.

Reset

The Reset command always repositions the nibbler at the specified starting location and direction and cancels any partial maze construction and incomplete server operation (like a Reload) and Slow mode. When it is the first line in the script or the button is clicked, it also clears all variables and the score to zero and restores any previously eaten pills.

If the Reset button is clicked a second time without doing something else in between, the script is also erased, and if you have changed the maze, the second Reset click will also revert to the default.

DoAll

The DoAll button runs the current script from the top after effectively doing a Reset action. When scripted, the DoAll command will also cancel any outstanding repeat loops before restarting the script at the top with everything Reset. A DoAll at the front of your script renders the script inoperable. Typing this command into the command line only enters it into your script; it does not also do it.

Slow

Except when it is waiting for the nibbler to complete its pending steps before advancing more, the script execution runs along at about ten lines per second (faster when skipping), which can be too fast to watch in real time. The Slow command slows the execution time down to one step per second (and skipping is slowed to ten per second) for subsequent steps, until the end of the script or Fast or Reset. If you speed up the nibbler using a Fast command, Slow will reduce it back to the normal rate.

Fast

The Fast command cancels a previous Slow command, and resumes running at full speed. Additional Fast commands speed up (double) the nibbler motion so it can run around the maze faster.

Skill

The Skill command lets you specify from the command line what skill level you wish to be operating at. Normally this starts out at level 0 and advances to +8 (the "expert" nibbler, which is colored orange) when the nibbler completes a maze with a score greater than 99 and at least one longer run without hitting a wall. After you complete the browser-based game segment and advanced into the introductory Java segment of this website, the skill number advances to +64, which puts at the top of the index page a link to a (Java as well as web-based) site map, previously omitted to ward off beginner confusion.

The skill level (however acquired) is preserved in a cookie on the local computer, and also in whatever server Save accounts you know the full user name of, so it is restored to your computer when you LogIn with Save access and download the script there.

Save

The Save command or button saves the current script on whatever account you are currently logged into and/or as a cookie on your local computer.

Reload

The Reload command or button replaces the current script with whatever script was most recently Saved on the account you are currently logged into, or else from a previously saved script in the local computer's cookie (if any). When scripted, the Reload command will also effectively do a DoAll command to restart the newly loaded script from the top. Combined with a scripted LogIn command, this enables you to link multiple scripts into continuous operation. Typing this command into the command line only enters it into your script; it does not also do it.

LogIn

The LogIn command or button logs you into a specified server account. The button asks you for a user name and to specify if this is a new account or not. The scripted command should be given a valid account name as a parameter, or if none is specified, it will cancel the current login. If the account name specified is invalid or unknown by the server, the script terminates in error. Typing this command into the command line enters it into your script, and it is the only way (that is, when it is a running script, or you completely reload the web page) to log out of the server.

Variables

Variables give your script the ability to set up parameters in one place, then use those parameters in other parts of your script. The variables in this implementation are always (positive or negative or zero) integers, and you can do simple arithmetic and comparisons on these variables to form new values dependent on the component variables and numbers.
 

Let

The Let command defines a new value for one of 26 variables named by the 26 letters of the alphabet. The form of the command is
let x = value
where "value" can be any valid combination of numbers and variables separated by arithmetic operators and/or grouped by parentheses.

After variables have been explained in the text, the game board will show all the known variable values in tiny numbers along the top edge of the game board (see Help panel).
 

Expressions

Most of the commands that take parameters can also accept values made up from variables and numbers and operators and called expressions according to the following rules:

1. Any number is a value.

2. Any variable is a value.

3. Any (value) enclosed in parentheses is a value, which is evaluated first before applying other operators.

4. Any value + another value is a value, the sum of them.

5. Any value - another value is a value, the (subtract) difference.

6. Any value * another value is a value, the (multiply) product of them.

7. Any value / another value is a value, the (divide) quotient of them, unless the second value is zero, which stops your script.

8. Any value can be compared (less < than, equal = to, or greater > than) another value, and if the comparison result is TRUE it is a value 1, and if the comparison is FALSE it is a value 0. Normally you would use these results to decide whether to do the next command line (TRUE) or skip it (FALSE) (see If), but they are numbers which you can also put into variables and/or combine with other values.

9. Any value & another value is a value, the logical AND of them. Each bit of the first value is matched against the corresponding bit of the other value, and if both bits are one, the corresponding bit of the result is one, otherwise it is zero. When applied to the results of comparisons (or other logical operations) the result is TRUE only if both comparisons are TRUE, otherwise FALSE.

10. Any value | another value is a value, the logical OR of them. Each bit of the first value is matched against the corresponding bit of the other value, and if both bits are zero, the corresponding bit of the result is zero, otherwise it is one. When applied to the results of comparisons (or other logical operations) the result is FALSE only if both comparisons are FALSE, otherwise TRUE.

11. Any three values connected by two operators, multiplication and division are done before addition and subtraction, which are done before logical operations, which are done before comparison; otherwise the operations are calculated in left-to-right order. Any value inside parentheses is completely evaluated before operators outside the parentheses are applied.

Suppose in your script

let P = 3
let X = 11
let A = X+P // A=14
let B = X-P // B=8
let C = X*P // C=33
let D = X/P // D=3 (the fraction is discarded)
let E = P-X // E=-8 (a negative number)
let F = E+B // F=0
let G = C-P*4 // G=21 {G=33-(3*4)=33-12, multiply before subtract}
let H = C*P-4 // H=95 {H=(33*3)-4=99-4, multiply before subtract}
let I = C*(P-4) // I=-33 {I=33*(3-4)=33*(-1), inside parens first}

Sequence Control

The most powerful quality of computer programming is that you get to tell the computer not only what order to do things in, but also when to change that sequence on the fly. There are two ways to do this, iteration (repeating the same steps multiple times) and conditions (doing one or more steps only if a certain condition is true). Like expressions, you can combine these in powerful and complex ways.

Repeat

The Repeat command takes a single parameter, the number of times to repeat everything up to the Next command. If there is no matching Next command, the script stops with an error. You can nest up to six repeats.
All the command lines following a Repeat command, up to and including its terminal Next command, are indented one space in the listing. This gives a visual indication of what is being repeated.

Next

The Next command tells the game engine to go back to the beginning of the current active Repeat to do the next iteration. After the specified number of iterations complete, the next line of the script after the Next command is executed. There is a tiny indication of the active repeats and the remaining number of times to run and tie first line number of the loop in the lower left corner of the game board after the main text explains them.

Exit

The Exit command will terminate the current active Repeat immediately and resume after the corresponding Next command, or stop with an error if there is none. This command only makes sense following an If command (or its corresponding Else command), for getting out of Repeat sooner than expected.

If

The If command takes as a parameter a value compared to another value as = (equal) or < (less) or > (greater), and if the comparison is TRUE (or non-zero), the next command is executed. If the comparison is FALSE (or zero), that command is skipped, along with all it involves -- for example, if the next command is a Repeat then everything up to and including its corresponding Next is skipped.
The command line following an If command -- if that is another If command, then that includes also the line it controls and its else (if present); if the conditional command is a Repeat command, then all the lines up to and including its terminal Next command -- are indented an extra space in the listing. This gives a visual indication of what is controlled by this conditional.

Else

The Else command must follow immediately after whatever command or sequence of commands is controlled by an If command, and it reverses the condition, that is, if the command following the If condition is TRUE (and its following command is executed) then the command following the Else is skipped; if the If condition is FALSE, then the command following the Else is executed.

For example, in the script,

let A=2
if A<2
 repeat A
  left A
  next
else
 right 6
Variable A is not less than 2, so the entire Repeat sequence is skipped and the Else activates the "right 6" command. On the other hand, if you "let A=1" at the front, then the If-condition is true, and the Repeat sequence is activated, and it does the "left A" exactly once and the nibbler moves left one step, and not right at all (because the Else command and its following line was skipped).

I/O

See (wall or pill)

This command takes the name of a variable as its parameter, and puts into that variable the distance in grid cells to either a wall or a pill (whichever is closer) in the direction the nibbler is facing, or else zero if the nibbler is facing off the edge of the game board. If it's a wall the number is negative. You can use if commands to decide whether to move the nibbler that direction to eat the pill or otherwise to avoid bumping into a wall.

Smell (pills)

This command takes the name of a variable as its parameter, and puts into that variable a number representing the sum and distance to pills that can be reached by moving at least one step in the direction the nibbler is facing without retracing. If the see command would return a positive value (that is, there is a pill visible in front of the nibbler, then the result is the number of cells forward to eat the last pill in that direction, which will always be less than the size of the game board (25).

If there are no pills visible in the direction the nibbler is facing, but there are one or more pills that can be reached starting off in that direction without retracing the current position, then the result is a number representing the number of such pills, divided by their relative distances, times 256 plus 32. This command can "smell" around corners, but it cannot smell through walls and the smell must come from the front: pills that can only be reached by moving backwards or to one side or the other of the nibbler can only be smelled when facing that direction. It will miss pills that are fully enclosed within walls with no open path through, and to get a complete status the nibbler must smell in each of the four compass directions.

The Smell command is a little tricky to understand. If the first thing you do after starting in the default maze is smell N then variable N will be set to six because there are some pills in front of the nibbler, and if you move left N or left 6 you will eat all of them. If you move left 5 and then right 6 and then left 1 you will be back at the starting place with five of those pills eaten (as well as one behind the nibbler), and then do a smell N you still get a result 6 in N because it will still take a left 6 to eat that one remaining visible pill. For an example with explanation, see the test maze here.

For the Smell command to work properly, it must wait until all pending nibbler moves have completed. If the script is running fast then some of the commands can execute while the nibbler is still plodding along (albeit faster than normal). This may look strange but is generally not a problem; however you can use the Smell command (and ignore the result) whenever you want the nibbler and code to "sync up" (become synchronized) at that point in your script.

Build Maze

The almost-ultimate game control is to define your own game board. If you use any of these four commands, the game goes into a build-game mode, which ends when you specify the Starting position of the nibbler or some navigation command. Then the whole maze is rebuilt to your specification, and the game proceeds from there. Reloading the web page or clicking on the Reset button twice reverts to the default maze. The positions of the walls, pills, and nibbler are specified in grid coordinates between 1 and 23. When you get to this stage of your skills, you will see grid numbers along the top and left edges of your game board, or look in the Game Help). The Reset command cancels any partial maze construction.

Wall

This command lets you specify one wall segment. It takes three parameters separated by commas: a vertical cell position then a horizontal cell position for the top cell of this wall, then the (positive) number of vertical or (negative) number of horizontal cells the wall covers.

To build a new maze, you should start giving Wall commands, and Chomp will accumulate all the Wall and Pill commands, and then actually build the maze when you give the Start command.

Pill

This command lets you specify one run of pills. It takes three parameters separated by commas: a vertical cell position then a horizontal cell position for the top cell of this run, then the (positive) number of vertical or (negative) number of horizontal cells this run specifies pills for.

Pill commands do not take effect immediately, but are collected with Wall commands, then the maze is built when you give a Start command, but you need at least one Wall command to build a new maze. If you neglect to specify any pills, Chomp will continue to use the pills from the previous maze.

Start

This command lets you specify the (initial) position and facing direction of the nibbler. Normally it is used with wall and pill specifications, and terminates an open maze specification. The first two parameters specify the grid coordinates of the nibbler, and the third coordinate is a number from 0 to 3 which specifies the direction the nibbler initially faces, 0=right, 1=down, 2=left, and 3=up.

After at least one Wall command, the Start command will discard the current maze and build a new maze from the accumulated Wall and Pill commands.

Spiral

The original PakMan maze is designed to be difficult to pick up all the pills. I decided it would be easier to learn about the Repeat command if the maze were more regular, so I created a spiral that you can traverse the whole maze with a 4-line script. The single Spiral command in the first line of your script loads the whole maze in.


Rev. 2020 February 21