Fill tiles in search if same in both branches
This gives a ~7% boost in solving ability.
This commit is contained in:
parent
dd3cabf11b
commit
120d393f12
31
main.c
31
main.c
@ -17,8 +17,7 @@
|
|||||||
#define QUEUE_MAX 128
|
#define QUEUE_MAX 128
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
FOUND_MINE,
|
MADE_INFERENCE,
|
||||||
FOUND_SAFE,
|
|
||||||
FOUND_NOTHING,
|
FOUND_NOTHING,
|
||||||
FOUND_CONTRADICTION,
|
FOUND_CONTRADICTION,
|
||||||
} update_res_t;
|
} update_res_t;
|
||||||
@ -120,7 +119,7 @@ static update_res_t update(state_t *state)
|
|||||||
|
|
||||||
if (mines + unknowns == state->field[x][y]) {
|
if (mines + unknowns == state->field[x][y]) {
|
||||||
setadj(state->field, x, y, UNKNOWN, MINE);
|
setadj(state->field, x, y, UNKNOWN, MINE);
|
||||||
return FOUND_MINE;
|
return MADE_INFERENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mines == state->field[x][y]) {
|
if (mines == state->field[x][y]) {
|
||||||
@ -130,7 +129,7 @@ static update_res_t update(state_t *state)
|
|||||||
enqueue(&state->queue, xi, yi);
|
enqueue(&state->queue, xi, yi);
|
||||||
}
|
}
|
||||||
setadj(state->field, x, y, UNKNOWN, SAFE);
|
setadj(state->field, x, y, UNKNOWN, SAFE);
|
||||||
return FOUND_SAFE;
|
return MADE_INFERENCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,9 +148,9 @@ static update_res_t search_at(state_t *state, int x, int y)
|
|||||||
if ((res = update(&with_mine)) == FOUND_CONTRADICTION) {
|
if ((res = update(&with_mine)) == FOUND_CONTRADICTION) {
|
||||||
state->field[x][y] = SAFE;
|
state->field[x][y] = SAFE;
|
||||||
enqueue(&state->queue, x, y);
|
enqueue(&state->queue, x, y);
|
||||||
return FOUND_SAFE;
|
return MADE_INFERENCE;
|
||||||
}
|
}
|
||||||
} while (res != FOUND_NOTHING);
|
} while (res == MADE_INFERENCE);
|
||||||
|
|
||||||
state_t with_safe;
|
state_t with_safe;
|
||||||
dup(state, &with_safe);
|
dup(state, &with_safe);
|
||||||
@ -159,11 +158,23 @@ static update_res_t search_at(state_t *state, int x, int y)
|
|||||||
do {
|
do {
|
||||||
if ((res = update(&with_safe)) == FOUND_CONTRADICTION) {
|
if ((res = update(&with_safe)) == FOUND_CONTRADICTION) {
|
||||||
state->field[x][y] = MINE;
|
state->field[x][y] = MINE;
|
||||||
return FOUND_MINE;
|
return MADE_INFERENCE;
|
||||||
}
|
}
|
||||||
} while (res != FOUND_NOTHING);
|
} while (res == MADE_INFERENCE);
|
||||||
|
|
||||||
return FOUND_NOTHING;
|
for (int y = 0; y < HEIGHT; ++y) {
|
||||||
|
for (int x = 0; x < WIDTH; ++x) {
|
||||||
|
if (with_mine.field[x][y] == with_safe.field[x][y] &&
|
||||||
|
state->field[x][y] != with_mine.field[x][y]) {
|
||||||
|
state->field[x][y] = with_mine.field[x][y];
|
||||||
|
if (state->field[x][y] == SAFE)
|
||||||
|
enqueue(&state->queue, x, y);
|
||||||
|
res = MADE_INFERENCE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static update_res_t search(state_t *state)
|
static update_res_t search(state_t *state)
|
||||||
@ -208,7 +219,7 @@ static status_t solve(int *probes_out)
|
|||||||
res = update(&state);
|
res = update(&state);
|
||||||
if (res == FOUND_NOTHING)
|
if (res == FOUND_NOTHING)
|
||||||
res = search(&state);
|
res = search(&state);
|
||||||
} while (res != FOUND_NOTHING);
|
} while (res == MADE_INFERENCE);
|
||||||
|
|
||||||
if (check(state.field) != OK) {
|
if (check(state.field) != OK) {
|
||||||
printf("Incorrect inference!\n");
|
printf("Incorrect inference!\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user