Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
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 finalstate(bstate state)
{
  int i;

  for (i = 0; i < statewidth; i++)
    if (ISNEEDY(state[i].type))
      return 0;
  return 1;
}
char *showstate(bstate state)
{
  static char buffers[NSHOWBUF][MAXSTATEWIDTH+1],*buf; // +1 for '\0'
  static int bufnr = 0;
  int type,i,ngroups[2];
                                                                                
  buf = buffers[bufnr++];
  if (bufnr == NSHOWBUF)
    bufnr = 0; // buffer rotation
  for (i = ngroups[0] = ngroups[1] = 0; i < statewidth; i++) {
    type = state[i].type;
    if (!ISNEEDY(type))
      buf[i] = CELLCHARS[type];
    else if (state[i].left < i)
      buf[i] = buf[state[i].left];
    else buf[i] = "Aa"[type&COLOR] + ngroups[type&COLOR]++;
  }
  buf[statewidth] = '\0';
  return buf;
}
Ejemplo n.º 5
0
char *showstate(Word_t s, int bump)
{
  static char buffers[NSHOWBUF][MAXSTATEWIDTH+1],*buf; // +1 for '\0'
  static int bufnr = 0;
  int nc,type,i,ngroups[2];
  bstate state;
  Word_t decode(Word_t, int);
                                                                                
  s = decode(s, bump);
  wordtostate(s, bump, state);
  buf = buffers[bufnr++];
  if (bufnr == NSHOWBUF)
    bufnr = 0; // buffer rotation
  for (i = ngroups[0] = ngroups[1] = 0; i < statewidth; i++) {
    type = state[i].type;
    if (!ISNEEDY(type))
      buf[i] = CELLCHARS[type];
    else if (type & HASL)
      buf[i] = buf[state[i].left];
    else { nc= state[i].needycolor; buf[i] = "Aa"[nc] + ngroups[nc]++; }
  }
  buf[statewidth] = '\0';
  return buf;
}
Ejemplo n.º 6
0
Word_t liberatecell(Word_t t, bstate state, int x)
{
  return ISNEEDY(state[x].type) ?
    mustliberatecell(t, state, x, state[x].needycolor) : t;
}
void liberatecell(bstate state, int x)
{
  if (ISNEEDY(state[x].type))
    mustliberatecell(state, x, state[x].type + LIBSTONE-NEEDY);
}
Ejemplo n.º 8
0
uint64_t liberatecell(uint64_t t, bstate state, int x)
{
  return ISNEEDY(state[x].type) ?
    mustliberatecell(t, state, x, state[x].color) : t;
}