void image::insert_tile_with_border(int32_t x, int32_t y, uint32_t width, uint32_t height, const image& other, uint32_t x1, uint32_t x2, uint32_t y1, uint32_t y2) { uint32_t x3 = other.width; uint32_t y3 = other.height; uint32_t w1 = x1-0; uint32_t w2 = x2-x1; uint32_t w3 = x3-x2; uint32_t h1 = y1-0; uint32_t h2 = y2-y1; uint32_t h3 = y3-y2; image sub; insert_sub(x, y, other, 0, 0, x1, y1); // top left sub.init_ref_sub(other, x1, 0, w2, h1); insert_tile(x+x1, y, width-w1-w3, h1, sub); // top insert_sub(x+width-w3, y, other, x2, 0, w3, y1); // top right sub.init_ref_sub(other, 0, y1, w1, h2); insert_tile(x, y+y1, w1, height-h1-h3, sub); // left sub.init_ref_sub(other, x1, y1, w2, h2); insert_tile(x+x1, y+y1, width-w1-w3, height-h1-h3, sub); // middle sub.init_ref_sub(other, x2, y1, w3, h2); insert_tile(x+width-w3, y+y1, w3, height-h1-h3, sub); // right insert_sub(x, y+height-h3, other, 0, y2, x1, h3); // bottom left sub.init_ref_sub(other, x1, y2, w2, h3); insert_tile(x+x1, y+height-h3, width-w1-w3, h3, sub); // bottom insert_sub(x+width-w3, y+height-h3, other, x2, y2, w3, h3); // bottom right }
int solve_rec(struct shape *board, const struct puzzle *p, int current_tile) { int x, y; const struct shape *current_shape; if (current_tile == p->no_tiles) { /* * Found solution */ printf("Solution:\n"); dump_board(board, 0); dump_board_svg(board); printf("\n"); return (0); } current_shape = &p->tiles[current_tile]; for (y = 0; y < board->height - current_shape->height + 1; y++) { for (x = 0; x < board->width - current_shape->width + 1; x++) { if (can_insert_tile(board, &p->tiles[current_tile], x, y)) { insert_tile(board, current_tile + 1, &p->tiles[current_tile], x, y); solve_rec(board, p, current_tile + 1); remove_tile(board, current_tile + 1); } } } return (0); }
// lod_offset: how much above nominal LOD this node is. void load_node(oct_node node, game_data * game_data, int lod_offset){ if(ht_lookup(game_data->loaded_nodes, &node)) return; i64 hash = get_hash(node, game_data->hashed_node, game_data); srand(hash); logd("%p ", hash); logd("Loading node.. %i %p\n", node.ptr2, hash); int val = 0; ht_insert(game_data->loaded_nodes, &node, &val); int size = 1; for(int i = lod_offset; i> 0; i--){ node = oct_get_sub(node, 0); size *= 2; } for(int i = 0; i < size; i++) for(int j = 0; j < size; j++){ insert_tile(node, vec3i_make(i, 0, j), rand()&1); if(rand() % 16 == 0){ insert_tile(node, vec3i_make(i, 1, j), GD_TREE_1); insert_tile(node, vec3i_make(i, 2, j), GD_TREE_2); insert_tile(node, vec3i_make(i, 3, j), GD_TREE_3); for(int k1 = -1; k1 <= 1; k1++) for(int k2 = -1; k2 <= 1; k2++) insert_tile(node, vec3i_make(i + k1, 4, j + k2), GD_FOILAGE); insert_tile(node, vec3i_make(i, 5, j), GD_FOILAGE); }else if(rand() % 4000 == 0){ insert_entity(node, vec3mk(i, 1, j), vec3mk(1, 1, 1), GD_FIREPLACE); }else if(rand() % 2000 == 0){ entity * n2 = insert_entity(node, vec3mk(i, 1, j), vec3mk(1, 1, 1), (rand() & 1) == 0 ? GD_BUG : GD_CAT); int unused_1; ht_insert(game_data->enemies, &n2, &unused_1); } } }