2. Examining the Rule (continued)
The first two lines are the initialization of the fields. Cell and ctrl are the fields in this example.
1 |
default cell=cell;// has values of 0,1,2 and . |
2 |
default ctrl=ctrl;// value will be assigned when you choose the symbol |
|
Lines one and two basically say that a field (either cell or ctrl) should keep it's value if there are no statements that affect the value according to the rule.
Lines four, five and six are comments to show that the next portion of the code are going to be related to the declarations.
4 |
/*******************************************************************************/ |
5 |
/*************************DECLARATIONS*************************************/ |
6 |
/*******************************************************************************/ |
Line eight is declaring an integer with the name "sum". This integer is used later in the code. It could have been declared just prior to it's use, but it is common to group all the declarations.
8 |
int sum; // initialize integer named "sum" |
Line nine is also a declaration. It is declaring an integer named "table". This is an array that is used later in the code.
9 |
int table[]={0, 0, 2, 0, 2, 0, 1}; //initialize integer named "table" |
The next three lines are again just comments to show the next portion of code are going to be related to a particular action.
11 |
/*******************************************************************************/ |
12 |
/************Code to Perform the Movement From Left to Right*********************/ |
13 |
/*******************************************************************************/ |
The lines below express a compound condition for the ctrl fields. If this field has a ctrl value of 0 (zero), and the ctrl field to the left has a value of something other than 0, then assign the value of the ctrl to the left to the current ctrl less one. Basically saying if this one is "dead", and the one to it's left is "alive", make this one "alive" with a value of the one to the left minus one.
15 |
if (ctrl==0 && left:ctrl) // if CTRL is nothing and LEFT CTRL is "alive" |
16 |
ctrl=left:ctrl-1;//assign CTRL the value LEFT CTRL -1 |
|