3. Explanations of Code (continued...)
Line 24 is just a comment to explain what the following lines of code will accomplish.
24 |
// empty space will check if a mouse is willing to come over |
Lines 26 through 33 deal with changing the value of the mouse field to 'M', when it is a neighbor of a cell that is already the mouse. Therefore giving the impression that the mouse is moving. Line 26 starts the condition by stating that the cell in question must have a mouse field with the value of '.' (zero).
Line 27 continues the condition with the first part of the "rotated if". It states the direc field for the cell must have a value of '.' and the neighbor cell must have a direc field value of '^', and it's mouse field value must equal 'M'. The interpretation of this line is basically the cell must not have a direc value set, and the neighbor cell must have a direc value that is pointing at the cell and it must be the mouse. So to say it yet another way. The neighbor cell must be the mouse and must be pointing at the cell in question in order for the cell to change into the mouse.
27 |
rot if (direc=='.' && so:direc=='^' && so:mouse=='M') |
Line 28 is just a comment stating the condition in line 27.
28 |
// a mouse points at me |
Line 29 is the statement that is to be executed when the conditions in lines 26 and 27 are met.
29 |
mouse=so:mouse; //so I copy it over |
Assign the value of the neighbor cell that is the mouse, to this cell. Make "me" the mouse.
Line 30 is the "else" of the rotated if. This will capture all others that do not meet the conditions in line 27.
30 |
else rot if (direc=='.' && no:direc=='d' && no:mouse=='M') |
If the cell in question has a mouse field value of '.' (zero), and a direc value of '.'. But the neighbor has a direc value of 'd' (dead-end) and the neighbor is the mouse, then execute the statement that follows the condition.
Line 31 is a comment that states the mouse needs to be rescued from the dead-end.
31 |
// a mouse needs rescue |
Line 32 is the statement to be executed when the conditions in line 30 are met. Assign the value of the neighbor cell to this cell. Or in other words, make "me" the mouse. Appears as if you are moving the value of the mouse from the neighbor cell into the cell in question.
32 |
mouse=no:mouse; // so I also copy it over |
33 |
} |
And the last line is the close brace to finish the "rotated if" that was started with line 26.