void wordtostate(Word_t s, int bump, bstate state) { char stack[MAXSTATEWIDTH]; int sp,i,type,leftcolor; cell *sti; leftcolor = SENTI(s); // sentinel sti = &state[0]; for (i = sp = 0; i < statewidth; sti++, i++) { sti->type = type = (s >> (3*i)) & 7; sti->left = sti->right = i; if (ISNEEDY(type)) { sti->needycolor = leftcolor ^ COLOR; // assume opposite color if (type & HASL) { if (!sp) { printf("sp=0! i=%d s=%3lo bump=%d\n",i, s, bump); exit(0); } sti->right = state[sti->left = stack[--sp]].right; state[sti->left].right = state[sti->right].left = i; sti->needycolor ^= (sti->left == i-1); // check color assumption } if (type & HASR) stack[sp++] = i; if (i == bump) sti->needycolor = BLACK; // color normalization leftcolor = sti->needycolor; } else leftcolor = type & 1; } if (sp) { printf("sp=%d s=%3lo bump=%d\n",sp, s, bump); exit(0); } }
int wordtostate(uint64_t s, int bump, bstate state) { int stack[MAXSTATEWIDTH]; // holds pairs of (groupleftend,grouprightend) int sp,i,type,leftcolor; // at most statewidth ends on stack cell *sti; leftcolor = SENTI(s); // sentinel for (sti = &state[i = sp = 0]; i < statewidth; sti++, i++) { sti->type = type = s & 7; s >>= 3; if (ISNEEDY(type)) { sti->color = leftcolor ^ COLOR; // assume opposite color if ((type & HASL) && i) { state[sti->left = stack[--sp]].right = i; // extend group if (sti->left == i-1) // assumption was wrong sti->color = leftcolor; } else stack[sp++] = i; // new left end if (type & HASR) stack[sp++] = i; // new right end else state[sti->right = stack[--sp]].left = i; // connect ends if (i == bump) sti->color = WHITE; // color normalization leftcolor = sti->color; } else leftcolor = type & COLOR; } return sp==0; }