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;
}
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;
}
/*
- * Save the unshuffled grid in an aux_info.
+ * Save the unshuffled grid in aux.
*/
{
- 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;
}
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 *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;
- 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.
*/
- 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);
- tiles_need_freeing = TRUE;
} 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;
+ }
}
/*
ret[retlen] = '\0';
ret = sresize(ret, retlen+1, char);
+ sfree(tiles);
+
return ret;
}
sfree(ui);
}
+static char *encode_ui(game_ui *ui)
+{
+ char buf[120];
+ /*
+ * We preserve the origin and centre-point coordinates over a
+ * serialise.
+ */
+ sprintf(buf, "O%d,%d;C%d,%d", ui->org_x, ui->org_y, ui->cx, ui->cy);
+ return dupstr(buf);
+}
+
+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);
+}
+
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
sprintf(buf, "L%d,%d", tx, ty);
return dupstr(buf);
} else if (button == LEFT_BUTTON || button == RIGHT_BUTTON) {
+ char buf[80];
/*
* The left and right buttons have no effect if clicked on a
* Otherwise, turn the tile one way or the other. Left button
* turns anticlockwise; right button turns clockwise.
*/
- char buf[80];
sprintf(buf, "%c%d,%d", (button == LEFT_BUTTON ? 'A' : 'C'), tx, ty);
return dupstr(buf);
} else if (button == 'J') {
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);
}
/*
TRUE, game_configure, custom_params,
validate_params,
new_game_desc,
- game_free_aux_info,
validate_desc,
new_game,
dup_game,
FALSE, game_text_format,
new_ui,
free_ui,
+ encode_ui,
+ decode_ui,
game_changed_state,
interpret_move,
execute_move,