summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-10-24 23:39:21 +0200
committerjonsykkel <jonrevold@gmail.com>2020-10-24 23:39:21 +0200
commitd4c267b7a0296573b62992b7da5f90d587e1a205 (patch)
treea2fe36b92a81b040db155727765ccccc6d8f452b
parent82317146d5fdb2c7f7e6ab9083703ac00072d629 (diff)
downloadmindustry_solver-d4c267b7a0296573b62992b7da5f90d587e1a205.tar.gz
ok
-rw-r--r--src/main.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c
index 8086855..dfbe58f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -50,6 +50,10 @@ typedef struct map_t{
drill_t *drill;
}map_t;
+typedef struct backup_t{
+ cell_t cell[MAP_BACKUP_SIZE];
+}backup_t;
+
static void fail(void){
printf("failed\n");
exit(1);
@@ -177,18 +181,21 @@ static void map_drill_add(map_t *map,size_t x,size_t y,size_t dim){
drill->y = y;
}
-static void map_backup(map_t *map,size_t x,size_t y,size_t dim,cell_t *backup){
+static void map_backup(map_t *map,size_t x,size_t y,size_t dim,backup_t *backup){
+ cell_t *cell = backup->cell;
for(size_t cy = y;cy < y+dim;cy++){
- memcpy(backup,MAP_CELL(map,x,cy),sizeof(cell_t)*dim);
- backup += dim;
+ memcpy(cell,MAP_CELL(map,x,cy),sizeof(cell_t)*dim);
+ cell += dim;
}
}
-static void map_restore(map_t *map,size_t x,size_t y,size_t dim,cell_t *backup){
+static void map_restore(map_t *map,size_t x,size_t y,size_t dim,backup_t *backup){
+ cell_t *cell = backup->cell;
for(size_t cy = y;cy < y+dim;cy++){
- memcpy(MAP_CELL(map,x,cy),backup,sizeof(cell_t)*dim);
- backup += dim;
+ memcpy(MAP_CELL(map,x,cy),cell,sizeof(cell_t)*dim);
+ cell += dim;
}
+ map->drill_cnt--;
}
//1 = placed drill
@@ -201,10 +208,10 @@ static int map_drill_auto(map_t *map,size_t dim){
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);
+ backup_t backup;
+ map_backup(map,x,y,dim,&backup);
map_drill_add(map,x,y,dim);
- map_restore(map,x,y,dim,backup);
+ //map_restore(map,x,y,dim,&backup);
return 1;
}
}