Skip to content

Commit

Permalink
Merge branch 'upstream'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisboyle committed Dec 19, 2016
2 parents 104e632 + 0b34887 commit 6a85427
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 38 deletions.
8 changes: 4 additions & 4 deletions app/src/main/assets-sources/puzzles.but
Expand Up @@ -1593,11 +1593,11 @@ affected by balls in one of the following ways:
re-emerge. This includes beams that meet a ball on the first rank
of the arena.

\b A beam with a ball to its front-left square gets deflected 90 degrees
to the right.
\b A beam with a ball in its front-left square and no ball ahead of it
gets deflected 90 degrees to the right.

\b A beam with a ball to its front-right square gets similarly deflected
to the left.
\b A beam with a ball in its front-right square and no ball ahead of
it gets similarly deflected to the left.

\b A beam that would re-emerge from its entry location is considered to be
\q{reflected}.
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/jni/pearl.c
Expand Up @@ -1610,8 +1610,6 @@ static void check_completion(game_state *state, int mark)
*/
for (i = 0; i < w*h; i++) {
int comp = dsf_canonify(dsf, i);
if (component_state[comp] == COMP_PATH)
comp = -1; /* part of the 'all paths' quasi-component */
if ((component_state[comp] == COMP_PATH &&
-1 != largest_comp) ||
(component_state[comp] == COMP_LOOP &&
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/jni/signpost.c
Expand Up @@ -286,7 +286,7 @@ static int check_nums(game_state *orig, game_state *copy, int only_immutable)
int i, ret = 1;
assert(copy->n == orig->n);
for (i = 0; i < copy->n; i++) {
if (only_immutable && !copy->flags[i] & FLAG_IMMUTABLE) continue;
if (only_immutable && !(copy->flags[i] & FLAG_IMMUTABLE)) continue;
assert(copy->nums[i] >= 0);
assert(copy->nums[i] <= copy->n);
if (copy->nums[i] != orig->nums[i]) {
Expand Down
78 changes: 52 additions & 26 deletions app/src/main/jni/solo.c
Expand Up @@ -2961,11 +2961,46 @@ static int gridgen(int cr, struct block_structure *blocks,
* End of grid generator code.
*/

static int check_killer_cage_sum(struct block_structure *kblocks,
digit *kgrid, digit *grid, int blk)
{
/*
* Returns: -1 if the cage has any empty square; 0 if all squares
* are full but the sum is wrong; +1 if all squares are full and
* they have the right sum.
*
* Does not check uniqueness of numbers within the cage; that's
* done elsewhere (because in error highlighting it needs to be
* detected separately so as to flag the error in a visually
* different way).
*/
int n_squares = kblocks->nr_squares[blk];
int sum = 0, clue = 0;
int i;

for (i = 0; i < n_squares; i++) {
int xy = kblocks->blocks[blk][i];

if (grid[xy] == 0)
return -1;
sum += grid[xy];

if (kgrid[xy]) {
assert(clue == 0);
clue = kgrid[xy];
}
}

assert(clue != 0);
return sum == clue;
}

/*
* Check whether a grid contains a valid complete puzzle.
*/
static int check_valid(int cr, struct block_structure *blocks,
struct block_structure *kblocks, int xtype, digit *grid)
struct block_structure *kblocks,
digit *kgrid, int xtype, digit *grid)
{
unsigned char *used;
int x, y, i, j, n;
Expand Down Expand Up @@ -3020,7 +3055,9 @@ static int check_valid(int cr, struct block_structure *blocks,

/*
* Check that each Killer cage, if any, contains at most one of
* everything.
* everything. If we also know the clues for those cages (which we
* might not, when this function is called early in puzzle
* generation), we also check that they all have the right sum.
*/
if (kblocks) {
for (i = 0; i < kblocks->nr_blocks; i++) {
Expand All @@ -3034,6 +3071,11 @@ static int check_valid(int cr, struct block_structure *blocks,
}
used[grid[kblocks->blocks[i][j]]-1] = TRUE;
}

if (kgrid && check_killer_cage_sum(kblocks, kgrid, grid, i) != 1) {
sfree(used);
return FALSE;
}
}
}

Expand Down Expand Up @@ -3621,8 +3663,7 @@ static char *new_game_desc(const game_params *params, random_state *rs,

if (!gridgen(cr, blocks, kblocks, params->xtype, grid, rs, area*area))
continue;

assert(check_valid(cr, blocks, kblocks, params->xtype, grid));
assert(check_valid(cr, blocks, kblocks, NULL, params->xtype, grid));

/*
* Save the solved grid in aux.
Expand Down Expand Up @@ -4726,8 +4767,9 @@ static game_state *execute_move(const game_state *from, const char *move)
* We've made a real change to the grid. Check to see
* if the game has been completed.
*/
if (!ret->completed && check_valid(cr, ret->blocks, ret->kblocks,
ret->xtype, ret->grid)) {
if (!ret->completed && check_valid(
cr, ret->blocks, ret->kblocks, ret->kgrid,
ret->xtype, ret->grid)) {
ret->completed = TRUE;
}
}
Expand Down Expand Up @@ -5247,26 +5289,10 @@ static void game_redraw(drawing *dr, game_drawstate *ds,
highlight |= 16;

if (d && state->kblocks) {
int i, b = state->kblocks->whichblock[y*cr+x];
int n_squares = state->kblocks->nr_squares[b];
int sum = 0, clue = 0;
for (i = 0; i < n_squares; i++) {
int xy = state->kblocks->blocks[b][i];
if (state->grid[xy] == 0)
break;

sum += state->grid[xy];
if (state->kgrid[xy]) {
assert(clue == 0);
clue = state->kgrid[xy];
}
}

if (i == n_squares) {
assert(clue != 0);
if (sum != clue)
highlight |= 32;
}
if (check_killer_cage_sum(
state->kblocks, state->kgrid, state->grid,
state->kblocks->whichblock[y*cr+x]) == 0)
highlight |= 32;
}

draw_number(dr, ds, state, x, y, highlight);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/jni/tracks.c
Expand Up @@ -1079,7 +1079,7 @@ static int solve_check_single_sub(game_state *state, int si, int id, int n,
x = i%w;
y = i/w;
if (abs(ox-x) > 1 || abs(oy-y) > 1) {
if (!state->sflags[i] & S_TRACK)
if (!(state->sflags[i] & S_TRACK))
did += solve_set_sflag(state, x, y, S_NOTRACK, what);
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/jni/unequal.c
Expand Up @@ -1218,7 +1218,7 @@ static game_state *load_game(const game_params *params, const char *desc,
why = _("Too much data to fit in grid"); goto fail;
}

if (*p < '0' && *p > '9') {
if (*p < '0' || *p > '9') {
why = _("Expecting number in game description"); goto fail;
}
n = atoi(p);
Expand Down
32 changes: 29 additions & 3 deletions not-in-use/gtk.c
Expand Up @@ -1936,14 +1936,32 @@ static gint configure_window(GtkWidget *widget,
return FALSE;
}

#if GTK_CHECK_VERSION(3,0,0)
static int window_extra_height(frontend *fe)
{
int ret = 0;
if (fe->menubar) {
GtkRequisition req;
gtk_widget_get_preferred_size(fe->menubar, &req, NULL);
ret += req.height;
}
if (fe->statusbar) {
GtkRequisition req;
gtk_widget_get_preferred_size(fe->statusbar, &req, NULL);
ret += req.height;
}
return ret;
}
#endif

static void resize_fe(frontend *fe)
{
int x, y;

get_size(fe, &x, &y);

#if GTK_CHECK_VERSION(3,0,0)
gtk_window_resize_to_geometry(GTK_WINDOW(fe->window), x, y);
gtk_window_resize(GTK_WINDOW(fe->window), x, y + window_extra_height(fe));
#else
fe->drawing_area_shrink_pending = FALSE;
gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), x, y);
Expand Down Expand Up @@ -2649,15 +2667,23 @@ static frontend *new_window(char *arg, int argtype, char **error)
#endif
{
GdkGeometry geom;
geom.base_width = geom.base_height = 0;
geom.base_width = 0;
#if GTK_CHECK_VERSION(3,0,0)
geom.base_height = window_extra_height(fe);
gtk_window_set_geometry_hints(GTK_WINDOW(fe->window), NULL,
&geom, GDK_HINT_BASE_SIZE);
#else
geom.base_height = 0;
gtk_window_set_geometry_hints(GTK_WINDOW(fe->window), fe->area,
&geom, GDK_HINT_BASE_SIZE);
#endif
}
fe->w = -1;
fe->h = -1;
get_size(fe, &x, &y);
#if GTK_CHECK_VERSION(3,0,0)
gtk_window_set_default_geometry(GTK_WINDOW(fe->window), x, y);
gtk_window_set_default_size(GTK_WINDOW(fe->window),
x, y + window_extra_height(fe));
#else
fe->drawing_area_shrink_pending = FALSE;
gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), x, y);
Expand Down

0 comments on commit 6a85427

Please sign in to comment.