76 unsigned long age = millis() -
birthday;
90#ifdef DEBUG_ADVANCEMENT
91 Serial.print(
"Ripple ");
93 Serial.println(
" advancing:");
102#ifdef DEBUG_ADVANCEMENT
103 Serial.print(
" Picking direction out of node ");
105 Serial.print(
" with agr. ");
109 int newDirection = -1;
111 int sharpLeft = (
position[1] + 1) % 6;
112 int wideLeft = (
position[1] + 2) % 6;
113 int forward = (
position[1] + 3) % 6;
114 int wideRight = (
position[1] + 4) % 6;
115 int sharpRight = (
position[1] + 5) % 6;
122 while (newDirection < 0) {
126 if (forwardConnection < 0) {
128#ifdef DEBUG_ADVANCEMENT
129 Serial.println(
" Can't go straight - picking more agr. path");
134#ifdef DEBUG_ADVANCEMENT
135 Serial.println(
" Going forward");
137 newDirection = forward;
145 if (leftConnection >= 0 && rightConnection >= 0) {
146#ifdef DEBUG_ADVANCEMENT
147 Serial.println(
" Turning left or right at random");
149 newDirection = random(2) ? wideLeft : wideRight;
151 else if (leftConnection >= 0) {
152#ifdef DEBUG_ADVANCEMENT
153 Serial.println(
" Can only turn left");
155 newDirection = wideLeft;
157 else if (rightConnection >= 0) {
158#ifdef DEBUG_ADVANCEMENT
159 Serial.println(
" Can only turn right");
161 newDirection = wideRight;
164#ifdef DEBUG_ADVANCEMENT
165 Serial.println(
" Can't make wide turn - picking more agr. path");
175 if (leftConnection >= 0 && rightConnection >= 0) {
176#ifdef DEBUG_ADVANCEMENT
177 Serial.println(
" Turning left or right at random");
179 newDirection = random(2) ? sharpLeft : sharpRight;
181 else if (leftConnection >= 0) {
182#ifdef DEBUG_ADVANCEMENT
183 Serial.println(
" Can only turn left");
185 newDirection = sharpLeft;
187 else if (rightConnection >= 0) {
188#ifdef DEBUG_ADVANCEMENT
189 Serial.println(
" Can only turn right");
191 newDirection = sharpRight;
194#ifdef DEBUG_ADVANCEMENT
195 Serial.println(
" Can't make tight turn - picking less agr. path");
207 for (
int i = 1; i < 6; i++) {
208 int possibleDirection = (
position[1] + i) % 6;
211 newDirection = possibleDirection;
216#ifdef DEBUG_ADVANCEMENT
217 Serial.println(
" Turning as rightward as possible");
221 for (
int i = 5; i >= 1; i--) {
222 int possibleDirection = (
position[1] + i) % 6;
225 newDirection = possibleDirection;
230#ifdef DEBUG_ADVANCEMENT
231 Serial.println(
" Turning as leftward as possible");
235#ifdef DEBUG_ADVANCEMENT
236 Serial.print(
" Leaving node ");
238 Serial.print(
" in direction ");
239 Serial.println(newDirection);
247#ifdef DEBUG_ADVANCEMENT
248 Serial.print(
" and entering segment ");
253#ifdef DEBUG_ADVANCEMENT
254 Serial.println(
" (starting at bottom)");
260#ifdef DEBUG_ADVANCEMENT
261 Serial.println(
" (starting at top)");
274#ifdef DEBUG_ADVANCEMENT
275 Serial.print(
" Reached top of seg. ");
281 for (
int i = 0; i < 6; i++) {
285 if (incomingConnection == segment)
288#ifdef DEBUG_ADVANCEMENT
289 Serial.print(
" Entering node ");
291 Serial.print(
" from direction ");
297#ifdef DEBUG_ADVANCEMENT
298 Serial.print(
" Moved up to seg. ");
300 Serial.print(
" LED ");
311#ifdef DEBUG_ADVANCEMENT
312 Serial.print(
" Reached bottom of seg. ");
318 for (
int i = 0; i < 6; i++) {
322 if (incomingConnection == segment)
325#ifdef DEBUG_ADVANCEMENT
326 Serial.print(
" Entering node ");
328 Serial.print(
" from direction ");
334#ifdef DEBUG_ADVANCEMENT
335 Serial.print(
" Moved down to seg. ");
337 Serial.print(
" LED ");
356#ifdef DEBUG_ADVANCEMENT
357 Serial.print(
" Age is now ");
365#ifdef DEBUG_ADVANCEMENT
366 Serial.println(
" Lifespan is up! Ripple is dead.");