~mdw
/
sgt
/
puzzles
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add WinHelp topic.
[sgt/puzzles]
/
net.c
diff --git
a/net.c
b/net.c
index
3b1339a
..
2e86700
100644
(file)
--- a/
net.c
+++ b/
net.c
@@
-77,11
+77,6
@@
struct game_params {
float barrier_probability;
};
float barrier_probability;
};
-struct game_aux_info {
- int width, height;
- unsigned char *tiles;
-};
-
struct game_state {
int width, height, wrapping, completed;
int last_rotate_x, last_rotate_y, last_rotate_dir;
struct game_state {
int width, height, wrapping, completed;
int last_rotate_x, last_rotate_y, last_rotate_dir;
@@
-1139,7
+1134,7
@@
static void perturb(int w, int h, unsigned char *tiles, int wrapping,
}
static char *new_game_desc(game_params *params, random_state *rs,
}
static char *new_game_desc(game_params *params, random_state *rs,
-
game_aux_info
**aux, int interactive)
+
char
**aux, int interactive)
{
tree234 *possibilities, *barriertree;
int w, h, x, y, cx, cy, nbarriers;
{
tree234 *possibilities, *barriertree;
int w, h, x, y, cx, cy, nbarriers;
@@
-1401,16
+1396,16
@@
static char *new_game_desc(game_params *params, random_state *rs,
}
/*
}
/*
- * Save the unshuffled grid in a
n aux_info
.
+ * Save the unshuffled grid in a
ux
.
*/
{
*/
{
- game_aux_info *solution;
+ char *solution;
+ int i;
- solution = snew(game_aux_info);
- solution->width = w;
- solution->height = h;
- solution->tiles = snewn(w * h, unsigned char);
- memcpy(solution->tiles, tiles, w * h);
+ solution = snewn(w * h + 1, char);
+ for (i = 0; i < w * h; i++)
+ solution[i] = "0123456789abcdef"[tiles[i] & 0xF];
+ solution[w*h] = '\0';
*aux = solution;
}
*aux = solution;
}
@@
-1515,12
+1510,6
@@
static char *new_game_desc(game_params *params, random_state *rs,
return desc;
}
return desc;
}
-static void game_free_aux_info(game_aux_info *aux)
-{
- sfree(aux->tiles);
- sfree(aux);
-}
-
static char *validate_desc(game_params *params, char *desc)
{
int w = params->width, h = params->height;
static char *validate_desc(game_params *params, char *desc)
{
int w = params->width, h = params->height;
@@
-1667,27
+1656,34
@@
static void free_game(game_state *state)
}
static char *solve_game(game_state *state, game_state *currstate,
}
static char *solve_game(game_state *state, game_state *currstate,
-
game_aux_info
*aux, char **error)
+
char
*aux, char **error)
{
unsigned char *tiles;
char *ret;
int retlen, retsize;
int i;
{
unsigned char *tiles;
char *ret;
int retlen, retsize;
int i;
- int tiles_need_freeing;
+
+ tiles = snewn(state->width * state->height, unsigned char);
if (!aux) {
/*
* Run the internal solver on the provided grid. This might
* not yield a complete solution.
*/
if (!aux) {
/*
* Run the internal solver on the provided grid. This might
* not yield a complete solution.
*/
- tiles = snewn(state->width * state->height, unsigned char);
memcpy(tiles, state->tiles, state->width * state->height);
net_solver(state->width, state->height, tiles,
state->barriers, state->wrapping);
memcpy(tiles, state->tiles, state->width * state->height);
net_solver(state->width, state->height, tiles,
state->barriers, state->wrapping);
- tiles_need_freeing = TRUE;
} else {
} else {
- tiles = aux->tiles;
- tiles_need_freeing = FALSE;
+ for (i = 0; i < state->width * state->height; i++) {
+ int c = aux[i];
+
+ if (c >= '0' && c <= '9')
+ tiles[i] = c - '0';
+ else if (c >= 'a' && c <= 'f')
+ tiles[i] = c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ tiles[i] = c - 'A' + 10;
+ }
}
/*
}
/*
@@
-1747,6
+1743,8
@@
static char *solve_game(game_state *state, game_state *currstate,
ret[retlen] = '\0';
ret = sresize(ret, retlen+1, char);
ret[retlen] = '\0';
ret = sresize(ret, retlen+1, char);
+ sfree(tiles);
+
return ret;
}
return ret;
}
@@
-1846,7
+1844,7
@@
static void free_ui(game_ui *ui)
sfree(ui);
}
sfree(ui);
}
-char *encode_ui(game_ui *ui)
+
static
char *encode_ui(game_ui *ui)
{
char buf[120];
/*
{
char buf[120];
/*
@@
-1857,7
+1855,7
@@
char *encode_ui(game_ui *ui)
return dupstr(buf);
}
return dupstr(buf);
}
-void decode_ui(game_ui *ui, char *encoding)
+
static
void decode_ui(game_ui *ui, char *encoding)
{
sscanf(encoding, "O%d,%d;C%d,%d",
&ui->org_x, &ui->org_y, &ui->cx, &ui->cy);
{
sscanf(encoding, "O%d,%d;C%d,%d",
&ui->org_x, &ui->org_y, &ui->cx, &ui->cy);
@@
-2407,8
+2405,7
@@
static void draw_tile(frontend *fe, game_state *state, game_drawstate *ds,
points[i+1] = by+(int)(cy+ty);
}
points[i+1] = by+(int)(cy+ty);
}
- draw_polygon(fe, points, 4, TRUE, col);
- draw_polygon(fe, points, 4, FALSE, COL_WIRE);
+ draw_polygon(fe, points, 4, col, COL_WIRE);
}
/*
}
/*
@@
-2747,7
+2744,6
@@
const struct game thegame = {
TRUE, game_configure, custom_params,
validate_params,
new_game_desc,
TRUE, game_configure, custom_params,
validate_params,
new_game_desc,
- game_free_aux_info,
validate_desc,
new_game,
dup_game,
validate_desc,
new_game,
dup_game,