mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 23:51:29 -07:00
Use C99 bool within source modules.
This is the main bulk of this boolification work, but although it's making the largest actual change, it should also be the least disruptive to anyone interacting with this code base downstream of me, because it doesn't modify any interface between modules: all the inter-module APIs were updated one by one in the previous commits. This just cleans up the code within each individual source file to use bool in place of int where I think that makes things clearer.
This commit is contained in:
@ -78,15 +78,16 @@ enum {
|
||||
#define TOCHAR(c,id) (E_FROM_FRONT(c,id) + ('a'-1))
|
||||
|
||||
struct game_params {
|
||||
int w, diff, id;
|
||||
int w, diff;
|
||||
bool id;
|
||||
};
|
||||
|
||||
struct game_state {
|
||||
game_params par;
|
||||
digit *grid;
|
||||
unsigned char *immutable;
|
||||
bool *immutable;
|
||||
int *pencil; /* bitmaps using bits 1<<1..1<<n */
|
||||
int completed, cheated;
|
||||
bool completed, cheated;
|
||||
digit *sequence; /* sequence of group elements shown */
|
||||
|
||||
/*
|
||||
@ -849,11 +850,11 @@ static game_state *new_game(midend *me, const game_params *params,
|
||||
|
||||
state->par = *params; /* structure copy */
|
||||
state->grid = snewn(a, digit);
|
||||
state->immutable = snewn(a, unsigned char);
|
||||
state->immutable = snewn(a, bool);
|
||||
state->pencil = snewn(a, int);
|
||||
for (i = 0; i < a; i++) {
|
||||
state->grid[i] = 0;
|
||||
state->immutable[i] = 0;
|
||||
state->immutable[i] = false;
|
||||
state->pencil[i] = 0;
|
||||
}
|
||||
state->sequence = snewn(w, digit);
|
||||
@ -868,7 +869,8 @@ static game_state *new_game(midend *me, const game_params *params,
|
||||
if (state->grid[i] != 0)
|
||||
state->immutable[i] = true;
|
||||
|
||||
state->completed = state->cheated = false;
|
||||
state->completed = false;
|
||||
state->cheated = false;
|
||||
|
||||
return state;
|
||||
}
|
||||
@ -881,12 +883,12 @@ static game_state *dup_game(const game_state *state)
|
||||
ret->par = state->par; /* structure copy */
|
||||
|
||||
ret->grid = snewn(a, digit);
|
||||
ret->immutable = snewn(a, unsigned char);
|
||||
ret->immutable = snewn(a, bool);
|
||||
ret->pencil = snewn(a, int);
|
||||
ret->sequence = snewn(w, digit);
|
||||
ret->dividers = snewn(w, int);
|
||||
memcpy(ret->grid, state->grid, a*sizeof(digit));
|
||||
memcpy(ret->immutable, state->immutable, a*sizeof(unsigned char));
|
||||
memcpy(ret->immutable, state->immutable, a*sizeof(bool));
|
||||
memcpy(ret->pencil, state->pencil, a*sizeof(int));
|
||||
memcpy(ret->sequence, state->sequence, w*sizeof(digit));
|
||||
memcpy(ret->dividers, state->dividers, w*sizeof(int));
|
||||
@ -1001,7 +1003,7 @@ struct game_ui {
|
||||
* This indicates whether the current highlight is a
|
||||
* pencil-mark one or a real one.
|
||||
*/
|
||||
int hpencil;
|
||||
bool hpencil;
|
||||
/*
|
||||
* This indicates whether or not we're showing the highlight
|
||||
* (used to be hx = hy = -1); important so that when we're
|
||||
@ -1009,13 +1011,13 @@ struct game_ui {
|
||||
* fixed position. When hshow = 1, pressing a valid number
|
||||
* or letter key or Space will enter that number or letter in the grid.
|
||||
*/
|
||||
int hshow;
|
||||
bool hshow;
|
||||
/*
|
||||
* This indicates whether we're using the highlight as a cursor;
|
||||
* it means that it doesn't vanish on a keypress, and that it is
|
||||
* allowed on immutable squares.
|
||||
*/
|
||||
int hcursor;
|
||||
bool hcursor;
|
||||
/*
|
||||
* This indicates whether we're dragging a table header to
|
||||
* reposition an entire row or column.
|
||||
@ -1031,7 +1033,9 @@ static game_ui *new_ui(const game_state *state)
|
||||
game_ui *ui = snew(game_ui);
|
||||
|
||||
ui->hx = ui->hy = 0;
|
||||
ui->hpencil = ui->hshow = ui->hcursor = 0;
|
||||
ui->hpencil = false;
|
||||
ui->hshow = false;
|
||||
ui->hcursor = false;
|
||||
ui->drag = 0;
|
||||
|
||||
return ui;
|
||||
@ -1063,7 +1067,7 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate,
|
||||
*/
|
||||
if (ui->hshow && ui->hpencil && !ui->hcursor &&
|
||||
newstate->grid[ui->hy * w + ui->hx] != 0) {
|
||||
ui->hshow = 0;
|
||||
ui->hshow = false;
|
||||
}
|
||||
if (ui->hshow && ui->odn > 1) {
|
||||
/*
|
||||
@ -1075,12 +1079,12 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate,
|
||||
for (i = 0; i < ui->odn; i++) {
|
||||
if (oldstate->sequence[ui->ohx + i*ui->odx] !=
|
||||
newstate->sequence[ui->ohx + i*ui->odx]) {
|
||||
ui->hshow = 0;
|
||||
ui->hshow = false;
|
||||
break;
|
||||
}
|
||||
if (oldstate->sequence[ui->ohy + i*ui->ody] !=
|
||||
newstate->sequence[ui->ohy + i*ui->ody]) {
|
||||
ui->hshow = 0;
|
||||
ui->hshow = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1132,17 +1136,18 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate,
|
||||
struct game_drawstate {
|
||||
game_params par;
|
||||
int w, tilesize;
|
||||
int started;
|
||||
bool started;
|
||||
long *tiles, *legend, *pencil, *errors;
|
||||
long *errtmp;
|
||||
digit *sequence;
|
||||
};
|
||||
|
||||
static int check_errors(const game_state *state, long *errors)
|
||||
static bool check_errors(const game_state *state, long *errors)
|
||||
{
|
||||
int w = state->par.w, a = w*w;
|
||||
digit *grid = state->grid;
|
||||
int i, j, k, x, y, errs = false;
|
||||
int i, j, k, x, y;
|
||||
bool errs = false;
|
||||
|
||||
/*
|
||||
* To verify that we have a valid group table, it suffices to
|
||||
@ -1304,8 +1309,8 @@ static char *interpret_move(const game_state *state, game_ui *ui,
|
||||
ty = state->sequence[ty];
|
||||
if (button == LEFT_BUTTON) {
|
||||
if (tx == ui->hx && ty == ui->hy &&
|
||||
ui->hshow && ui->hpencil == 0) {
|
||||
ui->hshow = 0;
|
||||
ui->hshow && !ui->hpencil) {
|
||||
ui->hshow = false;
|
||||
} else {
|
||||
ui->hx = tx;
|
||||
ui->hy = ty;
|
||||
@ -1314,9 +1319,9 @@ static char *interpret_move(const game_state *state, game_ui *ui,
|
||||
ui->odx = ui->ody = 0;
|
||||
ui->odn = 1;
|
||||
ui->hshow = !state->immutable[ty*w+tx];
|
||||
ui->hpencil = 0;
|
||||
ui->hpencil = false;
|
||||
}
|
||||
ui->hcursor = 0;
|
||||
ui->hcursor = false;
|
||||
return UI_UPDATE;
|
||||
}
|
||||
if (button == RIGHT_BUTTON) {
|
||||
@ -1326,21 +1331,21 @@ static char *interpret_move(const game_state *state, game_ui *ui,
|
||||
if (state->grid[ty*w+tx] == 0) {
|
||||
if (tx == ui->hx && ty == ui->hy &&
|
||||
ui->hshow && ui->hpencil) {
|
||||
ui->hshow = 0;
|
||||
ui->hshow = false;
|
||||
} else {
|
||||
ui->hpencil = 1;
|
||||
ui->hpencil = true;
|
||||
ui->hx = tx;
|
||||
ui->hy = ty;
|
||||
ui->ohx = otx;
|
||||
ui->ohy = oty;
|
||||
ui->odx = ui->ody = 0;
|
||||
ui->odn = 1;
|
||||
ui->hshow = 1;
|
||||
ui->hshow = true;
|
||||
}
|
||||
} else {
|
||||
ui->hshow = 0;
|
||||
ui->hshow = false;
|
||||
}
|
||||
ui->hcursor = 0;
|
||||
ui->hcursor = false;
|
||||
return UI_UPDATE;
|
||||
}
|
||||
} else if (tx >= 0 && tx < w && ty == -1) {
|
||||
@ -1373,16 +1378,17 @@ static char *interpret_move(const game_state *state, game_ui *ui,
|
||||
if (IS_CURSOR_MOVE(button)) {
|
||||
int cx = find_in_sequence(state->sequence, w, ui->hx);
|
||||
int cy = find_in_sequence(state->sequence, w, ui->hy);
|
||||
move_cursor(button, &cx, &cy, w, w, 0);
|
||||
move_cursor(button, &cx, &cy, w, w, false);
|
||||
ui->hx = state->sequence[cx];
|
||||
ui->hy = state->sequence[cy];
|
||||
ui->hshow = ui->hcursor = 1;
|
||||
ui->hshow = true;
|
||||
ui->hcursor = true;
|
||||
return UI_UPDATE;
|
||||
}
|
||||
if (ui->hshow &&
|
||||
(button == CURSOR_SELECT)) {
|
||||
ui->hpencil = 1 - ui->hpencil;
|
||||
ui->hcursor = 1;
|
||||
ui->hpencil = !ui->hpencil;
|
||||
ui->hcursor = true;
|
||||
return UI_UPDATE;
|
||||
}
|
||||
|
||||
@ -1433,7 +1439,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
|
||||
}
|
||||
movebuf = sresize(movebuf, buflen+1, char);
|
||||
|
||||
if (!ui->hcursor) ui->hshow = 0;
|
||||
if (!ui->hcursor) ui->hshow = false;
|
||||
|
||||
return movebuf;
|
||||
}
|
||||
@ -1473,7 +1479,7 @@ static game_state *execute_move(const game_state *from, const char *move)
|
||||
sscanf(move+1, "%d,%d,%d%n", &x, &y, &n, &pos) == 3 &&
|
||||
n >= 0 && n <= w) {
|
||||
const char *mp = move + 1 + pos;
|
||||
int pencil = (move[0] == 'P');
|
||||
bool pencil = (move[0] == 'P');
|
||||
ret = dup_game(from);
|
||||
|
||||
while (1) {
|
||||
@ -1902,7 +1908,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds,
|
||||
tile |= DF_HIGHLIGHT;
|
||||
} else if (ui->hshow) {
|
||||
int i = abs(x - ui->ohx);
|
||||
int highlight = 0;
|
||||
bool highlight = false;
|
||||
if (ui->odn > 1) {
|
||||
/*
|
||||
* When a diagonal multifill selection is shown,
|
||||
@ -1913,7 +1919,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds,
|
||||
if (i >= 0 && i < ui->odn &&
|
||||
x == ui->ohx + i*ui->odx &&
|
||||
y == ui->ohy + i*ui->ody)
|
||||
highlight = 1;
|
||||
highlight = true;
|
||||
} else {
|
||||
/*
|
||||
* For a single square, we move its highlight
|
||||
@ -2110,8 +2116,9 @@ int main(int argc, char **argv)
|
||||
char *id = NULL, *desc;
|
||||
const char *err;
|
||||
digit *grid;
|
||||
int grade = false;
|
||||
int ret, diff, really_show_working = false;
|
||||
bool grade = false;
|
||||
int ret, diff;
|
||||
bool really_show_working = false;
|
||||
|
||||
while (--argc > 0) {
|
||||
char *p = *++argv;
|
||||
@ -2156,7 +2163,7 @@ int main(int argc, char **argv)
|
||||
* the puzzle internally before doing anything else.
|
||||
*/
|
||||
ret = -1; /* placate optimiser */
|
||||
solver_show_working = false;
|
||||
solver_show_working = 0;
|
||||
for (diff = 0; diff < DIFFCOUNT; diff++) {
|
||||
memcpy(grid, s->grid, p->w * p->w);
|
||||
ret = solver(&s->par, grid, diff);
|
||||
|
@ -207,7 +207,7 @@ struct solver_scratch {
|
||||
* tracks whether or not the connected components containing
|
||||
* yx1 and yx2 are known to be distinct.
|
||||
*/
|
||||
unsigned char *disconnect;
|
||||
bool *disconnect;
|
||||
|
||||
/*
|
||||
* Temporary space used only inside particular solver loops.
|
||||
@ -227,7 +227,7 @@ struct solver_scratch *solver_scratch_new(int w, int h, int k)
|
||||
sc->dsf = snew_dsf(wh);
|
||||
sc->size = snewn(wh, int);
|
||||
sc->contents = snewn(wh * k, int);
|
||||
sc->disconnect = snewn(wh*wh, unsigned char);
|
||||
sc->disconnect = snewn(wh*wh, bool);
|
||||
sc->tmp = snewn(wh, int);
|
||||
|
||||
return sc;
|
||||
@ -312,7 +312,8 @@ void solver_disconnect(struct solver_scratch *sc, int yx1, int yx2)
|
||||
* Mark the components as disconnected from each other in the
|
||||
* disconnect matrix.
|
||||
*/
|
||||
sc->disconnect[yx1*wh+yx2] = sc->disconnect[yx2*wh+yx1] = 1;
|
||||
sc->disconnect[yx1*wh+yx2] = true;
|
||||
sc->disconnect[yx2*wh+yx1] = true;
|
||||
}
|
||||
|
||||
void solver_init(struct solver_scratch *sc)
|
||||
@ -328,16 +329,16 @@ void solver_init(struct solver_scratch *sc)
|
||||
*/
|
||||
dsf_init(sc->dsf, wh);
|
||||
for (i = 0; i < wh; i++) sc->size[i] = 1;
|
||||
memset(sc->disconnect, 0, wh*wh);
|
||||
memset(sc->disconnect, 0, wh*wh * sizeof(bool));
|
||||
}
|
||||
|
||||
int solver_attempt(struct solver_scratch *sc, const unsigned char *grid,
|
||||
unsigned char *gen_lock)
|
||||
bool *gen_lock)
|
||||
{
|
||||
int w = sc->w, h = sc->h, k = sc->k;
|
||||
int wh = w*h;
|
||||
int i, x, y;
|
||||
int done_something_overall = false;
|
||||
bool done_something_overall = false;
|
||||
|
||||
/*
|
||||
* Set up the contents array from the grid.
|
||||
@ -348,7 +349,7 @@ int solver_attempt(struct solver_scratch *sc, const unsigned char *grid,
|
||||
sc->contents[dsf_canonify(sc->dsf, i)*k+grid[i]] = i;
|
||||
|
||||
while (1) {
|
||||
int done_something = false;
|
||||
bool done_something = false;
|
||||
|
||||
/*
|
||||
* Go over the grid looking for reasons to add to the
|
||||
@ -406,8 +407,8 @@ int solver_attempt(struct solver_scratch *sc, const unsigned char *grid,
|
||||
* based deductions.
|
||||
*/
|
||||
if (gen_lock) {
|
||||
gen_lock[sc->contents[yx*k+i]] = 1;
|
||||
gen_lock[sc->contents[yx2*k+i]] = 1;
|
||||
gen_lock[sc->contents[yx*k+i]] = true;
|
||||
gen_lock[sc->contents[yx2*k+i]] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -500,14 +501,14 @@ unsigned char *generate(int w, int h, int k, random_state *rs)
|
||||
unsigned char *shuffled;
|
||||
int i, j, m, retries;
|
||||
int *permutation;
|
||||
unsigned char *gen_lock;
|
||||
bool *gen_lock;
|
||||
extern int *divvy_rectangle(int w, int h, int k, random_state *rs);
|
||||
|
||||
sc = solver_scratch_new(w, h, k);
|
||||
grid = snewn(wh, unsigned char);
|
||||
shuffled = snewn(k, unsigned char);
|
||||
permutation = snewn(wh, int);
|
||||
gen_lock = snewn(wh, unsigned char);
|
||||
gen_lock = snewn(wh, bool);
|
||||
|
||||
do {
|
||||
int *dsf = divvy_rectangle(w, h, k, rs);
|
||||
@ -547,7 +548,7 @@ unsigned char *generate(int w, int h, int k, random_state *rs)
|
||||
* on for deductions. This is gradually updated by
|
||||
* solver_attempt().
|
||||
*/
|
||||
memset(gen_lock, 0, wh);
|
||||
memset(gen_lock, 0, wh * sizeof(bool));
|
||||
|
||||
/*
|
||||
* Now repeatedly fill the grid with letters, and attempt
|
||||
|
@ -128,7 +128,7 @@ struct game_params {
|
||||
|
||||
struct game_immutable_state {
|
||||
int refcount;
|
||||
unsigned char *forcefield;
|
||||
bool *forcefield;
|
||||
};
|
||||
|
||||
struct game_solution {
|
||||
@ -145,7 +145,7 @@ struct game_state {
|
||||
int lastmoved, lastmoved_pos; /* for move counting */
|
||||
int movecount;
|
||||
int completed;
|
||||
int cheated;
|
||||
bool cheated;
|
||||
struct game_immutable_state *imm;
|
||||
struct game_solution *soln;
|
||||
int soln_index;
|
||||
@ -287,7 +287,7 @@ static const char *validate_params(const game_params *params, bool full)
|
||||
}
|
||||
|
||||
static char *board_text_format(int w, int h, unsigned char *data,
|
||||
unsigned char *forcefield)
|
||||
bool *forcefield)
|
||||
{
|
||||
int wh = w*h;
|
||||
int *dsf = snew_dsf(wh);
|
||||
@ -406,13 +406,14 @@ static struct board *newboard(int w, int h, unsigned char *data)
|
||||
* which is a pointer to a dynamically allocated array.
|
||||
*/
|
||||
static int solve_board(int w, int h, unsigned char *board,
|
||||
unsigned char *forcefield, int tx, int ty,
|
||||
bool *forcefield, int tx, int ty,
|
||||
int movelimit, int **moveout)
|
||||
{
|
||||
int wh = w*h;
|
||||
struct board *b, *b2, *b3;
|
||||
int *next, *anchors, *which;
|
||||
int *movereached, *movequeue, mqhead, mqtail;
|
||||
int *next, *which;
|
||||
bool *anchors, *movereached;
|
||||
int *movequeue, mqhead, mqtail;
|
||||
tree234 *sorted, *queue;
|
||||
int i, j, dir;
|
||||
int qlen, lastdist;
|
||||
@ -453,9 +454,9 @@ static int solve_board(int w, int h, unsigned char *board,
|
||||
qlen = 1;
|
||||
|
||||
next = snewn(wh, int);
|
||||
anchors = snewn(wh, int);
|
||||
anchors = snewn(wh, bool);
|
||||
which = snewn(wh, int);
|
||||
movereached = snewn(wh, int);
|
||||
movereached = snewn(wh, bool);
|
||||
movequeue = snewn(wh, int);
|
||||
lastdist = -1;
|
||||
|
||||
@ -637,11 +638,12 @@ static int solve_board(int w, int h, unsigned char *board,
|
||||
|
||||
static void generate_board(int w, int h, int *rtx, int *rty, int *minmoves,
|
||||
random_state *rs, unsigned char **rboard,
|
||||
unsigned char **rforcefield, int movelimit)
|
||||
bool **rforcefield, int movelimit)
|
||||
{
|
||||
int wh = w*h;
|
||||
unsigned char *board, *board2, *forcefield;
|
||||
unsigned char *tried_merge;
|
||||
unsigned char *board, *board2;
|
||||
bool *forcefield;
|
||||
bool *tried_merge;
|
||||
int *dsf;
|
||||
int *list, nlist, pos;
|
||||
int tx, ty;
|
||||
@ -653,17 +655,17 @@ static void generate_board(int w, int h, int *rtx, int *rty, int *minmoves,
|
||||
* border of walls.
|
||||
*/
|
||||
board = snewn(wh, unsigned char);
|
||||
forcefield = snewn(wh, unsigned char);
|
||||
forcefield = snewn(wh, bool);
|
||||
board2 = snewn(wh, unsigned char);
|
||||
memset(board, ANCHOR, wh);
|
||||
memset(forcefield, false, wh);
|
||||
memset(forcefield, 0, wh * sizeof(bool));
|
||||
for (i = 0; i < w; i++)
|
||||
board[i] = board[i+w*(h-1)] = WALL;
|
||||
for (i = 0; i < h; i++)
|
||||
board[i*w] = board[i*w+(w-1)] = WALL;
|
||||
|
||||
tried_merge = snewn(wh * wh, unsigned char);
|
||||
memset(tried_merge, 0, wh*wh);
|
||||
tried_merge = snewn(wh * wh, bool);
|
||||
memset(tried_merge, 0, wh*wh * sizeof(bool));
|
||||
dsf = snew_dsf(wh);
|
||||
|
||||
/*
|
||||
@ -680,7 +682,8 @@ static void generate_board(int w, int h, int *rtx, int *rty, int *minmoves,
|
||||
*/
|
||||
tx = w-2;
|
||||
ty = h-3;
|
||||
forcefield[ty*w+tx+1] = forcefield[(ty+1)*w+tx+1] = true;
|
||||
forcefield[ty*w+tx+1] = true;
|
||||
forcefield[(ty+1)*w+tx+1] = true;
|
||||
board[ty*w+tx+1] = board[(ty+1)*w+tx+1] = EMPTY;
|
||||
|
||||
/*
|
||||
@ -799,7 +802,8 @@ static void generate_board(int w, int h, int *rtx, int *rty, int *minmoves,
|
||||
* Didn't work. Revert the merge.
|
||||
*/
|
||||
memcpy(board, board2, wh);
|
||||
tried_merge[c1 * wh + c2] = tried_merge[c2 * wh + c1] = true;
|
||||
tried_merge[c1 * wh + c2] = true;
|
||||
tried_merge[c2 * wh + c1] = true;
|
||||
} else {
|
||||
int c;
|
||||
|
||||
@ -808,10 +812,10 @@ static void generate_board(int w, int h, int *rtx, int *rty, int *minmoves,
|
||||
dsf_merge(dsf, c1, c2);
|
||||
c = dsf_canonify(dsf, c1);
|
||||
for (i = 0; i < wh; i++)
|
||||
tried_merge[c*wh+i] = (tried_merge[c1*wh+i] |
|
||||
tried_merge[c*wh+i] = (tried_merge[c1*wh+i] ||
|
||||
tried_merge[c2*wh+i]);
|
||||
for (i = 0; i < wh; i++)
|
||||
tried_merge[i*wh+c] = (tried_merge[i*wh+c1] |
|
||||
tried_merge[i*wh+c] = (tried_merge[i*wh+c1] ||
|
||||
tried_merge[i*wh+c2]);
|
||||
}
|
||||
}
|
||||
@ -837,7 +841,8 @@ static char *new_game_desc(const game_params *params, random_state *rs,
|
||||
{
|
||||
int w = params->w, h = params->h, wh = w*h;
|
||||
int tx, ty, minmoves;
|
||||
unsigned char *board, *forcefield;
|
||||
unsigned char *board;
|
||||
bool *forcefield;
|
||||
char *ret, *p;
|
||||
int i;
|
||||
|
||||
@ -863,7 +868,8 @@ static char *new_game_desc(const game_params *params, random_state *rs,
|
||||
i++;
|
||||
} else {
|
||||
int count = 1;
|
||||
int b = board[i], f = forcefield[i];
|
||||
int b = board[i];
|
||||
bool f = forcefield[i];
|
||||
int c = (b == ANCHOR ? 'a' :
|
||||
b == MAINANCHOR ? 'm' :
|
||||
b == EMPTY ? 'e' :
|
||||
@ -889,12 +895,13 @@ static char *new_game_desc(const game_params *params, random_state *rs,
|
||||
static const char *validate_desc(const game_params *params, const char *desc)
|
||||
{
|
||||
int w = params->w, h = params->h, wh = w*h;
|
||||
int *active, *link;
|
||||
bool *active;
|
||||
int *link;
|
||||
int mains = 0;
|
||||
int i, tx, ty, minmoves;
|
||||
char *ret;
|
||||
|
||||
active = snewn(wh, int);
|
||||
active = snewn(wh, bool);
|
||||
link = snewn(wh, int);
|
||||
i = 0;
|
||||
|
||||
@ -1011,12 +1018,12 @@ static game_state *new_game(midend *me, const game_params *params,
|
||||
state->movecount = 0;
|
||||
state->imm = snew(struct game_immutable_state);
|
||||
state->imm->refcount = 1;
|
||||
state->imm->forcefield = snewn(wh, unsigned char);
|
||||
state->imm->forcefield = snewn(wh, bool);
|
||||
|
||||
i = 0;
|
||||
|
||||
while (*desc && *desc != ',') {
|
||||
int f = false;
|
||||
bool f = false;
|
||||
|
||||
assert(i < wh);
|
||||
|
||||
@ -1176,11 +1183,11 @@ static char *game_text_format(const game_state *state)
|
||||
}
|
||||
|
||||
struct game_ui {
|
||||
int dragging;
|
||||
bool dragging;
|
||||
int drag_anchor;
|
||||
int drag_offset_x, drag_offset_y;
|
||||
int drag_currpos;
|
||||
unsigned char *reachable;
|
||||
bool *reachable;
|
||||
int *bfs_queue; /* used as scratch in interpret_move */
|
||||
};
|
||||
|
||||
@ -1192,8 +1199,8 @@ static game_ui *new_ui(const game_state *state)
|
||||
ui->dragging = false;
|
||||
ui->drag_anchor = ui->drag_currpos = -1;
|
||||
ui->drag_offset_x = ui->drag_offset_y = -1;
|
||||
ui->reachable = snewn(wh, unsigned char);
|
||||
memset(ui->reachable, 0, wh);
|
||||
ui->reachable = snewn(wh, bool);
|
||||
memset(ui->reachable, 0, wh * sizeof(bool));
|
||||
ui->bfs_queue = snewn(wh, int);
|
||||
|
||||
return ui;
|
||||
@ -1235,7 +1242,7 @@ struct game_drawstate {
|
||||
int tilesize;
|
||||
int w, h;
|
||||
unsigned long *grid; /* what's currently displayed */
|
||||
int started;
|
||||
bool started;
|
||||
};
|
||||
|
||||
static char *interpret_move(const game_state *state, game_ui *ui,
|
||||
@ -1274,7 +1281,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
|
||||
* the anchor, to find all the places to which this block
|
||||
* can be dragged.
|
||||
*/
|
||||
memset(ui->reachable, false, wh);
|
||||
memset(ui->reachable, 0, wh * sizeof(bool));
|
||||
qhead = qtail = 0;
|
||||
ui->reachable[i] = true;
|
||||
ui->bfs_queue[qtail++] = i;
|
||||
@ -1393,7 +1400,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
|
||||
ui->dragging = false;
|
||||
ui->drag_anchor = ui->drag_currpos = -1;
|
||||
ui->drag_offset_x = ui->drag_offset_y = -1;
|
||||
memset(ui->reachable, 0, wh);
|
||||
memset(ui->reachable, 0, wh * sizeof(bool));
|
||||
|
||||
return str;
|
||||
} else if (button == ' ' && state->soln) {
|
||||
@ -1415,8 +1422,8 @@ static char *interpret_move(const game_state *state, game_ui *ui,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int move_piece(int w, int h, const unsigned char *src,
|
||||
unsigned char *dst, unsigned char *ff, int from, int to)
|
||||
static bool move_piece(int w, int h, const unsigned char *src,
|
||||
unsigned char *dst, bool *ff, int from, int to)
|
||||
{
|
||||
int wh = w*h;
|
||||
int i, j;
|
||||
@ -2141,9 +2148,9 @@ static void game_redraw(drawing *dr, game_drawstate *ds,
|
||||
board = snewn(wh, unsigned char);
|
||||
memcpy(board, state->board, wh);
|
||||
if (ui->dragging) {
|
||||
int mpret = move_piece(w, h, state->board, board,
|
||||
state->imm->forcefield,
|
||||
ui->drag_anchor, ui->drag_currpos);
|
||||
bool mpret = move_piece(w, h, state->board, board,
|
||||
state->imm->forcefield,
|
||||
ui->drag_anchor, ui->drag_currpos);
|
||||
assert(mpret);
|
||||
}
|
||||
|
||||
@ -2359,8 +2366,9 @@ int main(int argc, char **argv)
|
||||
{
|
||||
game_params *p;
|
||||
game_state *s;
|
||||
char *id = NULL, *desc, *err;
|
||||
int count = false;
|
||||
char *id = NULL, *desc;
|
||||
const char *err;
|
||||
bool count = false;
|
||||
int ret;
|
||||
int *moves;
|
||||
|
||||
@ -2413,7 +2421,7 @@ int main(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
while (1) {
|
||||
int moveret;
|
||||
bool moveret;
|
||||
char *text = board_text_format(s->w, s->h, s->board,
|
||||
s->imm->forcefield);
|
||||
game_state *s2;
|
||||
|
@ -131,7 +131,7 @@ struct game_state {
|
||||
game_params p;
|
||||
unsigned char *grid;
|
||||
int px, py;
|
||||
int completed;
|
||||
bool completed;
|
||||
};
|
||||
|
||||
static game_params *default_params(void)
|
||||
@ -300,7 +300,7 @@ static const char *validate_params(const game_params *params, bool full)
|
||||
*/
|
||||
|
||||
static void sokoban_generate(int w, int h, unsigned char *grid, int moves,
|
||||
int nethack, random_state *rs)
|
||||
bool nethack, random_state *rs)
|
||||
{
|
||||
struct pull {
|
||||
int ox, oy, nx, ny, score;
|
||||
@ -940,7 +940,7 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate,
|
||||
struct game_drawstate {
|
||||
game_params p;
|
||||
int tilesize;
|
||||
int started;
|
||||
bool started;
|
||||
unsigned short *grid;
|
||||
};
|
||||
|
||||
@ -1099,7 +1099,8 @@ static game_state *execute_move(const game_state *state, const char *move)
|
||||
{
|
||||
int w = state->p.w, h = state->p.h;
|
||||
int px = state->px, py = state->py;
|
||||
int dx, dy, nx, ny, nbx, nby, type, m, i, freebarrels, freetargets;
|
||||
int dx, dy, nx, ny, nbx, nby, type, m, i;
|
||||
bool freebarrels, freetargets;
|
||||
game_state *ret;
|
||||
|
||||
if (*move < '1' || *move == '5' || *move > '9' || move[1])
|
||||
|
Reference in New Issue
Block a user