summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/unequal.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/puzzles/src/unequal.c')
-rw-r--r--apps/plugins/puzzles/src/unequal.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/apps/plugins/puzzles/src/unequal.c b/apps/plugins/puzzles/src/unequal.c
index a63b7d8ed0..cb477c9e37 100644
--- a/apps/plugins/puzzles/src/unequal.c
+++ b/apps/plugins/puzzles/src/unequal.c
@@ -218,24 +218,21 @@ static config_item *game_configure(const game_params *params)
218 218
219 ret[0].name = "Mode"; 219 ret[0].name = "Mode";
220 ret[0].type = C_CHOICES; 220 ret[0].type = C_CHOICES;
221 ret[0].sval = ":Unequal:Adjacent"; 221 ret[0].u.choices.choicenames = ":Unequal:Adjacent";
222 ret[0].ival = params->adjacent; 222 ret[0].u.choices.selected = params->adjacent;
223 223
224 ret[1].name = "Size (s*s)"; 224 ret[1].name = "Size (s*s)";
225 ret[1].type = C_STRING; 225 ret[1].type = C_STRING;
226 sprintf(buf, "%d", params->order); 226 sprintf(buf, "%d", params->order);
227 ret[1].sval = dupstr(buf); 227 ret[1].u.string.sval = dupstr(buf);
228 ret[1].ival = 0;
229 228
230 ret[2].name = "Difficulty"; 229 ret[2].name = "Difficulty";
231 ret[2].type = C_CHOICES; 230 ret[2].type = C_CHOICES;
232 ret[2].sval = DIFFCONFIG; 231 ret[2].u.choices.choicenames = DIFFCONFIG;
233 ret[2].ival = params->diff; 232 ret[2].u.choices.selected = params->diff;
234 233
235 ret[3].name = NULL; 234 ret[3].name = NULL;
236 ret[3].type = C_END; 235 ret[3].type = C_END;
237 ret[3].sval = NULL;
238 ret[3].ival = 0;
239 236
240 return ret; 237 return ret;
241} 238}
@@ -244,14 +241,14 @@ static game_params *custom_params(const config_item *cfg)
244{ 241{
245 game_params *ret = snew(game_params); 242 game_params *ret = snew(game_params);
246 243
247 ret->adjacent = cfg[0].ival; 244 ret->adjacent = cfg[0].u.choices.selected;
248 ret->order = atoi(cfg[1].sval); 245 ret->order = atoi(cfg[1].u.string.sval);
249 ret->diff = cfg[2].ival; 246 ret->diff = cfg[2].u.choices.selected;
250 247
251 return ret; 248 return ret;
252} 249}
253 250
254static char *validate_params(const game_params *params, int full) 251static const char *validate_params(const game_params *params, int full)
255{ 252{
256 if (params->order < 3 || params->order > 32) 253 if (params->order < 3 || params->order > 32)
257 return "Order must be between 3 and 32"; 254 return "Order must be between 3 and 32";
@@ -1198,12 +1195,12 @@ generate:
1198} 1195}
1199 1196
1200static game_state *load_game(const game_params *params, const char *desc, 1197static game_state *load_game(const game_params *params, const char *desc,
1201 char **why_r) 1198 const char **why_r)
1202{ 1199{
1203 game_state *state = blank_game(params->order, params->adjacent); 1200 game_state *state = blank_game(params->order, params->adjacent);
1204 const char *p = desc; 1201 const char *p = desc;
1205 int i = 0, n, o = params->order, x, y; 1202 int i = 0, n, o = params->order, x, y;
1206 char *why = NULL; 1203 const char *why = NULL;
1207 1204
1208 while (*p) { 1205 while (*p) {
1209 while (*p >= 'a' && *p <= 'z') { 1206 while (*p >= 'a' && *p <= 'z') {
@@ -1294,9 +1291,9 @@ static game_state *new_game(midend *me, const game_params *params,
1294 return state; 1291 return state;
1295} 1292}
1296 1293
1297static char *validate_desc(const game_params *params, const char *desc) 1294static const char *validate_desc(const game_params *params, const char *desc)
1298{ 1295{
1299 char *why = NULL; 1296 const char *why = NULL;
1300 game_state *dummy = load_game(params, desc, &why); 1297 game_state *dummy = load_game(params, desc, &why);
1301 if (dummy) { 1298 if (dummy) {
1302 free_game(dummy); 1299 free_game(dummy);
@@ -1307,7 +1304,7 @@ static char *validate_desc(const game_params *params, const char *desc)
1307} 1304}
1308 1305
1309static char *solve_game(const game_state *state, const game_state *currstate, 1306static char *solve_game(const game_state *state, const game_state *currstate,
1310 const char *aux, char **error) 1307 const char *aux, const char **error)
1311{ 1308{
1312 game_state *solved; 1309 game_state *solved;
1313 int r; 1310 int r;
@@ -1425,7 +1422,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
1425 ui->hshow = 1; 1422 ui->hshow = 1;
1426 } 1423 }
1427 ui->hcursor = 0; 1424 ui->hcursor = 0;
1428 return ""; 1425 return UI_UPDATE;
1429 } 1426 }
1430 if (button == RIGHT_BUTTON) { 1427 if (button == RIGHT_BUTTON) {
1431 /* pencil highlighting for non-filled squares */ 1428 /* pencil highlighting for non-filled squares */
@@ -1439,7 +1436,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
1439 ui->hshow = 1; 1436 ui->hshow = 1;
1440 } 1437 }
1441 ui->hcursor = 0; 1438 ui->hcursor = 0;
1442 return ""; 1439 return UI_UPDATE;
1443 } 1440 }
1444 } 1441 }
1445 1442
@@ -1453,11 +1450,12 @@ static char *interpret_move(const game_state *state, game_ui *ui,
1453 ny != ui->hy + adjthan[i].dy); ++i); 1450 ny != ui->hy + adjthan[i].dy); ++i);
1454 1451
1455 if (i == 4) 1452 if (i == 4)
1456 return ""; /* invalid direction, i.e. out of the board */ 1453 return UI_UPDATE; /* invalid direction, i.e. out of
1454 * the board */
1457 1455
1458 if (!(GRID(state, flags, ui->hx, ui->hy) & adjthan[i].f || 1456 if (!(GRID(state, flags, ui->hx, ui->hy) & adjthan[i].f ||
1459 GRID(state, flags, nx, ny ) & adjthan[i].fo)) 1457 GRID(state, flags, nx, ny ) & adjthan[i].fo))
1460 return ""; /* no clue to toggle */ 1458 return UI_UPDATE; /* no clue to toggle */
1461 1459
1462 if (state->adjacent) 1460 if (state->adjacent)
1463 self = (adjthan[i].dx >= 0 && adjthan[i].dy >= 0); 1461 self = (adjthan[i].dx >= 0 && adjthan[i].dy >= 0);
@@ -1475,13 +1473,13 @@ static char *interpret_move(const game_state *state, game_ui *ui,
1475 } else { 1473 } else {
1476 move_cursor(button, &ui->hx, &ui->hy, ds->order, ds->order, FALSE); 1474 move_cursor(button, &ui->hx, &ui->hy, ds->order, ds->order, FALSE);
1477 ui->hshow = ui->hcursor = 1; 1475 ui->hshow = ui->hcursor = 1;
1478 return ""; 1476 return UI_UPDATE;
1479 } 1477 }
1480 } 1478 }
1481 if (ui->hshow && IS_CURSOR_SELECT(button)) { 1479 if (ui->hshow && IS_CURSOR_SELECT(button)) {
1482 ui->hpencil = 1 - ui->hpencil; 1480 ui->hpencil = 1 - ui->hpencil;
1483 ui->hcursor = 1; 1481 ui->hcursor = 1;
1484 return ""; 1482 return UI_UPDATE;
1485 } 1483 }
1486 1484
1487 n = c2n(button, state->order); 1485 n = c2n(button, state->order);
@@ -1568,7 +1566,9 @@ static game_state *execute_move(const game_state *state, const char *move)
1568 } 1566 }
1569 return ret; 1567 return ret;
1570 } else if (move[0] == 'H') { 1568 } else if (move[0] == 'H') {
1571 return solver_hint(state, NULL, DIFF_EASY, DIFF_EASY); 1569 ret = solver_hint(state, NULL, DIFF_EASY, DIFF_EASY);
1570 check_complete(ret->nums, ret, 1);
1571 return ret;
1572 } else if (move[0] == 'F' && sscanf(move+1, "%d,%d,%d", &x, &y, &n) == 3 && 1572 } else if (move[0] == 'F' && sscanf(move+1, "%d,%d,%d", &x, &y, &n) == 3 &&
1573 x >= 0 && x < state->order && y >= 0 && y < state->order) { 1573 x >= 0 && x < state->order && y >= 0 && y < state->order) {
1574 ret = dup_game(state); 1574 ret = dup_game(state);
@@ -2041,7 +2041,7 @@ const char *quis = NULL;
2041 2041
2042#if 0 /* currently unused */ 2042#if 0 /* currently unused */
2043 2043
2044static void debug_printf(char *fmt, ...) 2044static void debug_printf(const char *fmt, ...)
2045{ 2045{
2046 char buf[4096]; 2046 char buf[4096];
2047 va_list ap; 2047 va_list ap;
@@ -2125,7 +2125,7 @@ static int solve(game_params *p, char *desc, int debug)
2125 2125
2126static void check(game_params *p) 2126static void check(game_params *p)
2127{ 2127{
2128 char *msg = validate_params(p, 1); 2128 const char *msg = validate_params(p, 1);
2129 if (msg) { 2129 if (msg) {
2130 fprintf(stderr, "%s: %s", quis, msg); 2130 fprintf(stderr, "%s: %s", quis, msg);
2131 exit(1); 2131 exit(1);
@@ -2233,7 +2233,8 @@ int main(int argc, const char *argv[])
2233 int i; 2233 int i;
2234 for (i = 0; i < argc; i++) { 2234 for (i = 0; i < argc; i++) {
2235 const char *id = *argv++; 2235 const char *id = *argv++;
2236 char *desc = strchr(id, ':'), *err; 2236 char *desc = strchr(id, ':');
2237 const char *err;
2237 p = default_params(); 2238 p = default_params();
2238 if (desc) { 2239 if (desc) {
2239 *desc++ = '\0'; 2240 *desc++ = '\0';