summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/guess.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/puzzles/src/guess.c')
-rw-r--r--apps/plugins/puzzles/src/guess.c63
1 files changed, 29 insertions, 34 deletions
diff --git a/apps/plugins/puzzles/src/guess.c b/apps/plugins/puzzles/src/guess.c
index 8f058638da..a14f3bdc4d 100644
--- a/apps/plugins/puzzles/src/guess.c
+++ b/apps/plugins/puzzles/src/guess.c
@@ -74,7 +74,7 @@ static game_params *dup_params(const game_params *params)
74} 74}
75 75
76static const struct { 76static const struct {
77 char *name; 77 const char *name;
78 game_params params; 78 game_params params;
79} guess_presets[] = { 79} guess_presets[] = {
80 {"Standard", {6, 4, 10, FALSE, TRUE}}, 80 {"Standard", {6, 4, 10, FALSE, TRUE}},
@@ -166,35 +166,28 @@ static config_item *game_configure(const game_params *params)
166 ret[0].name = "Colours"; 166 ret[0].name = "Colours";
167 ret[0].type = C_STRING; 167 ret[0].type = C_STRING;
168 sprintf(buf, "%d", params->ncolours); 168 sprintf(buf, "%d", params->ncolours);
169 ret[0].sval = dupstr(buf); 169 ret[0].u.string.sval = dupstr(buf);
170 ret[0].ival = 0;
171 170
172 ret[1].name = "Pegs per guess"; 171 ret[1].name = "Pegs per guess";
173 ret[1].type = C_STRING; 172 ret[1].type = C_STRING;
174 sprintf(buf, "%d", params->npegs); 173 sprintf(buf, "%d", params->npegs);
175 ret[1].sval = dupstr(buf); 174 ret[1].u.string.sval = dupstr(buf);
176 ret[1].ival = 0;
177 175
178 ret[2].name = "Guesses"; 176 ret[2].name = "Guesses";
179 ret[2].type = C_STRING; 177 ret[2].type = C_STRING;
180 sprintf(buf, "%d", params->nguesses); 178 sprintf(buf, "%d", params->nguesses);
181 ret[2].sval = dupstr(buf); 179 ret[2].u.string.sval = dupstr(buf);
182 ret[2].ival = 0;
183 180
184 ret[3].name = "Allow blanks"; 181 ret[3].name = "Allow blanks";
185 ret[3].type = C_BOOLEAN; 182 ret[3].type = C_BOOLEAN;
186 ret[3].sval = NULL; 183 ret[3].u.boolean.bval = params->allow_blank;
187 ret[3].ival = params->allow_blank;
188 184
189 ret[4].name = "Allow duplicates"; 185 ret[4].name = "Allow duplicates";
190 ret[4].type = C_BOOLEAN; 186 ret[4].type = C_BOOLEAN;
191 ret[4].sval = NULL; 187 ret[4].u.boolean.bval = params->allow_multiple;
192 ret[4].ival = params->allow_multiple;
193 188
194 ret[5].name = NULL; 189 ret[5].name = NULL;
195 ret[5].type = C_END; 190 ret[5].type = C_END;
196 ret[5].sval = NULL;
197 ret[5].ival = 0;
198 191
199 return ret; 192 return ret;
200} 193}
@@ -203,17 +196,17 @@ static game_params *custom_params(const config_item *cfg)
203{ 196{
204 game_params *ret = snew(game_params); 197 game_params *ret = snew(game_params);
205 198
206 ret->ncolours = atoi(cfg[0].sval); 199 ret->ncolours = atoi(cfg[0].u.string.sval);
207 ret->npegs = atoi(cfg[1].sval); 200 ret->npegs = atoi(cfg[1].u.string.sval);
208 ret->nguesses = atoi(cfg[2].sval); 201 ret->nguesses = atoi(cfg[2].u.string.sval);
209 202
210 ret->allow_blank = cfg[3].ival; 203 ret->allow_blank = cfg[3].u.boolean.bval;
211 ret->allow_multiple = cfg[4].ival; 204 ret->allow_multiple = cfg[4].u.boolean.bval;
212 205
213 return ret; 206 return ret;
214} 207}
215 208
216static char *validate_params(const game_params *params, int full) 209static const char *validate_params(const game_params *params, int full)
217{ 210{
218 if (params->ncolours < 2 || params->npegs < 2) 211 if (params->ncolours < 2 || params->npegs < 2)
219 return "Trivial solutions are uninteresting"; 212 return "Trivial solutions are uninteresting";
@@ -287,7 +280,7 @@ newcol:
287 return ret; 280 return ret;
288} 281}
289 282
290static char *validate_desc(const game_params *params, const char *desc) 283static const char *validate_desc(const game_params *params, const char *desc)
291{ 284{
292 unsigned char *bmp; 285 unsigned char *bmp;
293 int i; 286 int i;
@@ -367,7 +360,7 @@ static void free_game(game_state *state)
367} 360}
368 361
369static char *solve_game(const game_state *state, const game_state *currstate, 362static char *solve_game(const game_state *state, const game_state *currstate,
370 const char *aux, char **error) 363 const char *aux, const char **error)
371{ 364{
372 return dupstr("S"); 365 return dupstr("S");
373} 366}
@@ -447,7 +440,8 @@ static void free_ui(game_ui *ui)
447 440
448static char *encode_ui(const game_ui *ui) 441static char *encode_ui(const game_ui *ui)
449{ 442{
450 char *ret, *p, *sep; 443 char *ret, *p;
444 const char *sep;
451 int i; 445 int i;
452 446
453 /* 447 /*
@@ -621,7 +615,8 @@ static int mark_pegs(pegrow guess, const pegrow solution, int ncols)
621 615
622static char *encode_move(const game_state *from, game_ui *ui) 616static char *encode_move(const game_state *from, game_ui *ui)
623{ 617{
624 char *buf, *p, *sep; 618 char *buf, *p;
619 const char *sep;
625 int len, i; 620 int len, i;
626 621
627 len = ui->curr_pegs->npegs * 20 + 2; 622 len = ui->curr_pegs->npegs * 20 + 2;
@@ -779,7 +774,7 @@ static char *interpret_move(const game_state *from, game_ui *ui,
779 */ 774 */
780 if (button == 'l' || button == 'L') { 775 if (button == 'l' || button == 'L') {
781 ui->show_labels = !ui->show_labels; 776 ui->show_labels = !ui->show_labels;
782 return ""; 777 return UI_UPDATE;
783 } 778 }
784 779
785 if (from->solved) return NULL; 780 if (from->solved) return NULL;
@@ -836,13 +831,13 @@ static char *interpret_move(const game_state *from, game_ui *ui,
836 ui->drag_y = y; 831 ui->drag_y = y;
837 debug(("Start dragging, col = %d, (%d,%d)", 832 debug(("Start dragging, col = %d, (%d,%d)",
838 ui->drag_col, ui->drag_x, ui->drag_y)); 833 ui->drag_col, ui->drag_x, ui->drag_y));
839 ret = ""; 834 ret = UI_UPDATE;
840 } 835 }
841 } else if (button == LEFT_DRAG && ui->drag_col) { 836 } else if (button == LEFT_DRAG && ui->drag_col) {
842 ui->drag_x = x; 837 ui->drag_x = x;
843 ui->drag_y = y; 838 ui->drag_y = y;
844 debug(("Keep dragging, (%d,%d)", ui->drag_x, ui->drag_y)); 839 debug(("Keep dragging, (%d,%d)", ui->drag_x, ui->drag_y));
845 ret = ""; 840 ret = UI_UPDATE;
846 } else if (button == LEFT_RELEASE && ui->drag_col) { 841 } else if (button == LEFT_RELEASE && ui->drag_col) {
847 if (over_guess > -1) { 842 if (over_guess > -1) {
848 debug(("Dropping colour %d onto guess peg %d", 843 debug(("Dropping colour %d onto guess peg %d",
@@ -859,13 +854,13 @@ static char *interpret_move(const game_state *from, game_ui *ui,
859 ui->drag_opeg = -1; 854 ui->drag_opeg = -1;
860 ui->display_cur = 0; 855 ui->display_cur = 0;
861 debug(("Stop dragging.")); 856 debug(("Stop dragging."));
862 ret = ""; 857 ret = UI_UPDATE;
863 } else if (button == RIGHT_BUTTON) { 858 } else if (button == RIGHT_BUTTON) {
864 if (over_guess > -1) { 859 if (over_guess > -1) {
865 /* we use ths feedback in the game_ui to signify 860 /* we use ths feedback in the game_ui to signify
866 * 'carry this peg to the next guess as well'. */ 861 * 'carry this peg to the next guess as well'. */
867 ui->holds[over_guess] = 1 - ui->holds[over_guess]; 862 ui->holds[over_guess] = 1 - ui->holds[over_guess];
868 ret = ""; 863 ret = UI_UPDATE;
869 } 864 }
870 } else if (button == LEFT_RELEASE && over_hint && ui->markable) { 865 } else if (button == LEFT_RELEASE && over_hint && ui->markable) {
871 /* NB this won't trigger if on the end of a drag; that's on 866 /* NB this won't trigger if on the end of a drag; that's on
@@ -880,10 +875,10 @@ static char *interpret_move(const game_state *from, game_ui *ui,
880 ui->colour_cur++; 875 ui->colour_cur++;
881 if (button == CURSOR_UP && ui->colour_cur > 0) 876 if (button == CURSOR_UP && ui->colour_cur > 0)
882 ui->colour_cur--; 877 ui->colour_cur--;
883 ret = ""; 878 ret = UI_UPDATE;
884 } else if (button == 'h' || button == 'H' || button == '?') { 879 } else if (button == 'h' || button == 'H' || button == '?') {
885 compute_hint(from, ui); 880 compute_hint(from, ui);
886 ret = ""; 881 ret = UI_UPDATE;
887 } else if (button == CURSOR_LEFT || button == CURSOR_RIGHT) { 882 } else if (button == CURSOR_LEFT || button == CURSOR_RIGHT) {
888 int maxcur = from->params.npegs; 883 int maxcur = from->params.npegs;
889 if (ui->markable) maxcur++; 884 if (ui->markable) maxcur++;
@@ -893,25 +888,25 @@ static char *interpret_move(const game_state *from, game_ui *ui,
893 ui->peg_cur++; 888 ui->peg_cur++;
894 if (button == CURSOR_LEFT && ui->peg_cur > 0) 889 if (button == CURSOR_LEFT && ui->peg_cur > 0)
895 ui->peg_cur--; 890 ui->peg_cur--;
896 ret = ""; 891 ret = UI_UPDATE;
897 } else if (IS_CURSOR_SELECT(button)) { 892 } else if (IS_CURSOR_SELECT(button)) {
898 ui->display_cur = 1; 893 ui->display_cur = 1;
899 if (ui->peg_cur == from->params.npegs) { 894 if (ui->peg_cur == from->params.npegs) {
900 ret = encode_move(from, ui); 895 ret = encode_move(from, ui);
901 } else { 896 } else {
902 set_peg(&from->params, ui, ui->peg_cur, ui->colour_cur+1); 897 set_peg(&from->params, ui, ui->peg_cur, ui->colour_cur+1);
903 ret = ""; 898 ret = UI_UPDATE;
904 } 899 }
905 } else if (button == 'D' || button == 'd' || button == '\b') { 900 } else if (button == 'D' || button == 'd' || button == '\b') {
906 ui->display_cur = 1; 901 ui->display_cur = 1;
907 set_peg(&from->params, ui, ui->peg_cur, 0); 902 set_peg(&from->params, ui, ui->peg_cur, 0);
908 ret = ""; 903 ret = UI_UPDATE;
909 } else if (button == CURSOR_SELECT2) { 904 } else if (button == CURSOR_SELECT2) {
910 if (ui->peg_cur == from->params.npegs) 905 if (ui->peg_cur == from->params.npegs)
911 return NULL; 906 return NULL;
912 ui->display_cur = 1; 907 ui->display_cur = 1;
913 ui->holds[ui->peg_cur] = 1 - ui->holds[ui->peg_cur]; 908 ui->holds[ui->peg_cur] = 1 - ui->holds[ui->peg_cur];
914 ret = ""; 909 ret = UI_UPDATE;
915 } 910 }
916 return ret; 911 return ret;
917} 912}