diff options
author | Franklin Wei <git@fwei.tk> | 2017-10-23 17:19:29 -0400 |
---|---|---|
committer | Franklin Wei <git@fwei.tk> | 2017-10-23 17:19:29 -0400 |
commit | ef1306764e6443d67612542654f252b376c5993e (patch) | |
tree | 5f064178c1f9a23695b1b52b8bd487434be9006e /apps/plugins/puzzles/src/solo.c | |
parent | 7a8c9daf7ef5a8b38d4c4f6625ff2d9d8eb1aa0a (diff) | |
download | rockbox-ef1306764e6443d67612542654f252b376c5993e.tar.gz rockbox-ef1306764e6443d67612542654f252b376c5993e.zip |
puzzles: resync with upstream
There have been some improvements with regard to small screen sizes,
which will be nice to have.
Change-Id: I30c740514156258d2818fde325c1a751500f7611
Diffstat (limited to 'apps/plugins/puzzles/src/solo.c')
-rw-r--r-- | apps/plugins/puzzles/src/solo.c | 99 |
1 files changed, 48 insertions, 51 deletions
diff --git a/apps/plugins/puzzles/src/solo.c b/apps/plugins/puzzles/src/solo.c index 0d383c39aa..ef2852f1d9 100644 --- a/apps/plugins/puzzles/src/solo.c +++ b/apps/plugins/puzzles/src/solo.c | |||
@@ -299,9 +299,9 @@ static game_params *dup_params(const game_params *params) | |||
299 | static int game_fetch_preset(int i, char **name, game_params **params) | 299 | static int game_fetch_preset(int i, char **name, game_params **params) |
300 | { | 300 | { |
301 | static struct { | 301 | static struct { |
302 | char *title; | 302 | const char *title; |
303 | game_params params; | 303 | game_params params; |
304 | } presets[] = { | 304 | } const presets[] = { |
305 | { "2x2 Trivial", { 2, 2, SYMM_ROT2, DIFF_BLOCK, DIFF_KMINMAX, FALSE, FALSE } }, | 305 | { "2x2 Trivial", { 2, 2, SYMM_ROT2, DIFF_BLOCK, DIFF_KMINMAX, FALSE, FALSE } }, |
306 | { "2x3 Basic", { 2, 3, SYMM_ROT2, DIFF_SIMPLE, DIFF_KMINMAX, FALSE, FALSE } }, | 306 | { "2x3 Basic", { 2, 3, SYMM_ROT2, DIFF_SIMPLE, DIFF_KMINMAX, FALSE, FALSE } }, |
307 | { "3x3 Trivial", { 3, 3, SYMM_ROT2, DIFF_BLOCK, DIFF_KMINMAX, FALSE, FALSE } }, | 307 | { "3x3 Trivial", { 3, 3, SYMM_ROT2, DIFF_BLOCK, DIFF_KMINMAX, FALSE, FALSE } }, |
@@ -445,46 +445,39 @@ static config_item *game_configure(const game_params *params) | |||
445 | ret[0].name = "Columns of sub-blocks"; | 445 | ret[0].name = "Columns of sub-blocks"; |
446 | ret[0].type = C_STRING; | 446 | ret[0].type = C_STRING; |
447 | sprintf(buf, "%d", params->c); | 447 | sprintf(buf, "%d", params->c); |
448 | ret[0].sval = dupstr(buf); | 448 | ret[0].u.string.sval = dupstr(buf); |
449 | ret[0].ival = 0; | ||
450 | 449 | ||
451 | ret[1].name = "Rows of sub-blocks"; | 450 | ret[1].name = "Rows of sub-blocks"; |
452 | ret[1].type = C_STRING; | 451 | ret[1].type = C_STRING; |
453 | sprintf(buf, "%d", params->r); | 452 | sprintf(buf, "%d", params->r); |
454 | ret[1].sval = dupstr(buf); | 453 | ret[1].u.string.sval = dupstr(buf); |
455 | ret[1].ival = 0; | ||
456 | 454 | ||
457 | ret[2].name = "\"X\" (require every number in each main diagonal)"; | 455 | ret[2].name = "\"X\" (require every number in each main diagonal)"; |
458 | ret[2].type = C_BOOLEAN; | 456 | ret[2].type = C_BOOLEAN; |
459 | ret[2].sval = NULL; | 457 | ret[2].u.boolean.bval = params->xtype; |
460 | ret[2].ival = params->xtype; | ||
461 | 458 | ||
462 | ret[3].name = "Jigsaw (irregularly shaped sub-blocks)"; | 459 | ret[3].name = "Jigsaw (irregularly shaped sub-blocks)"; |
463 | ret[3].type = C_BOOLEAN; | 460 | ret[3].type = C_BOOLEAN; |
464 | ret[3].sval = NULL; | 461 | ret[3].u.boolean.bval = (params->r == 1); |
465 | ret[3].ival = (params->r == 1); | ||
466 | 462 | ||
467 | ret[4].name = "Killer (digit sums)"; | 463 | ret[4].name = "Killer (digit sums)"; |
468 | ret[4].type = C_BOOLEAN; | 464 | ret[4].type = C_BOOLEAN; |
469 | ret[4].sval = NULL; | 465 | ret[4].u.boolean.bval = params->killer; |
470 | ret[4].ival = params->killer; | ||
471 | 466 | ||
472 | ret[5].name = "Symmetry"; | 467 | ret[5].name = "Symmetry"; |
473 | ret[5].type = C_CHOICES; | 468 | ret[5].type = C_CHOICES; |
474 | ret[5].sval = ":None:2-way rotation:4-way rotation:2-way mirror:" | 469 | ret[5].u.choices.choicenames = ":None:2-way rotation:4-way rotation:2-way mirror:" |
475 | "2-way diagonal mirror:4-way mirror:4-way diagonal mirror:" | 470 | "2-way diagonal mirror:4-way mirror:4-way diagonal mirror:" |
476 | "8-way mirror"; | 471 | "8-way mirror"; |
477 | ret[5].ival = params->symm; | 472 | ret[5].u.choices.selected = params->symm; |
478 | 473 | ||
479 | ret[6].name = "Difficulty"; | 474 | ret[6].name = "Difficulty"; |
480 | ret[6].type = C_CHOICES; | 475 | ret[6].type = C_CHOICES; |
481 | ret[6].sval = ":Trivial:Basic:Intermediate:Advanced:Extreme:Unreasonable"; | 476 | ret[6].u.choices.choicenames = ":Trivial:Basic:Intermediate:Advanced:Extreme:Unreasonable"; |
482 | ret[6].ival = params->diff; | 477 | ret[6].u.choices.selected = params->diff; |
483 | 478 | ||
484 | ret[7].name = NULL; | 479 | ret[7].name = NULL; |
485 | ret[7].type = C_END; | 480 | ret[7].type = C_END; |
486 | ret[7].sval = NULL; | ||
487 | ret[7].ival = 0; | ||
488 | 481 | ||
489 | return ret; | 482 | return ret; |
490 | } | 483 | } |
@@ -493,22 +486,22 @@ static game_params *custom_params(const config_item *cfg) | |||
493 | { | 486 | { |
494 | game_params *ret = snew(game_params); | 487 | game_params *ret = snew(game_params); |
495 | 488 | ||
496 | ret->c = atoi(cfg[0].sval); | 489 | ret->c = atoi(cfg[0].u.string.sval); |
497 | ret->r = atoi(cfg[1].sval); | 490 | ret->r = atoi(cfg[1].u.string.sval); |
498 | ret->xtype = cfg[2].ival; | 491 | ret->xtype = cfg[2].u.boolean.bval; |
499 | if (cfg[3].ival) { | 492 | if (cfg[3].u.boolean.bval) { |
500 | ret->c *= ret->r; | 493 | ret->c *= ret->r; |
501 | ret->r = 1; | 494 | ret->r = 1; |
502 | } | 495 | } |
503 | ret->killer = cfg[4].ival; | 496 | ret->killer = cfg[4].u.boolean.bval; |
504 | ret->symm = cfg[5].ival; | 497 | ret->symm = cfg[5].u.choices.selected; |
505 | ret->diff = cfg[6].ival; | 498 | ret->diff = cfg[6].u.choices.selected; |
506 | ret->kdiff = DIFF_KINTERSECT; | 499 | ret->kdiff = DIFF_KINTERSECT; |
507 | 500 | ||
508 | return ret; | 501 | return ret; |
509 | } | 502 | } |
510 | 503 | ||
511 | static char *validate_params(const game_params *params, int full) | 504 | static const char *validate_params(const game_params *params, int full) |
512 | { | 505 | { |
513 | if (params->c < 2) | 506 | if (params->c < 2) |
514 | return "Both dimensions must be at least 2"; | 507 | return "Both dimensions must be at least 2"; |
@@ -838,19 +831,20 @@ static void solver_place(struct solver_usage *usage, int x, int y, int n) | |||
838 | */ | 831 | */ |
839 | struct solver_scratch; | 832 | struct solver_scratch; |
840 | static int solver_elim(struct solver_usage *usage, int *indices, | 833 | static int solver_elim(struct solver_usage *usage, int *indices, |
841 | char *fmt, ...) __attribute__((format(printf,3,4))); | 834 | const char *fmt, ...) |
835 | __attribute__((format(printf,3,4))); | ||
842 | static int solver_intersect(struct solver_usage *usage, | 836 | static int solver_intersect(struct solver_usage *usage, |
843 | int *indices1, int *indices2, char *fmt, ...) | 837 | int *indices1, int *indices2, const char *fmt, ...) |
844 | __attribute__((format(printf,4,5))); | 838 | __attribute__((format(printf,4,5))); |
845 | static int solver_set(struct solver_usage *usage, | 839 | static int solver_set(struct solver_usage *usage, |
846 | struct solver_scratch *scratch, | 840 | struct solver_scratch *scratch, |
847 | int *indices, char *fmt, ...) | 841 | int *indices, const char *fmt, ...) |
848 | __attribute__((format(printf,4,5))); | 842 | __attribute__((format(printf,4,5))); |
849 | #endif | 843 | #endif |
850 | 844 | ||
851 | static int solver_elim(struct solver_usage *usage, int *indices | 845 | static int solver_elim(struct solver_usage *usage, int *indices |
852 | #ifdef STANDALONE_SOLVER | 846 | #ifdef STANDALONE_SOLVER |
853 | , char *fmt, ... | 847 | , const char *fmt, ... |
854 | #endif | 848 | #endif |
855 | ) | 849 | ) |
856 | { | 850 | { |
@@ -914,7 +908,7 @@ static int solver_elim(struct solver_usage *usage, int *indices | |||
914 | static int solver_intersect(struct solver_usage *usage, | 908 | static int solver_intersect(struct solver_usage *usage, |
915 | int *indices1, int *indices2 | 909 | int *indices1, int *indices2 |
916 | #ifdef STANDALONE_SOLVER | 910 | #ifdef STANDALONE_SOLVER |
917 | , char *fmt, ... | 911 | , const char *fmt, ... |
918 | #endif | 912 | #endif |
919 | ) | 913 | ) |
920 | { | 914 | { |
@@ -992,7 +986,7 @@ static int solver_set(struct solver_usage *usage, | |||
992 | struct solver_scratch *scratch, | 986 | struct solver_scratch *scratch, |
993 | int *indices | 987 | int *indices |
994 | #ifdef STANDALONE_SOLVER | 988 | #ifdef STANDALONE_SOLVER |
995 | , char *fmt, ... | 989 | , const char *fmt, ... |
996 | #endif | 990 | #endif |
997 | ) | 991 | ) |
998 | { | 992 | { |
@@ -1358,7 +1352,7 @@ static int solver_forcing(struct solver_usage *usage, | |||
1358 | (ondiag1(yt*cr+xt) && ondiag1(y*cr+x)))))) { | 1352 | (ondiag1(yt*cr+xt) && ondiag1(y*cr+x)))))) { |
1359 | #ifdef STANDALONE_SOLVER | 1353 | #ifdef STANDALONE_SOLVER |
1360 | if (solver_show_working) { | 1354 | if (solver_show_working) { |
1361 | char *sep = ""; | 1355 | const char *sep = ""; |
1362 | int xl, yl; | 1356 | int xl, yl; |
1363 | printf("%*sforcing chain, %d at ends of ", | 1357 | printf("%*sforcing chain, %d at ends of ", |
1364 | solver_recurse_depth*4, "", orign); | 1358 | solver_recurse_depth*4, "", orign); |
@@ -2523,7 +2517,7 @@ static void solver(int cr, struct block_structure *blocks, | |||
2523 | 2517 | ||
2524 | #ifdef STANDALONE_SOLVER | 2518 | #ifdef STANDALONE_SOLVER |
2525 | if (solver_show_working) { | 2519 | if (solver_show_working) { |
2526 | char *sep = ""; | 2520 | const char *sep = ""; |
2527 | printf("%*srecursing on (%d,%d) [", | 2521 | printf("%*srecursing on (%d,%d) [", |
2528 | solver_recurse_depth*4, "", x + 1, y + 1); | 2522 | solver_recurse_depth*4, "", x + 1, y + 1); |
2529 | for (i = 0; i < j; i++) { | 2523 | for (i = 0; i < j; i++) { |
@@ -3161,7 +3155,8 @@ static int symmetries(const game_params *params, int x, int y, | |||
3161 | static char *encode_solve_move(int cr, digit *grid) | 3155 | static char *encode_solve_move(int cr, digit *grid) |
3162 | { | 3156 | { |
3163 | int i, len; | 3157 | int i, len; |
3164 | char *ret, *p, *sep; | 3158 | char *ret, *p; |
3159 | const char *sep; | ||
3165 | 3160 | ||
3166 | /* | 3161 | /* |
3167 | * It's surprisingly easy to work out _exactly_ how long this | 3162 | * It's surprisingly easy to work out _exactly_ how long this |
@@ -3861,7 +3856,8 @@ static const char *spec_to_grid(const char *desc, digit *grid, int area) | |||
3861 | * end of the block spec, and return an error string or NULL if everything | 3856 | * end of the block spec, and return an error string or NULL if everything |
3862 | * is OK. The DSF is stored in *PDSF. | 3857 | * is OK. The DSF is stored in *PDSF. |
3863 | */ | 3858 | */ |
3864 | static char *spec_to_dsf(const char **pdesc, int **pdsf, int cr, int area) | 3859 | static const char *spec_to_dsf(const char **pdesc, int **pdsf, |
3860 | int cr, int area) | ||
3865 | { | 3861 | { |
3866 | const char *desc = *pdesc; | 3862 | const char *desc = *pdesc; |
3867 | int pos = 0; | 3863 | int pos = 0; |
@@ -3929,7 +3925,7 @@ static char *spec_to_dsf(const char **pdesc, int **pdsf, int cr, int area) | |||
3929 | return NULL; | 3925 | return NULL; |
3930 | } | 3926 | } |
3931 | 3927 | ||
3932 | static char *validate_grid_desc(const char **pdesc, int range, int area) | 3928 | static const char *validate_grid_desc(const char **pdesc, int range, int area) |
3933 | { | 3929 | { |
3934 | const char *desc = *pdesc; | 3930 | const char *desc = *pdesc; |
3935 | int squares = 0; | 3931 | int squares = 0; |
@@ -3959,11 +3955,11 @@ static char *validate_grid_desc(const char **pdesc, int range, int area) | |||
3959 | return NULL; | 3955 | return NULL; |
3960 | } | 3956 | } |
3961 | 3957 | ||
3962 | static char *validate_block_desc(const char **pdesc, int cr, int area, | 3958 | static const char *validate_block_desc(const char **pdesc, int cr, int area, |
3963 | int min_nr_blocks, int max_nr_blocks, | 3959 | int min_nr_blocks, int max_nr_blocks, |
3964 | int min_nr_squares, int max_nr_squares) | 3960 | int min_nr_squares, int max_nr_squares) |
3965 | { | 3961 | { |
3966 | char *err; | 3962 | const char *err; |
3967 | int *dsf; | 3963 | int *dsf; |
3968 | 3964 | ||
3969 | err = spec_to_dsf(pdesc, &dsf, cr, area); | 3965 | err = spec_to_dsf(pdesc, &dsf, cr, area); |
@@ -4036,10 +4032,10 @@ static char *validate_block_desc(const char **pdesc, int cr, int area, | |||
4036 | return NULL; | 4032 | return NULL; |
4037 | } | 4033 | } |
4038 | 4034 | ||
4039 | static char *validate_desc(const game_params *params, const char *desc) | 4035 | static const char *validate_desc(const game_params *params, const char *desc) |
4040 | { | 4036 | { |
4041 | int cr = params->c * params->r, area = cr*cr; | 4037 | int cr = params->c * params->r, area = cr*cr; |
4042 | char *err; | 4038 | const char *err; |
4043 | 4039 | ||
4044 | err = validate_grid_desc(&desc, cr, area); | 4040 | err = validate_grid_desc(&desc, cr, area); |
4045 | if (err) | 4041 | if (err) |
@@ -4116,7 +4112,7 @@ static game_state *new_game(midend *me, const game_params *params, | |||
4116 | state->immutable[i] = TRUE; | 4112 | state->immutable[i] = TRUE; |
4117 | 4113 | ||
4118 | if (r == 1) { | 4114 | if (r == 1) { |
4119 | char *err; | 4115 | const char *err; |
4120 | int *dsf; | 4116 | int *dsf; |
4121 | assert(*desc == ','); | 4117 | assert(*desc == ','); |
4122 | desc++; | 4118 | desc++; |
@@ -4134,7 +4130,7 @@ static game_state *new_game(midend *me, const game_params *params, | |||
4134 | make_blocks_from_whichblock(state->blocks); | 4130 | make_blocks_from_whichblock(state->blocks); |
4135 | 4131 | ||
4136 | if (params->killer) { | 4132 | if (params->killer) { |
4137 | char *err; | 4133 | const char *err; |
4138 | int *dsf; | 4134 | int *dsf; |
4139 | assert(*desc == ','); | 4135 | assert(*desc == ','); |
4140 | desc++; | 4136 | desc++; |
@@ -4234,7 +4230,7 @@ static void free_game(game_state *state) | |||
4234 | } | 4230 | } |
4235 | 4231 | ||
4236 | static char *solve_game(const game_state *state, const game_state *currstate, | 4232 | static char *solve_game(const game_state *state, const game_state *currstate, |
4237 | const char *ai, char **error) | 4233 | const char *ai, const char **error) |
4238 | { | 4234 | { |
4239 | int cr = state->cr; | 4235 | int cr = state->cr; |
4240 | char *ret; | 4236 | char *ret; |
@@ -4586,7 +4582,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
4586 | ui->hpencil = 0; | 4582 | ui->hpencil = 0; |
4587 | } | 4583 | } |
4588 | ui->hcursor = 0; | 4584 | ui->hcursor = 0; |
4589 | return ""; /* UI activity occurred */ | 4585 | return UI_UPDATE; |
4590 | } | 4586 | } |
4591 | if (button == RIGHT_BUTTON) { | 4587 | if (button == RIGHT_BUTTON) { |
4592 | /* | 4588 | /* |
@@ -4606,19 +4602,19 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
4606 | ui->hshow = 0; | 4602 | ui->hshow = 0; |
4607 | } | 4603 | } |
4608 | ui->hcursor = 0; | 4604 | ui->hcursor = 0; |
4609 | return ""; /* UI activity occurred */ | 4605 | return UI_UPDATE; |
4610 | } | 4606 | } |
4611 | } | 4607 | } |
4612 | if (IS_CURSOR_MOVE(button)) { | 4608 | if (IS_CURSOR_MOVE(button)) { |
4613 | move_cursor(button, &ui->hx, &ui->hy, cr, cr, 0); | 4609 | move_cursor(button, &ui->hx, &ui->hy, cr, cr, 0); |
4614 | ui->hshow = ui->hcursor = 1; | 4610 | ui->hshow = ui->hcursor = 1; |
4615 | return ""; | 4611 | return UI_UPDATE; |
4616 | } | 4612 | } |
4617 | if (ui->hshow && | 4613 | if (ui->hshow && |
4618 | (button == CURSOR_SELECT)) { | 4614 | (button == CURSOR_SELECT)) { |
4619 | ui->hpencil = 1 - ui->hpencil; | 4615 | ui->hpencil = 1 - ui->hpencil; |
4620 | ui->hcursor = 1; | 4616 | ui->hcursor = 1; |
4621 | return ""; | 4617 | return UI_UPDATE; |
4622 | } | 4618 | } |
4623 | 4619 | ||
4624 | if (ui->hshow && | 4620 | if (ui->hshow && |
@@ -5584,7 +5580,8 @@ int main(int argc, char **argv) | |||
5584 | { | 5580 | { |
5585 | game_params *p; | 5581 | game_params *p; |
5586 | game_state *s; | 5582 | game_state *s; |
5587 | char *id = NULL, *desc, *err; | 5583 | char *id = NULL, *desc; |
5584 | const char *err; | ||
5588 | int grade = FALSE; | 5585 | int grade = FALSE; |
5589 | struct difficulty dlev; | 5586 | struct difficulty dlev; |
5590 | 5587 | ||