diff options
| author | Simon Tatham <anakin@pobox.com> | 2005-05-22 11:15:03 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2005-05-22 11:15:03 +0000 |
| commit | fc3f16b364e64ad01c3c1d19e99051b922e2a4f8 (patch) | |
| tree | f52000606f3756d3e10d14c6295a92c3f22116aa /net.c | |
| parent | d45d94d355916117cd4c66b050b3ec14c4fbbd4a (diff) | |
| download | puzzles-fc3f16b364e64ad01c3c1d19e99051b922e2a4f8.zip puzzles-fc3f16b364e64ad01c3c1d19e99051b922e2a4f8.tar.gz puzzles-fc3f16b364e64ad01c3c1d19e99051b922e2a4f8.tar.bz2 puzzles-fc3f16b364e64ad01c3c1d19e99051b922e2a4f8.tar.xz | |
The Net solver now makes use of barrier information when applied to
a typed-in grid.
[originally from svn r5827]
Diffstat (limited to 'net.c')
| -rw-r--r-- | net.c | 32 |
1 files changed, 29 insertions, 3 deletions
@@ -415,7 +415,8 @@ static int todo_get(struct todo *todo) { return ret; } -static int net_solver(int w, int h, unsigned char *tiles, int wrapping) +static int net_solver(int w, int h, unsigned char *tiles, + unsigned char *barriers, int wrapping) { unsigned char *tilestate; unsigned char *edgestate; @@ -523,6 +524,30 @@ static int net_solver(int w, int h, unsigned char *tiles, int wrapping) } /* + * If we have barriers available, we can mark those edges as + * closed too. + */ + if (barriers) { + for (y = 0; y < h; y++) for (x = 0; x < w; x++) { + int d; + for (d = 1; d <= 8; d += d) { + if (barriers[y*w+x] & d) { + int x2, y2; + /* + * In principle the barrier list should already + * contain each barrier from each side, but + * let's not take chances with our internal + * consistency. + */ + OFFSETWH(x2, y2, x, y, d, w, h); + edgestate[(y*w+x) * 5 + d] = 2; + edgestate[(y2*w+x2) * 5 + F(d)] = 2; + } + } + } + } + + /* * Since most deductions made by this solver are local (the * exception is loop avoidance, where joining two tiles * together on one side of the grid can theoretically permit a @@ -1264,7 +1289,7 @@ static char *new_game_desc(game_params *params, random_state *rs, /* * Run the solver to check unique solubility. */ - while (!net_solver(w, h, tiles, params->wrapping)) { + while (!net_solver(w, h, tiles, NULL, params->wrapping)) { int n = 0; /* @@ -1641,7 +1666,8 @@ static game_state *solve_game(game_state *state, game_aux_info *aux, * not yield a complete solution. */ ret = dup_game(state); - net_solver(ret->width, ret->height, ret->tiles, ret->wrapping); + net_solver(ret->width, ret->height, ret->tiles, + ret->barriers, ret->wrapping); } else { assert(aux->width == state->width); assert(aux->height == state->height); |