void init() { neighbors_.resize(num_sites()); source_.resize(num_bonds()); target_.resize(num_bonds()); site_phase_.resize(num_sites()); bond_phase_.resize(num_bonds()); for (unsigned int s = 0; s < num_sites(); ++s) { int x, y; boost::tie(x, y) = index2xy(s); site_phase_[s] = 2.0 * ((x + y) % 2) - 1.0; for (unsigned int k = 0; k < 4; ++k) { int d = 1- int(k & 2); neighbors_[s][k] = ((k & 1) == 0) ? xy2index(x + d, y) : xy2index(x, y + d); } } for (unsigned int b = 0; b < num_bonds(); ++b) { unsigned int s = b / 2; int x, y; boost::tie(x, y) = index2xy(s); unsigned int t; if (b % 2 == 0) { t = xy2index(x + 1, y); // target right bond_phase_[b] = 2.0 * ((b / 2) % 2) - 1.0; } else { t = xy2index(x, y + 1); // target below bond_phase_[b] = 2.0 * ((b / length_x_ / 2) % 2) - 1.0; } source_[b] = s; target_[b] = t; } }
void init() { source_.resize(num_bonds()); target_.resize(num_bonds()); site_phase_.resize(num_sites()); bond_phase_.resize(num_bonds()); for (unsigned int s = 0; s < num_sites(); ++s) { int x, y; boost::tie(x, y) = index2xy(s); site_phase_[s] = 2 * ((x + y) % 2) - 1; } for (unsigned int b = 0; b < num_bonds(); ++b) { unsigned int s = b / 2; int x, y; boost::tie(x, y) = index2xy(s); unsigned int t; if (b % 2 == 0) { t = xy2index(x + 1, y); // target right bond_phase_[b] = 2.0 * ((b / 2) % 2) - 1.0; } else { t = xy2index(x, y + 1); // target below bond_phase_[b] = 2.0 * ((b / length_x_ / 2) % 2) - 1.0; } source_[b] = s; target_[b] = t; } }
static uint32_t countPaths(btstring_t *data, int32_t x, int32_t y) { uint32_t rval = 0; if (x > 0) { if (isPath(data->buf[xy2index(x - 1, y)])) { rval++; } } if (y > 0) { if (isPath(data->buf[xy2index(x, y - 1)])) { rval++; } } if (y < 15) { if (isPath(data->buf[xy2index(x, y + 1)])) { rval++; } } if (x < 15) { if (isPath(data->buf[xy2index(x + 1, y)])) { rval++; } } return rval; }
static void convertPath(btstring_t *data, int32_t x, int32_t y) { uint32_t index; uint32_t i; int32_t saveX, saveY; uint32_t numPaths; index = xy2index(x, y); data->buf[index] = 0xff; while (countPaths(data, x, y) == 1) { move(data, &x, &y); data->buf[xy2index(x, y)] = 0xff; } if (!countPaths(data, x, y)) { return; } saveX = x; saveY = y; numPaths = countPaths(data, x, y); for (i = 0; i < numPaths; i++) { move(data, &x, &y); convertPath(data, x, y); x = saveX; y = saveY; } }
static void move(btstring_t *data, int32_t *x, int32_t *y) { if (*x > 0) { if (isPath(data->buf[xy2index(*x - 1, *y)])) { *x = *x - 1; return; } } if (*y > 0) { if (isPath(data->buf[xy2index(*x, *y - 1)])) { *y = *y - 1; return; } } if (*x < 15) { if (isPath(data->buf[xy2index(*x + 1, *y)])) { *x = *x + 1; return; } } if (*y < 15) { if (isPath(data->buf[xy2index(*x, *y + 1)])) { *y = *y + 1; return; } } }
// doing this twice should be like a nop void invert_screen(termstate_t *term) { int x, y; int fg, bg, in; // swap fg and bg for all chars for (y = 0; y < term->phys_h; y++) for (x = 0; x < term->w; x++) { unpack_attribs(term->attrib[xy2index(term, x, y)], &fg, &bg, &in); term->attrib[xy2index(term, x, y)] = pack_attribs(bg, fg, in); } }
unsigned int neighbor(unsigned int s, unsigned int k) const { int x, y; boost::tie(x, y) = index2xy(s); int d = 1- 2 * (k & 1); return (k & 2) ? xy2index(x + d, y) : xy2index(x, y + d); }