mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Mines now follows the conventional approach of offering a completely
blank grid until you make the first click; to ensure solubility, it does not generate the mine layout until that click, and then ensures it is solvable starting from that position. This has involved three infrastructure changes: - random.c now offers functions to encode and decode an entire random_state as a string - each puzzle's new_game() is now passed a pointer to the midend itself, which most of them ignore - there's a function in the midend which a game can call back to _rewrite_ its current game description. So Mines now has two entirely separate forms of game ID. One contains the generation-time parameters (n and unique) plus an encoding of a random_state; the other actually encodes the grid once it's been generated, and also contains the initial click position. When called with the latter, new_game() does plausibly normal stuff. When called with the former, it notes down all the details and waits until the first square is opened, and _then_ does the grid generation and updates the game description in the midend. So if, _after_ your first click, you decide you want to share this particular puzzle with someone else, you can do that fine. Also in this checkin, the mine layout is no longer _copied_ between all the game_states on the undo chain. Instead, it's in a separate structure and all game_states share a pointer to it - and the structure is reference-counted to ensure deallocation. [originally from svn r5862]
This commit is contained in:
@ -144,6 +144,7 @@ char *midend_set_config(midend_data *me, int which, config_item *cfg);
|
||||
char *midend_game_id(midend_data *me, char *id);
|
||||
char *midend_text_format(midend_data *me);
|
||||
char *midend_solve(midend_data *me);
|
||||
void midend_supersede_game_desc(midend_data *me, char *desc);
|
||||
|
||||
/*
|
||||
* malloc.c
|
||||
@ -176,6 +177,8 @@ random_state *random_init(char *seed, int len);
|
||||
unsigned long random_bits(random_state *state, int bits);
|
||||
unsigned long random_upto(random_state *state, unsigned long limit);
|
||||
void random_free(random_state *state);
|
||||
char *random_state_encode(random_state *state);
|
||||
random_state *random_state_decode(char *input);
|
||||
/* random.c also exports SHA, which occasionally comes in useful. */
|
||||
typedef unsigned long uint32;
|
||||
typedef struct {
|
||||
@ -213,7 +216,7 @@ struct game {
|
||||
game_aux_info **aux);
|
||||
void (*free_aux_info)(game_aux_info *aux);
|
||||
char *(*validate_desc)(game_params *params, char *desc);
|
||||
game_state *(*new_game)(game_params *params, char *desc);
|
||||
game_state *(*new_game)(midend_data *me, game_params *params, char *desc);
|
||||
game_state *(*dup_game)(game_state *state);
|
||||
void (*free_game)(game_state *state);
|
||||
int can_solve;
|
||||
|
Reference in New Issue
Block a user