staff project download information miscellaneous
Trend Download   Mouse Maze
  Download

Trend Tutorials
Trend Basics
Game of Life
One Dimensional CA
Mouse Maze
1-D Bubble Sort
Animation


More Trend Examples

 
MangoVect DownloadPicky DownloadLucy2 DownloadGRAMAUBViz DownloadgeneDBN Download
3. Explanations of Code (continued...)

Line 12 continues the "if" that was started in line eight. Line 12 is the first "else" to the condition in line eight. It continues that if the particular cell has the value of 'M' in the mouse field and the cell in the mouse field just above it has a value of '.' (zero), or has a value of 'F' (food) and a direc value of '.' (zero), then execute the statement that follows the condition.

12 else rot if ((no:mouse=='.' || no:mouse=='F') && no:direc=='.')

Line 13 is just a comment explaining the condition in line 12. Saying the cell in the mouse field with a value of 'M' is checking it's neighbors.

13 // check empty neighbors
14 direc='^'; // find one, so set the direction

The statement in line 14 says to assign a value of '^' to the direc field in the cell that meets the condition in line 12. So assign a direction to the neighbor that has a value of '.' for the mouse field or a value of 'F' in the mouse field and '.' in the direc field.

Line 15 is the default for the condition started in line eight. It is the "else" that catches any of the fields that have a value of 'M' in the mouse field, but are not true in the second part of the condition. So if a cell has a value of 'M' in the mouse field, but does not prove true for lines nine and 12, then execute the statement that follows in line 16.

15 else // exhausted all chance, should back track now
16 direc='d'; // so set to dead direction and wait for rescue

Lines 15 and 16 set the value of direc to 'd', to show it has hit a dead end. The mouse can no longer move anywhere other than where it came from because it has reached a dead end. The value of 'd' for the field direc will prevent the mouse from entering the same cell at a later point. There is no reason for the mouse to enter a cell that is a dead end.

Line 17 is a close brace to finish the "if" condition started in line eight.

17 }

Lines 19 through 22 are to find whether the mouse has found the food yet.

19 if (mouse=='F') { //if I am food and mouse found me then I change to 'V'
20 rot if (so:mouse=='M' && so:direc=='^')
21 mouse= 'V';
22 }

Line 19 starts the condition by checking to see if a cell has a value of 'F' in the mouse field. Line 20 goes from there and continues the condition. If a cell has a value of 'F' in the mouse field, then it checks with a "rotated if" whether a neighbor (North, South, East, West) has a value of 'M' in the mouse field and if the neighbor has a value of '^' in the direc field. In other words, if a cell has a value of 'F', it is considered the food. If it is the food, and it has a neighbor that is a mouse, and that mouse is pointing or coming toward the food, then execute the statement. The statement in line 21 says that the cell that is the food is assigned the value of 'V' for victory. Victory is once the food is found by the mouse. Line 22 finishes it with a close brace.


Last modified June 13, 2008 . All rights reserved.

Contact Webmaster

lab