28 #ifndef ELEMENT_REPROVERT_H
29 #define ELEMENT_REPROVERT_H
45 typedef typename CC::ATOM_TYPE T;
46 typedef typename CC::PARAM_CONFIG P;
47 enum { R = P::EVENT_WINDOW_RADIUS };
52 static const u32 STATE_BELOW_IDX = 0;
53 static const u32 STATE_BELOW_LEN = 9;
54 static const u32 STATE_ABOVE_IDX = STATE_BELOW_IDX+STATE_BELOW_LEN;
55 static const u32 STATE_ABOVE_LEN = 9;
56 static const u32 STATE_GAP_IDX = STATE_ABOVE_IDX+STATE_ABOVE_LEN;
57 static const u32 STATE_GAP_LEN = 2;
58 static const u32 STATE_BITS = STATE_GAP_IDX+STATE_GAP_LEN;
60 static const u32 MAX_BELOW = (1<<STATE_BELOW_LEN)-1;
61 static const u32 MAX_ABOVE = (1<<STATE_ABOVE_LEN)-1;
63 u32 GetBelow(
const T &atom, u32 badType)
const {
65 return atom.GetStateField(STATE_BELOW_IDX,STATE_BELOW_LEN);
68 bool SetBelow(T &atom, u32 value)
const {
70 atom.SetStateField(STATE_BELOW_IDX,STATE_BELOW_LEN,value);
74 u32 GetAbove(
const T &atom, u32 badType)
const {
76 return atom.GetStateField(STATE_ABOVE_IDX,STATE_ABOVE_LEN);
79 bool SetAbove(T &atom, u32 value)
const {
81 atom.SetStateField(STATE_ABOVE_IDX,STATE_ABOVE_LEN,value);
85 u32 GetGap(
const T &atom, u32 badType)
const {
87 return atom.GetStateField(STATE_GAP_IDX,STATE_GAP_LEN)+1;
90 bool SetGap(T &atom, u32 value)
const {
92 atom.SetStateField(STATE_GAP_IDX,STATE_GAP_LEN,value-1);
108 void AbstractElement_Reprovert<CC>::ReproduceVertically(EventWindow<CC>& window)
const
110 Random & random = window.GetRandom();
111 T
self = window.GetCenterAtom();
112 s32 gap = GetGap(
self,0);
114 u32 selfType =
self.GetType();
115 s32 belowSelf = GetBelow(
self,0);
116 s32 aboveSelf = GetAbove(
self,0);
117 bool down = random.CreateBool();
118 SPoint repPt(0, down ? gap : -gap);
120 if (!window.IsLiveSite(repPt))
125 T other = window.GetRelativeAtom(repPt);
126 u32 otherType = other.GetType();
128 bool weChanged =
false;
130 if (Element_Empty<CC>::THE_INSTANCE.IsType(otherType)) {
138 SetBelow(newAtom, down || belowSelf==0 ? 0 : belowSelf + 1);
139 SetAbove(newAtom, !down || aboveSelf==0 ? 0 : aboveSelf + 1);
140 window.SetRelativeAtom(repPt, newAtom);
142 }
else if (otherType == selfType) {
143 s32 belowThem = GetBelow(other,0);
144 s32 aboveThem = GetAbove(other,0);
146 if (down && belowThem + 1 != belowSelf) {
147 SetBelow(
self, belowThem + 1);
151 if (!down && aboveThem + 1 != aboveSelf) {
152 SetAbove(
self, aboveThem + 1);
161 if (down && belowSelf > 0 && random.OneIn(10)) {
163 SetBelow(
self, belowSelf);
165 }
else if (!down && aboveSelf > 0 && random.OneIn(10)) {
167 SetAbove(
self, aboveSelf);
173 window.SetCenterAtom(
self);
u32 NoDiffusability(EventWindow< CC > &ew, SPoint nowAt, SPoint maybeAt) const
Definition: Element.h:508
Definition: AbstractElement_Reprovert.h:42
virtual u32 Diffusability(EventWindow< CC > &ew, SPoint nowAt, SPoint maybeAt) const
Definition: AbstractElement_Reprovert.h:99
Definition: ElementTable.h:43