summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-10-24 23:35:19 +0200
committerjonsykkel <jonrevold@gmail.com>2020-10-24 23:35:19 +0200
commit82317146d5fdb2c7f7e6ab9083703ac00072d629 (patch)
tree03eddd6a7595d3ed7fefbc5ca0ab3a0a6b954686
parentbfedebd1b0a2a4dc77763802a5fa8e5ab4035485 (diff)
downloadmindustry_solver-82317146d5fdb2c7f7e6ab9083703ac00072d629.tar.gz
ok
-rw-r--r--src/main.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 170f7bc..8086855 100644
--- a/src/main.c
+++ b/src/main.c
@@ -13,6 +13,7 @@
#define MAP_CELL_OUTOFBOUNDS(M,X,Y) (((size_t)(X) >= (M)->width) || ((size_t)(Y) >= (M)->height))
#define MAP_CELL(M,X,Y) &(M)->cell[(M)->width*(Y)+(X)]
#define MAP_CELL_IS_BORDER(M,X,Y) ((X) == 0 || (Y) == 0 || (X) == (M)->width-1 || (Y) == (M)->height-1)
+#define MAP_BACKUP_SIZE (DRILL_DIM_MAX*DRILL_DIM_MAX)
#ifdef FASTIK
#define CHECK_DIM(D) do{}while(0);
@@ -45,7 +46,7 @@ typedef struct map_t{
size_t width;
size_t height;
cell_t *cell;
- size_t drill_count;
+ size_t drill_cnt;
drill_t *drill;
}map_t;
@@ -80,9 +81,9 @@ static void map_alloc(map_t *map,size_t width,size_t height,char const *init){
cell_init(c,s);
}
}
- drill_max = (width/DRILL_DIM_MIN)*(height/DRILL_DIM_MIN);
- map->drill = malloc(sizeof(drill_t)*drill_max);
- map->drill_count = 0;
+ drill_max = (width/DRILL_DIM_MIN)*(height/DRILL_DIM_MIN);
+ map->drill = malloc(sizeof(drill_t)*drill_max);
+ map->drill_cnt = 0;
}
static void map_print(map_t *map){
@@ -169,6 +170,25 @@ static void map_drill_add(map_t *map,size_t x,size_t y,size_t dim){
c->drill_index = 1; //tmp
}
}
+
+ drill_t *drill;
+ drill = &map->drill[map->drill_cnt++];
+ drill->x = x;
+ drill->y = y;
+}
+
+static void map_backup(map_t *map,size_t x,size_t y,size_t dim,cell_t *backup){
+ for(size_t cy = y;cy < y+dim;cy++){
+ memcpy(backup,MAP_CELL(map,x,cy),sizeof(cell_t)*dim);
+ backup += dim;
+ }
+}
+
+static void map_restore(map_t *map,size_t x,size_t y,size_t dim,cell_t *backup){
+ for(size_t cy = y;cy < y+dim;cy++){
+ memcpy(MAP_CELL(map,x,cy),backup,sizeof(cell_t)*dim);
+ backup += dim;
+ }
}
//1 = placed drill
@@ -180,7 +200,11 @@ static int map_drill_auto(map_t *map,size_t dim){
for(size_t x = 0;x < map->width-(dim-1);x++){
int ore = map_drill_prospect(map,x,y,dim);
if(ore < target) continue;
+
+ cell_t backup[MAP_BACKUP_SIZE];
+ map_backup(map,x,y,dim,backup);
map_drill_add(map,x,y,dim);
+ map_restore(map,x,y,dim,backup);
return 1;
}
}