summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/cube.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2018-12-21 22:13:13 -0500
committerFranklin Wei <git@fwei.tk>2018-12-21 22:13:33 -0500
commitb3356e3aff34a4ab94778e7f6a8db43f9135296c (patch)
tree9119f850f2138db65da93461505b0a9b08e56d32 /apps/plugins/puzzles/src/cube.c
parentf08d218e676f9ee8b5c26e755088671baf3a70b7 (diff)
downloadrockbox-b3356e3aff34a4ab94778e7f6a8db43f9135296c.zip
rockbox-b3356e3aff34a4ab94778e7f6a8db43f9135296c.tar.gz
rockbox-b3356e3aff34a4ab94778e7f6a8db43f9135296c.tar.bz2
rockbox-b3356e3aff34a4ab94778e7f6a8db43f9135296c.tar.xz
puzzles: resync with upstream
This brings the code to upstream commit 3ece3d6 (I've made my own Rockbox- specific changes on top of that). Changes include using C99 `bool' throughout, and minor logic fixes for some puzzles. Change-Id: Ie823e73ae49a8ee1de411d6d406df2ba835af541
Diffstat (limited to 'apps/plugins/puzzles/src/cube.c')
-rw-r--r--apps/plugins/puzzles/src/cube.c74
1 files changed, 37 insertions, 37 deletions
diff --git a/apps/plugins/puzzles/src/cube.c b/apps/plugins/puzzles/src/cube.c
index 7491565..bda7623 100644
--- a/apps/plugins/puzzles/src/cube.c
+++ b/apps/plugins/puzzles/src/cube.c
@@ -178,7 +178,7 @@ struct grid_square {
int npoints;
float points[8]; /* maximum */
int directions[8]; /* bit masks showing point pairs */
- int flip;
+ bool flip;
int tetra_class;
};
@@ -220,7 +220,7 @@ struct game_state {
int dpkey[2]; /* key-point indices into polyhedron */
int previous;
float angle;
- int completed;
+ int completed; /* stores move count at completion */
int movecount;
};
@@ -235,7 +235,7 @@ static game_params *default_params(void)
return ret;
}
-static int game_fetch_preset(int i, char **name, game_params **params)
+static bool game_fetch_preset(int i, char **name, game_params **params)
{
game_params *ret = snew(game_params);
const char *str;
@@ -267,12 +267,12 @@ static int game_fetch_preset(int i, char **name, game_params **params)
break;
default:
sfree(ret);
- return FALSE;
+ return false;
}
*name = dupstr(str);
*params = ret;
- return TRUE;
+ return true;
}
static void free_params(game_params *params)
@@ -304,7 +304,7 @@ static void decode_params(game_params *ret, char const *string)
}
}
-static char *encode_params(const game_params *params, int full)
+static char *encode_params(const game_params *params, bool full)
{
char data[256];
@@ -348,7 +348,7 @@ static void enum_grid_squares(const game_params *params, egc_callback callback,
sq.directions[DOWN_LEFT] = 0; /* no diagonals in a square */
sq.directions[DOWN_RIGHT] = 0; /* no diagonals in a square */
- sq.flip = FALSE;
+ sq.flip = false;
/*
* This is supremely irrelevant, but just to avoid
@@ -406,7 +406,7 @@ static void enum_grid_squares(const game_params *params, egc_callback callback,
sq.directions[DOWN_LEFT] = sq.directions[LEFT];
sq.directions[DOWN_RIGHT] = sq.directions[RIGHT];
- sq.flip = TRUE;
+ sq.flip = true;
if (firstix < 0)
firstix = ix & 3;
@@ -451,7 +451,7 @@ static void enum_grid_squares(const game_params *params, egc_callback callback,
sq.directions[UP_LEFT] = sq.directions[LEFT];
sq.directions[UP_RIGHT] = sq.directions[RIGHT];
- sq.flip = FALSE;
+ sq.flip = false;
if (firstix < 0)
firstix = (ix - 1) & 3;
@@ -534,7 +534,7 @@ static void count_grid_square_callback(void *ctx, struct grid_square *sq)
classes[thisclass]++;
}
-static const char *validate_params(const game_params *params, int full)
+static const char *validate_params(const game_params *params, bool full)
{
int classes[5];
int i;
@@ -543,8 +543,8 @@ static const char *validate_params(const game_params *params, int full)
return "Unrecognised solid type";
if (solids[params->solid]->order == 4) {
- if (params->d1 <= 0 || params->d2 <= 0)
- return "Both grid dimensions must be greater than zero";
+ if (params->d1 <= 1 || params->d2 <= 1)
+ return "Both grid dimensions must be greater than one";
} else {
if (params->d1 <= 0 && params->d2 <= 0)
return "At least one grid dimension must be greater than zero";
@@ -595,11 +595,11 @@ static void classify_grid_square_callback(void *ctx, struct grid_square *sq)
}
static char *new_game_desc(const game_params *params, random_state *rs,
- char **aux, int interactive)
+ char **aux, bool interactive)
{
struct grid_data data;
int i, j, k, m, area, facesperclass;
- int *flags;
+ bool *flags;
char *desc, *p;
/*
@@ -634,16 +634,16 @@ static char *new_game_desc(const game_params *params, random_state *rs,
* So now we know how many faces to allocate in each class. Get
* on with it.
*/
- flags = snewn(area, int);
+ flags = snewn(area, bool);
for (i = 0; i < area; i++)
- flags[i] = FALSE;
+ flags[i] = false;
for (i = 0; i < data.nclasses; i++) {
for (j = 0; j < facesperclass; j++) {
int n = random_upto(rs, data.nsquares[i]);
assert(!flags[data.gridptrs[i][n]]);
- flags[data.gridptrs[i][n]] = TRUE;
+ flags[data.gridptrs[i][n]] = true;
/*
* Move everything else up the array. I ought to use a
@@ -727,8 +727,8 @@ static int lowest_face(const struct solid *solid)
return best;
}
-static int align_poly(const struct solid *solid, struct grid_square *sq,
- int *pkey)
+static bool align_poly(const struct solid *solid, struct grid_square *sq,
+ int *pkey)
{
float zmin;
int i, j;
@@ -768,14 +768,14 @@ static int align_poly(const struct solid *solid, struct grid_square *sq,
}
if (matches != 1 || index < 0)
- return FALSE;
+ return false;
pkey[j] = index;
}
- return TRUE;
+ return true;
}
-static void flip_poly(struct solid *solid, int flip)
+static void flip_poly(struct solid *solid, bool flip)
{
int i;
@@ -791,7 +791,7 @@ static void flip_poly(struct solid *solid, int flip)
}
}
-static struct solid *transform_poly(const struct solid *solid, int flip,
+static struct solid *transform_poly(const struct solid *solid, bool flip,
int key0, int key1, float angle)
{
struct solid *ret = snew(struct solid);
@@ -918,7 +918,7 @@ static game_state *new_game(midend *me, const game_params *params,
break;
}
if (v & j)
- SET_SQUARE(state, i, TRUE);
+ SET_SQUARE(state, i, true);
j >>= 1;
if (j == 0)
j = 8;
@@ -938,7 +938,7 @@ static game_state *new_game(midend *me, const game_params *params,
*/
{
int pkey[4];
- int ret;
+ bool ret;
ret = align_poly(state->solid, &state->grid->squares[state->current], pkey);
assert(ret);
@@ -1005,9 +1005,9 @@ static char *solve_game(const game_state *state, const game_state *currstate,
return NULL;
}
-static int game_can_format_as_text_now(const game_params *params)
+static bool game_can_format_as_text_now(const game_params *params)
{
- return TRUE;
+ return true;
}
static char *game_text_format(const game_state *state)
@@ -1312,7 +1312,7 @@ static game_state *execute_move(const game_state *from, const char *move)
*/
{
int all_pkey[4];
- int success;
+ bool success;
if (from->solid->order == 4 && direction == UP)
angle = -angle; /* HACK */
@@ -1418,7 +1418,7 @@ static game_state *execute_move(const game_state *from, const char *move)
*/
{
int pkey[4];
- int success;
+ bool success;
success = align_poly(ret->solid, &ret->grid->squares[ret->current], pkey);
assert(success);
@@ -1713,9 +1713,9 @@ static int game_status(const game_state *state)
return state->completed ? +1 : 0;
}
-static int game_timing_state(const game_state *state, game_ui *ui)
+static bool game_timing_state(const game_state *state, game_ui *ui)
{
- return TRUE;
+ return true;
}
static void game_print_size(const game_params *params, float *x, float *y)
@@ -1738,15 +1738,15 @@ const struct game thegame = {
encode_params,
free_params,
dup_params,
- TRUE, game_configure, custom_params,
+ true, game_configure, custom_params,
validate_params,
new_game_desc,
validate_desc,
new_game,
dup_game,
free_game,
- FALSE, solve_game,
- FALSE, game_can_format_as_text_now, game_text_format,
+ false, solve_game,
+ false, game_can_format_as_text_now, game_text_format,
new_ui,
free_ui,
encode_ui,
@@ -1763,8 +1763,8 @@ const struct game thegame = {
game_anim_length,
game_flash_length,
game_status,
- FALSE, FALSE, game_print_size, game_print,
- TRUE, /* wants_statusbar */
- FALSE, game_timing_state,
+ false, false, game_print_size, game_print,
+ true, /* wants_statusbar */
+ false, game_timing_state,
0, /* flags */
};