summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/loopgen.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/loopgen.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/loopgen.c')
-rw-r--r--apps/plugins/puzzles/src/loopgen.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/apps/plugins/puzzles/src/loopgen.c b/apps/plugins/puzzles/src/loopgen.c
index 0b69904..e738d4a 100644
--- a/apps/plugins/puzzles/src/loopgen.c
+++ b/apps/plugins/puzzles/src/loopgen.c
@@ -75,16 +75,16 @@ static int black_sort_cmpfn(void *v1, void *v2)
/* 'board' is an array of enum face_colour, indicating which faces are
* currently black/white/grey. 'colour' is FACE_WHITE or FACE_BLACK.
* Returns whether it's legal to colour the given face with this colour. */
-static int can_colour_face(grid *g, char* board, int face_index,
- enum face_colour colour)
+static bool can_colour_face(grid *g, char* board, int face_index,
+ enum face_colour colour)
{
int i, j;
grid_face *test_face = g->faces + face_index;
grid_face *starting_face, *current_face;
grid_dot *starting_dot;
int transitions;
- int current_state, s; /* booleans: equal or not-equal to 'colour' */
- int found_same_coloured_neighbour = FALSE;
+ bool current_state, s; /* equal or not-equal to 'colour' */
+ bool found_same_coloured_neighbour = false;
assert(board[face_index] != colour);
/* Can only consider a face for colouring if it's adjacent to a face
@@ -93,12 +93,12 @@ static int can_colour_face(grid *g, char* board, int face_index,
grid_edge *e = test_face->edges[i];
grid_face *f = (e->face1 == test_face) ? e->face2 : e->face1;
if (FACE_COLOUR(f) == colour) {
- found_same_coloured_neighbour = TRUE;
+ found_same_coloured_neighbour = true;
break;
}
}
if (!found_same_coloured_neighbour)
- return FALSE;
+ return false;
/* Need to avoid creating a loop of faces of this colour around some
* differently-coloured faces.
@@ -158,11 +158,11 @@ static int can_colour_face(grid *g, char* board, int face_index,
current_state = (FACE_COLOUR(current_face) == colour);
starting_dot = NULL;
starting_face = NULL;
- while (TRUE) {
+ while (true) {
/* Advance to next face.
* Need to loop here because it might take several goes to
* find it. */
- while (TRUE) {
+ while (true) {
j++;
if (j == test_face->dots[i]->order)
j = 0;
@@ -206,7 +206,7 @@ static int can_colour_face(grid *g, char* board, int face_index,
}
}
- return (transitions == 2) ? TRUE : FALSE;
+ return (transitions == 2) ? true : false;
}
/* Count the number of neighbours of 'face', having colour 'colour' */
@@ -306,7 +306,7 @@ void generate_loop(grid *g, char *board, random_state *rs,
tree234 *lightable_faces_sorted;
tree234 *darkable_faces_sorted;
int *face_list;
- int do_random_pass;
+ bool do_random_pass;
/* Make a board */
memset(board, FACE_GREY, num_faces);
@@ -361,7 +361,7 @@ void generate_loop(grid *g, char *board, random_state *rs,
}
/* Colour faces one at a time until no more faces are colourable. */
- while (TRUE)
+ while (true)
{
enum face_colour colour;
tree234 *faces_to_pick;
@@ -501,12 +501,12 @@ void generate_loop(grid *g, char *board, random_state *rs,
* make some illicit deductions. To combat this (and make the path more
* interesting), we do one final pass making random flips. */
- /* Set to TRUE for final pass */
- do_random_pass = FALSE;
+ /* Set to true for final pass */
+ do_random_pass = false;
- while (TRUE) {
+ while (true) {
/* Remember whether a flip occurred during this pass */
- int flipped = FALSE;
+ bool flipped = false;
for (i = 0; i < num_faces; ++i) {
int j = face_list[i];
@@ -522,14 +522,14 @@ void generate_loop(grid *g, char *board, random_state *rs,
/* normal pass - flip when neighbour count is 1 */
if (face_num_neighbours(g, board, face, opp) == 1) {
board[j] = opp;
- flipped = TRUE;
+ flipped = true;
}
}
}
}
if (do_random_pass) break;
- if (!flipped) do_random_pass = TRUE;
+ if (!flipped) do_random_pass = true;
}
sfree(face_list);