diff options
author | jonsykkel <jonrevold@gmail.com> | 2020-10-25 01:33:28 +0200 |
---|---|---|
committer | jonsykkel <jonrevold@gmail.com> | 2020-10-25 01:33:28 +0200 |
commit | f4871a1af2da53589fc49207cca86bb6ad269bad (patch) | |
tree | aeeacbf92f3471189f9adabd4d66aa2456e98974 | |
parent | 48909d70e121bd07a0537b599275ad8fb2b78054 (diff) | |
download | mindustry_solver-f4871a1af2da53589fc49207cca86bb6ad269bad.tar.gz |
border
-rw-r--r-- | src/main.c | 58 |
1 files changed, 34 insertions, 24 deletions
@@ -76,20 +76,26 @@ static void cell_init(cell_t *c,char s){ static void map_alloc(map_t *map,size_t width,size_t height,char const *init){ size_t drill_max; size_t size; + size_t pad; - map->width = width; - map->height = height; - size = width*height; + pad = (DRILL_DIM_MAX-1); + map->width = width+pad*2; + map->height = height+pad*2; + size = map->width*map->height; map->cell = malloc(sizeof(cell_t)*size); if(!map->cell) fail(); for(size_t y = 0;y < height;y++){ for(size_t x = 0;x < width;x++){ char s = STR_CELL(init,width,x,y); - cell_t *c = MAP_CELL(map,x,y); + cell_t *c = MAP_CELL(map,x+pad,y+pad); cell_init(c,s); } } - drill_max = (width/DRILL_DIM_MIN)*(height/DRILL_DIM_MIN); + for(size_t x = 0;x < map->width;x++) cell_init(MAP_CELL(map,x, 0 ),' '); + for(size_t x = 0;x < map->width;x++) cell_init(MAP_CELL(map,x, map->height-1),' '); + for(size_t y = 0;y < map->height;y++) cell_init(MAP_CELL(map,0, y ),' '); + for(size_t y = 0;y < map->height;y++) cell_init(MAP_CELL(map,map->width-1,y ),' '); + drill_max = (map->width/DRILL_DIM_MIN)*(map->height/DRILL_DIM_MIN); map->drill = malloc(sizeof(drill_t)*drill_max); map->drill_cnt = 0; map->ore_cnt = 0; @@ -102,8 +108,13 @@ static void map_print(map_t *map){ switch(c->type){ case CELL_TYPE_GROUND: putc(' ',stdout); break; case CELL_TYPE_ORE: putc('o',stdout); break; - case CELL_TYPE_DRILL: putc('D',stdout); break; - default: fail(); + case CELL_TYPE_DRILL:; + drill_t *d = &map->drill[c->drill_index]; + if(d->x == x && d->y == y) putc('0'+d->dim,stdout); + else putc('D',stdout); + break; + default: + fail(); } } putc('\n',stdout); @@ -150,9 +161,10 @@ static void map_drill_add(map_t *map,size_t x,size_t y,size_t dim,size_t ore){ } drill_t *drill; - drill = &map->drill[map->drill_cnt]; - drill->x = x; - drill->y = y; + drill = &map->drill[map->drill_cnt]; + drill->x = x; + drill->y = y; + drill->dim = dim; map->drill_cnt++; map->ore_cnt += ore; @@ -257,21 +269,18 @@ static int map_drill_auto(map_t *map,size_t dim){ int main(int argc,char **argv){ map_t map; - /* - map_alloc(&map,18,12, " " - " o " - " oo oo oooo " - " oo oo ooooo " - " oooooo " - " ooooooooooo " - " ooooooooooooo " - " ooooooooooooo " - " ooooooooooooo " - " oooooooooo " - " ooooo " - " "); - */ + map_alloc(&map,16,10, " o " + " oo oo oooo" + " oo oo ooooo" + " oooooo" + " ooooooooooo " + " ooooooooooooo " + " ooooooooooooo " + "ooooooooooooo " + " oooooooooo " + " ooooo "); + /* map_alloc(&map,12,12, " " " oooooooooo " " oooooooooo " @@ -284,6 +293,7 @@ int main(int argc,char **argv){ " oooooooooo " " oooooooooo " " "); + */ while(map_drill_auto(&map,2)); map_print(&map); |