bool G2048::move_up(){ bool moved = false; for (size_t j = 0; j < 4; ++j){ for (size_t i = 0; i < 4; ++i){ if (!game[i][j]){ size_t t = up_swap(i, j); if (game[t][j]){ swap(game[i][j], game[t][j]); moved = true; } } } } if (up_add()){ move_up(); moved = true; } if (moved) return true; else return false; }
int up_generate(struct rde_peer *peer, struct rde_aspath *asp, struct bgpd_addr *addr, u_int8_t prefixlen) { struct update_attr *ua = NULL; struct update_prefix *up; if (asp) { ua = calloc(1, sizeof(struct update_attr)); if (ua == NULL) fatal("up_generate"); if (up_generate_attr(peer, ua, asp, addr->aid) == -1) { log_warnx("generation of bgp path attributes failed"); free(ua); return (-1); } /* * use aspath_hash as attr_hash, this may be unoptimal * but currently I don't care. */ ua->attr_hash = hash32_buf(ua->attr, ua->attr_len, HASHINIT); if (ua->mpattr) ua->attr_hash = hash32_buf(ua->mpattr, ua->mpattr_len, ua->attr_hash); } up = calloc(1, sizeof(struct update_prefix)); if (up == NULL) fatal("up_generate"); up->prefix = *addr; up->prefixlen = prefixlen; if (up_add(peer, up, ua) == -1) return (-1); return (0); }