|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectRule
The 31-bit rule represented with the code. Code is implemented with one
integer. Bits are represented as binary integer number. Bit index 0 is the
least significant bit, index 30 is the most significant bit. Handling with
rule is done by the boolean values: true
represents 1 and
false
represents 0.
Field Summary | |
private int |
code
Rule code. |
static int |
RULE_232
Famous 232 rule. |
Constructor Summary | |
Rule()
Creates Rule with zero code. |
|
Rule(int ruleCode)
Creates Rule with the given code. |
|
Rule(Rule rule)
Creates Rule from the specified rule. |
Method Summary | |
private int |
bitIndex(int index)
|
void |
clear(int index)
Set the bit at the specified index to false . |
void |
flip(int index)
Flips the bit at the specified index to represent a negated value. |
static Rule |
generateRandomRule()
Generates a random rule. |
boolean |
get(int index)
|
int |
getCode()
|
Rule |
mutate(double probability)
Mutates (damages) the rule with the specified probability. |
void |
set(int index)
Set the bit at the specified index to true . |
void |
set(int index,
boolean value)
Set the bit at the specified index to the specified value. |
void |
setCode(int ruleCode)
|
java.lang.String |
toString()
|
boolean |
traverse(boolean fifth,
boolean forth,
boolean third,
boolean second,
boolean first)
Traverses the cell's grid with the rule by specifying neighbour cell states and getting the cell's new state. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int RULE_232
private int code
Constructor Detail |
public Rule()
Rule
with zero code.
public Rule(int ruleCode)
Rule
with the given code.
ruleCode
- the rule code.public Rule(Rule rule)
Rule
from the specified rule.
rule
- the rule (null
not permitted).Method Detail |
public static Rule generateRandomRule()
null
not possible).public int getCode()
public void setCode(int ruleCode)
ruleCode
- the rule code.private int bitIndex(int index)
index
- the integer index of the bit.
java.lang.IndexOutOfBoundsException
- if index is not in [0, 30].public boolean get(int index)
index
- the index of the bit (must be [0, 30]).
true
if bit is 1, false
if bit is 0.public void clear(int index)
false
.
index
- the index of the bit (must be [0, 30]).public void set(int index)
true
.
index
- the index of the bit (must be [0, 30]).public void set(int index, boolean value)
index
- the index of the bit (must be [0, 30]).value
- public void flip(int index)
index
- the index of the bit (must be [0, 30]).public Rule mutate(double probability)
probability
- the probability to flip the bit.
null
not possible).public boolean traverse(boolean fifth, boolean forth, boolean third, boolean second, boolean first)
false
.true
=1, false
=0.
fifth
- the state of the neighbour cell (most significant bit).forth
- the state of the neighbour cell (left).third
- the state of the centered cell (actually the observed one).second
- the state of the neighbout cell (right).first
- the state of the neighbour cell (least significant bit).
java.lang.IllegalArgumentException
- if fifth, forth, third, second arguments
are true
, and first is false
. This
represents the last bit index (31) that is not allowed, since the
rule is 31-bit.public java.lang.String toString()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |