Make peg removal accessible from the keyboard.
[sgt/puzzles] / guess.c
CommitLineData
74476385 1/*
2 * guess.c: Mastermind clone.
3 */
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8#include <assert.h>
9#include <ctype.h>
10#include <math.h>
11
12#include "puzzles.h"
13
14#define FLASH_FRAME 0.5F
15
16enum {
17 COL_BACKGROUND,
c6203e43 18 COL_FRAME, COL_CURSOR, COL_FLASH, COL_HOLD,
74476385 19 COL_EMPTY, /* must be COL_1 - 1 */
20 COL_1, COL_2, COL_3, COL_4, COL_5, COL_6, COL_7, COL_8, COL_9, COL_10,
21 COL_CORRECTPLACE, COL_CORRECTCOLOUR,
22 NCOLOURS
23};
24
25struct game_params {
26 int ncolours, npegs, nguesses;
c6203e43 27 int allow_blank, allow_multiple;
74476385 28};
29
30#define FEEDBACK_CORRECTPLACE 1
31#define FEEDBACK_CORRECTCOLOUR 2
32
33typedef struct pegrow {
34 int npegs;
35 int *pegs; /* 0 is 'empty' */
36 int *feedback; /* may well be unused */
37} *pegrow;
38
39struct game_state {
40 game_params params;
41 pegrow *guesses; /* length params->nguesses */
42 pegrow solution;
43 int next_go; /* from 0 to nguesses-1;
44 if next_go == nguesses then they've lost. */
45 int solved;
46};
47
48static game_params *default_params(void)
49{
50 game_params *ret = snew(game_params);
51
52 /* AFAIK this is the canonical Mastermind ruleset. */
53 ret->ncolours = 6;
54 ret->npegs = 4;
55 ret->nguesses = 10;
56
c6203e43 57 ret->allow_blank = 0;
58 ret->allow_multiple = 1;
59
74476385 60 return ret;
61}
62
74476385 63static void free_params(game_params *params)
64{
65 sfree(params);
66}
67
68static game_params *dup_params(game_params *params)
69{
70 game_params *ret = snew(game_params);
71 *ret = *params; /* structure copy */
72 return ret;
73}
74
51cda7fe 75static const struct {
76 char *name;
77 game_params params;
78} guess_presets[] = {
79 {"Standard", {6, 4, 10, FALSE, TRUE}},
80 {"Super", {8, 5, 12, FALSE, TRUE}},
81};
82
83
84static int game_fetch_preset(int i, char **name, game_params **params)
85{
86 if (i < 0 || i >= lenof(guess_presets))
87 return FALSE;
88
89 *name = dupstr(guess_presets[i].name);
90 /*
91 * get round annoying const issues
92 */
93 {
94 game_params tmp = guess_presets[i].params;
95 *params = dup_params(&tmp);
96 }
97
98 return TRUE;
99}
100
74476385 101static void decode_params(game_params *params, char const *string)
102{
103 char const *p = string;
104 game_params *defs = default_params();
105
106 *params = *defs; free_params(defs);
107
108 while (*p) {
109 switch (*p++) {
110 case 'c':
111 params->ncolours = atoi(p);
112 while (*p && isdigit((unsigned char)*p)) p++;
113 break;
114
115 case 'p':
116 params->npegs = atoi(p);
117 while (*p && isdigit((unsigned char)*p)) p++;
118 break;
119
120 case 'g':
121 params->nguesses = atoi(p);
122 while (*p && isdigit((unsigned char)*p)) p++;
123 break;
124
c6203e43 125 case 'b':
126 params->allow_blank = 1;
127 break;
128
129 case 'B':
130 params->allow_blank = 0;
131 break;
132
133 case 'm':
134 params->allow_multiple = 1;
135 break;
136
137 case 'M':
138 params->allow_multiple = 0;
139 break;
140
74476385 141 default:
142 ;
143 }
144 }
145}
146
147static char *encode_params(game_params *params, int full)
148{
149 char data[256];
150
c6203e43 151 sprintf(data, "c%dp%dg%d%s%s",
152 params->ncolours, params->npegs, params->nguesses,
153 params->allow_blank ? "b" : "B", params->allow_multiple ? "m" : "M");
74476385 154
155 return dupstr(data);
156}
157
158static config_item *game_configure(game_params *params)
159{
160 config_item *ret;
161 char buf[80];
162
c6203e43 163 ret = snewn(6, config_item);
74476385 164
c6203e43 165 ret[0].name = "Colours";
74476385 166 ret[0].type = C_STRING;
167 sprintf(buf, "%d", params->ncolours);
168 ret[0].sval = dupstr(buf);
169 ret[0].ival = 0;
170
c6203e43 171 ret[1].name = "Pegs per guess";
74476385 172 ret[1].type = C_STRING;
173 sprintf(buf, "%d", params->npegs);
174 ret[1].sval = dupstr(buf);
175 ret[1].ival = 0;
176
c6203e43 177 ret[2].name = "Guesses";
74476385 178 ret[2].type = C_STRING;
179 sprintf(buf, "%d", params->nguesses);
180 ret[2].sval = dupstr(buf);
181 ret[2].ival = 0;
182
c6203e43 183 ret[3].name = "Allow blanks";
184 ret[3].type = C_BOOLEAN;
74476385 185 ret[3].sval = NULL;
c6203e43 186 ret[3].ival = params->allow_blank;
187
188 ret[4].name = "Allow duplicates";
189 ret[4].type = C_BOOLEAN;
190 ret[4].sval = NULL;
191 ret[4].ival = params->allow_multiple;
192
193 ret[5].name = NULL;
194 ret[5].type = C_END;
195 ret[5].sval = NULL;
196 ret[5].ival = 0;
74476385 197
198 return ret;
199}
200
201static game_params *custom_params(config_item *cfg)
202{
203 game_params *ret = snew(game_params);
204
205 ret->ncolours = atoi(cfg[0].sval);
206 ret->npegs = atoi(cfg[1].sval);
207 ret->nguesses = atoi(cfg[2].sval);
208
c6203e43 209 ret->allow_blank = cfg[3].ival;
210 ret->allow_multiple = cfg[4].ival;
211
74476385 212 return ret;
213}
214
215static char *validate_params(game_params *params)
216{
217 if (params->ncolours < 2 || params->npegs < 2)
218 return "Trivial solutions are uninteresting";
219 /* NB as well as the no. of colours we define, max(ncolours) must
220 * also fit in an unsigned char; see new_game_desc. */
221 if (params->ncolours > 10)
222 return "Too many colours";
223 if (params->nguesses < 1)
224 return "Must have at least one guess";
c6203e43 225 if (!params->allow_multiple && params->ncolours < params->npegs)
226 return "Disallowing multiple colours requires at least as many colours as pegs";
74476385 227 return NULL;
228}
229
230static pegrow new_pegrow(int npegs)
231{
232 pegrow pegs = snew(struct pegrow);
233
234 pegs->npegs = npegs;
235 pegs->pegs = snewn(pegs->npegs, int);
236 memset(pegs->pegs, 0, pegs->npegs * sizeof(int));
237 pegs->feedback = snewn(pegs->npegs, int);
238 memset(pegs->feedback, 0, pegs->npegs * sizeof(int));
239
240 return pegs;
241}
242
243static pegrow dup_pegrow(pegrow pegs)
244{
6b98d12c 245 pegrow newpegs = new_pegrow(pegs->npegs);
74476385 246
74476385 247 memcpy(newpegs->pegs, pegs->pegs, newpegs->npegs * sizeof(int));
74476385 248 memcpy(newpegs->feedback, pegs->feedback, newpegs->npegs * sizeof(int));
249
250 return newpegs;
251}
252
253static void invalidate_pegrow(pegrow pegs)
254{
255 memset(pegs->pegs, -1, pegs->npegs * sizeof(int));
256 memset(pegs->feedback, -1, pegs->npegs * sizeof(int));
257}
258
259static void free_pegrow(pegrow pegs)
260{
261 sfree(pegs->pegs);
262 sfree(pegs->feedback);
263 sfree(pegs);
264}
265
266static char *new_game_desc(game_params *params, random_state *rs,
c566778e 267 char **aux, int interactive)
74476385 268{
269 unsigned char *bmp = snewn(params->npegs, unsigned char);
270 char *ret;
c6203e43 271 int i, c;
272 pegrow colcount = new_pegrow(params->ncolours);
273
274 for (i = 0; i < params->npegs; i++) {
275newcol:
276 c = random_upto(rs, params->ncolours);
277 if (!params->allow_multiple && colcount->pegs[c]) goto newcol;
278 colcount->pegs[c]++;
279 bmp[i] = (unsigned char)(c+1);
280 }
74476385 281 obfuscate_bitmap(bmp, params->npegs*8, FALSE);
282
283 ret = bin2hex(bmp, params->npegs);
284 sfree(bmp);
c6203e43 285 free_pegrow(colcount);
74476385 286 return ret;
287}
288
74476385 289static char *validate_desc(game_params *params, char *desc)
290{
c6203e43 291 unsigned char *bmp;
292 int i;
293
294 /* desc is just an (obfuscated) bitmap of the solution; check that
295 * it's the correct length and (when unobfuscated) contains only
296 * sensible colours. */
74476385 297 if (strlen(desc) != params->npegs * 2)
298 return "Game description is wrong length";
c6203e43 299 bmp = hex2bin(desc, params->npegs);
300 obfuscate_bitmap(bmp, params->npegs*8, TRUE);
301 for (i = 0; i < params->npegs; i++) {
302 if (bmp[i] < 1 || bmp[i] > params->ncolours) {
303 sfree(bmp);
304 return "Game description is corrupted";
305 }
306 }
307 sfree(bmp);
308
74476385 309 return NULL;
310}
311
312static game_state *new_game(midend_data *me, game_params *params, char *desc)
313{
314 game_state *state = snew(game_state);
315 unsigned char *bmp;
316 int i;
317
318 state->params = *params;
319 state->guesses = snewn(params->nguesses, pegrow);
320 for (i = 0; i < params->nguesses; i++)
321 state->guesses[i] = new_pegrow(params->npegs);
322 state->solution = new_pegrow(params->npegs);
323
324 bmp = hex2bin(desc, params->npegs);
325 obfuscate_bitmap(bmp, params->npegs*8, TRUE);
326 for (i = 0; i < params->npegs; i++)
327 state->solution->pegs[i] = (int)bmp[i];
328 sfree(bmp);
329
330 state->next_go = state->solved = 0;
331
332 return state;
333}
334
335static game_state *dup_game(game_state *state)
336{
337 game_state *ret = snew(game_state);
338 int i;
339
340 *ret = *state;
6b98d12c 341
74476385 342 ret->guesses = snewn(state->params.nguesses, pegrow);
343 for (i = 0; i < state->params.nguesses; i++)
344 ret->guesses[i] = dup_pegrow(state->guesses[i]);
345 ret->solution = dup_pegrow(state->solution);
346
347 return ret;
348}
349
350static void free_game(game_state *state)
351{
352 int i;
353
354 free_pegrow(state->solution);
355 for (i = 0; i < state->params.nguesses; i++)
356 free_pegrow(state->guesses[i]);
357 sfree(state->guesses);
358
359 sfree(state);
360}
361
df11cd4e 362static char *solve_game(game_state *state, game_state *currstate,
c566778e 363 char *aux, char **error)
74476385 364{
df11cd4e 365 return dupstr("S");
74476385 366}
367
368static char *game_text_format(game_state *state)
369{
370 return NULL;
371}
372
373struct game_ui {
374 pegrow curr_pegs; /* half-finished current move */
375 int *holds;
376 int colour_cur; /* position of up-down colour picker cursor */
377 int peg_cur; /* position of left-right peg picker cursor */
378 int display_cur, markable;
379
380 int drag_col, drag_x, drag_y; /* x and y are *center* of peg! */
c6203e43 381 int drag_opeg; /* peg index, if dragged from a peg (from current guess), otherwise -1 */
74476385 382};
383
384static game_ui *new_ui(game_state *state)
385{
386 game_ui *ui = snew(struct game_ui);
387 memset(ui, 0, sizeof(struct game_ui));
388 ui->curr_pegs = new_pegrow(state->params.npegs);
389 ui->holds = snewn(state->params.npegs, int);
390 memset(ui->holds, 0, sizeof(int)*state->params.npegs);
c6203e43 391 ui->drag_opeg = -1;
74476385 392 return ui;
393}
394
395static void free_ui(game_ui *ui)
396{
397 free_pegrow(ui->curr_pegs);
398 sfree(ui->holds);
399 sfree(ui);
400}
401
844f605f 402static char *encode_ui(game_ui *ui)
ae8290c6 403{
404 return NULL;
405}
406
844f605f 407static void decode_ui(game_ui *ui, char *encoding)
ae8290c6 408{
409}
410
74476385 411static void game_changed_state(game_ui *ui, game_state *oldstate,
412 game_state *newstate)
413{
414 int i;
415
416 /* just clear the row-in-progress when we have an undo/redo. */
417 for (i = 0; i < ui->curr_pegs->npegs; i++)
418 ui->curr_pegs->pegs[i] = 0;
75953cd4 419 ui->markable = FALSE;
74476385 420}
421
422#define PEGSZ (ds->pegsz)
423#define PEGOFF (ds->pegsz + ds->gapsz)
424#define HINTSZ (ds->hintsz)
425#define HINTOFF (ds->hintsz + ds->gapsz)
426
74b36224 427#define GAP (ds->gapsz)
66732e7a 428#define CGAP (ds->gapsz / 2)
429
74476385 430#define PEGRAD (ds->pegrad)
431#define HINTRAD (ds->hintrad)
432
433#define COL_OX (ds->colx)
434#define COL_OY (ds->coly)
435#define COL_X(c) (COL_OX)
436#define COL_Y(c) (COL_OY + (c)*PEGOFF)
437#define COL_W PEGOFF
438#define COL_H (ds->colours->npegs*PEGOFF)
439
440#define GUESS_OX (ds->guessx)
441#define GUESS_OY (ds->guessy)
442#define GUESS_X(g,p) (GUESS_OX + (p)*PEGOFF)
443#define GUESS_Y(g,p) (GUESS_OY + (g)*PEGOFF)
444#define GUESS_W (ds->solution->npegs*PEGOFF)
445#define GUESS_H (ds->nguesses*PEGOFF)
446
447#define HINT_OX (GUESS_OX + GUESS_W + ds->gapsz)
448#define HINT_OY (GUESS_OY + (PEGSZ - HINTOFF - HINTSZ) / 2)
449#define HINT_X(g) HINT_OX
450#define HINT_Y(g) (HINT_OY + (g)*PEGOFF)
74b36224 451#define HINT_W ((ds->hintw*HINTOFF) - GAP)
74476385 452#define HINT_H GUESS_H
453
454#define SOLN_OX GUESS_OX
455#define SOLN_OY (GUESS_OY + GUESS_H + ds->gapsz + 2)
456#define SOLN_W GUESS_W
457#define SOLN_H PEGOFF
458
459struct game_drawstate {
460 int nguesses;
461 pegrow *guesses; /* same size as state->guesses */
462 pegrow solution; /* only displayed if state->solved */
463 pegrow colours; /* length ncolours, not npegs */
464
74476385 465 int pegsz, hintsz, gapsz; /* peg size (diameter), etc. */
466 int pegrad, hintrad; /* radius of peg, hint */
467 int border;
468 int colx, coly; /* origin of colours vertical bar */
469 int guessx, guessy; /* origin of guesses */
470 int solnx, solny; /* origin of solution */
471 int hintw; /* no. of hint tiles we're wide per row */
472 int w, h, started, solved;
473
74476385 474 int next_go;
475
476 blitter *blit_peg;
477 int drag_col, blit_ox, blit_oy;
478};
479
c6203e43 480static int is_markable(game_params *params, pegrow pegs)
74476385 481{
c6203e43 482 int i, nset = 0, nrequired, ret = 0;
483 pegrow colcount = new_pegrow(params->ncolours);
74476385 484
c6203e43 485 nrequired = params->allow_blank ? 1 : params->npegs;
486
487 for (i = 0; i < params->npegs; i++) {
6b98d12c 488 int c = pegs->pegs[i];
489 if (c > 0) {
490 colcount->pegs[c-1]++;
c6203e43 491 nset++;
492 }
493 }
494 if (nset < nrequired) goto done;
74476385 495
c6203e43 496 if (!params->allow_multiple) {
497 for (i = 0; i < params->ncolours; i++) {
498 if (colcount->pegs[i] > 1) goto done;
499 }
74476385 500 }
c6203e43 501 ret = 1;
502done:
503 free_pegrow(colcount);
504 return ret;
505}
506
507static void set_peg(game_params *params, game_ui *ui, int peg, int col)
508{
509 ui->curr_pegs->pegs[peg] = col;
510 ui->markable = is_markable(params, ui->curr_pegs);
74476385 511}
512
513static int mark_pegs(pegrow guess, pegrow solution, int ncols)
514{
515 int nc_place = 0, nc_colour = 0, i, j;
516
517 assert(guess && solution && (guess->npegs == solution->npegs));
518
519 for (i = 0; i < guess->npegs; i++) {
520 if (guess->pegs[i] == solution->pegs[i]) nc_place++;
521 }
522
523 /* slight bit of cleverness: we have the following formula, from
524 * http://mathworld.wolfram.com/Mastermind.html that gives:
525 *
526 * nc_colour = sum(colours, min(#solution, #guess)) - nc_place
527 *
528 * I think this is due to Knuth.
529 */
530 for (i = 1; i <= ncols; i++) {
531 int n_guess = 0, n_solution = 0;
532 for (j = 0; j < guess->npegs; j++) {
533 if (guess->pegs[j] == i) n_guess++;
534 if (solution->pegs[j] == i) n_solution++;
535 }
536 nc_colour += min(n_guess, n_solution);
537 }
538 nc_colour -= nc_place;
539
540 debug(("mark_pegs, %d pegs, %d right place, %d right colour",
541 guess->npegs, nc_place, nc_colour));
542 assert((nc_colour + nc_place) <= guess->npegs);
543
544 memset(guess->feedback, 0, guess->npegs*sizeof(int));
545 for (i = 0, j = 0; i < nc_place; i++)
546 guess->feedback[j++] = FEEDBACK_CORRECTPLACE;
547 for (i = 0; i < nc_colour; i++)
548 guess->feedback[j++] = FEEDBACK_CORRECTCOLOUR;
549
550 return nc_place;
551}
552
df11cd4e 553static char *encode_move(game_state *from, game_ui *ui)
74476385 554{
df11cd4e 555 char *buf, *p, *sep;
556 int len, i, solved;
557 pegrow tmppegs;
558
559 len = ui->curr_pegs->npegs * 20 + 2;
560 buf = snewn(len, char);
561 p = buf;
562 *p++ = 'G';
563 sep = "";
564 for (i = 0; i < ui->curr_pegs->npegs; i++) {
565 p += sprintf(p, "%s%d", sep, ui->curr_pegs->pegs[i]);
566 sep = ",";
74476385 567 }
df11cd4e 568 *p++ = '\0';
569 assert(p - buf <= len);
570 buf = sresize(buf, len, char);
571
572 tmppegs = dup_pegrow(ui->curr_pegs);
573 solved = mark_pegs(tmppegs, from->solution, from->params.ncolours);
574 solved = (solved == from->params.ncolours);
575 free_pegrow(tmppegs);
576
577 for (i = 0; i < from->solution->npegs; i++) {
578 if (!ui->holds[i] || solved) {
579 ui->curr_pegs->pegs[i] = 0;
580 }
581 if (solved) ui->holds[i] = 0;
74476385 582 }
c6203e43 583 ui->markable = is_markable(&from->params, ui->curr_pegs);
df11cd4e 584 if (!ui->markable && ui->peg_cur == from->solution->npegs)
585 ui->peg_cur--;
74476385 586
df11cd4e 587 return buf;
74476385 588}
589
df11cd4e 590static char *interpret_move(game_state *from, game_ui *ui, game_drawstate *ds,
591 int x, int y, int button)
74476385 592{
593 int over_col = 0; /* one-indexed */
594 int over_guess = -1; /* zero-indexed */
e98cc9b7 595 int over_past_guess_y = -1; /* zero-indexed */
596 int over_past_guess_x = -1; /* zero-indexed */
74476385 597 int over_hint = 0; /* zero or one */
df11cd4e 598 char *ret = NULL;
74476385 599
600 int guess_ox = GUESS_X(from->next_go, 0);
601 int guess_oy = GUESS_Y(from->next_go, 0);
602
603 if (from->solved) return NULL;
604
605 if (x >= COL_OX && x <= (COL_OX + COL_W) &&
606 y >= COL_OY && y <= (COL_OY + COL_H)) {
607 over_col = ((y - COL_OY) / PEGOFF) + 1;
608 } else if (x >= guess_ox &&
609 y >= guess_oy && y <= (guess_oy + GUESS_H)) {
610 if (x <= (guess_ox + GUESS_W)) {
611 over_guess = (x - guess_ox) / PEGOFF;
612 } else {
613 over_hint = 1;
614 }
e98cc9b7 615 } else if (x >= guess_ox &&
616 y >= GUESS_OY && y < guess_oy) {
617 over_past_guess_y = (y - GUESS_OY) / PEGOFF;
618 over_past_guess_x = (x - guess_ox) / PEGOFF;
74476385 619 }
e98cc9b7 620 debug(("make_move: over_col %d, over_guess %d, over_hint %d,"
c6203e43 621 " over_past_guess (%d,%d)", over_col, over_guess, over_hint,
622 over_past_guess_x, over_past_guess_y));
74476385 623
624 assert(ds->blit_peg);
625
626 /* mouse input */
627 if (button == LEFT_BUTTON) {
628 if (over_col > 0) {
629 ui->drag_col = over_col;
c6203e43 630 ui->drag_opeg = -1;
74476385 631 debug(("Start dragging from colours"));
632 } else if (over_guess > -1) {
633 int col = ui->curr_pegs->pegs[over_guess];
634 if (col) {
635 ui->drag_col = col;
c6203e43 636 ui->drag_opeg = over_guess;
74476385 637 debug(("Start dragging from a guess"));
638 }
e98cc9b7 639 } else if (over_past_guess_y > -1) {
640 int col =
641 from->guesses[over_past_guess_y]->pegs[over_past_guess_x];
642 if (col) {
643 ui->drag_col = col;
c6203e43 644 ui->drag_opeg = -1;
e98cc9b7 645 debug(("Start dragging from a past guess"));
646 }
74476385 647 }
648 if (ui->drag_col) {
649 ui->drag_x = x;
650 ui->drag_y = y;
651 debug(("Start dragging, col = %d, (%d,%d)",
652 ui->drag_col, ui->drag_x, ui->drag_y));
df11cd4e 653 ret = "";
74476385 654 }
655 } else if (button == LEFT_DRAG && ui->drag_col) {
656 ui->drag_x = x;
657 ui->drag_y = y;
658 debug(("Keep dragging, (%d,%d)", ui->drag_x, ui->drag_y));
df11cd4e 659 ret = "";
74476385 660 } else if (button == LEFT_RELEASE && ui->drag_col) {
661 if (over_guess > -1) {
662 debug(("Dropping colour %d onto guess peg %d",
663 ui->drag_col, over_guess));
c6203e43 664 set_peg(&from->params, ui, over_guess, ui->drag_col);
665 } else {
666 if (ui->drag_opeg > -1) {
667 debug(("Removing colour %d from peg %d",
668 ui->drag_col, ui->drag_opeg));
669 set_peg(&from->params, ui, ui->drag_opeg, 0);
670 }
74476385 671 }
672 ui->drag_col = 0;
c6203e43 673 ui->drag_opeg = -1;
eb6acfe7 674 ui->display_cur = 0;
74476385 675 debug(("Stop dragging."));
df11cd4e 676 ret = "";
74476385 677 } else if (button == RIGHT_BUTTON) {
678 if (over_guess > -1) {
679 /* we use ths feedback in the game_ui to signify
680 * 'carry this peg to the next guess as well'. */
681 ui->holds[over_guess] = 1 - ui->holds[over_guess];
df11cd4e 682 ret = "";
74476385 683 }
684 } else if (button == LEFT_RELEASE && over_hint && ui->markable) {
685 /* NB this won't trigger if on the end of a drag; that's on
686 * purpose, in case you drop by mistake... */
df11cd4e 687 ret = encode_move(from, ui);
74476385 688 }
689
690 /* keyboard input */
691 if (button == CURSOR_UP || button == CURSOR_DOWN) {
692 ui->display_cur = 1;
693 if (button == CURSOR_DOWN && (ui->colour_cur+1) < from->params.ncolours)
694 ui->colour_cur++;
695 if (button == CURSOR_UP && ui->colour_cur > 0)
696 ui->colour_cur--;
df11cd4e 697 ret = "";
74476385 698 } else if (button == CURSOR_LEFT || button == CURSOR_RIGHT) {
699 int maxcur = from->params.npegs;
700 if (ui->markable) maxcur++;
701
702 ui->display_cur = 1;
703 if (button == CURSOR_RIGHT && (ui->peg_cur+1) < maxcur)
704 ui->peg_cur++;
705 if (button == CURSOR_LEFT && ui->peg_cur > 0)
706 ui->peg_cur--;
df11cd4e 707 ret = "";
74476385 708 } else if (button == CURSOR_SELECT || button == ' ' || button == '\r' ||
709 button == '\n') {
f467efad 710 ui->display_cur = 1;
74476385 711 if (ui->peg_cur == from->params.npegs) {
df11cd4e 712 ret = encode_move(from, ui);
74476385 713 } else {
c6203e43 714 set_peg(&from->params, ui, ui->peg_cur, ui->colour_cur+1);
df11cd4e 715 ret = "";
74476385 716 }
59dae0db 717 } else if (button == 'D' || button == 'd' || button == '\b') {
718 ui->display_cur = 1;
719 set_peg(&from->params, ui, ui->peg_cur, 0);
720 ret = "";
badb093d 721 } else if (button == 'H' || button == 'h') {
f467efad 722 ui->display_cur = 1;
badb093d 723 ui->holds[ui->peg_cur] = 1 - ui->holds[ui->peg_cur];
df11cd4e 724 ret = "";
74476385 725 }
726 return ret;
727}
728
df11cd4e 729static game_state *execute_move(game_state *from, char *move)
730{
731 int i, nc_place;
732 game_state *ret;
733 char *p;
734
735 if (!strcmp(move, "S")) {
736 ret = dup_game(from);
737 ret->solved = 1;
738 return ret;
739 } else if (move[0] == 'G') {
740 p = move+1;
741
742 ret = dup_game(from);
743
744 for (i = 0; i < from->solution->npegs; i++) {
745 int val = atoi(p);
746 if (val <= 0 || val > from->params.ncolours) {
747 free_game(ret);
748 return NULL;
749 }
750 ret->guesses[from->next_go]->pegs[i] = atoi(p);
751 while (*p && isdigit((unsigned char)*p)) p++;
752 if (*p == ',') p++;
753 }
754
755 nc_place = mark_pegs(ret->guesses[from->next_go], ret->solution, ret->params.ncolours);
756
757 if (nc_place == ret->solution->npegs) {
758 ret->solved = 1; /* win! */
759 } else {
760 ret->next_go = from->next_go + 1;
761 if (ret->next_go >= ret->params.nguesses)
762 ret->solved = 1; /* 'lose' so we show the pegs. */
763 }
764
765 return ret;
766 } else
767 return NULL;
768}
769
74476385 770/* ----------------------------------------------------------------------
771 * Drawing routines.
772 */
773
774#define PEG_PREFER_SZ 32
775
776/* next three are multipliers for pegsz. It will look much nicer if
777 * (2*PEG_HINT) + PEG_GAP = 1.0 as the hints are formatted like that. */
778#define PEG_GAP 0.10
779#define PEG_HINT 0.35
780
781#define BORDER 0.5
782
783static void game_size(game_params *params, game_drawstate *ds,
784 int *x, int *y, int expand)
785{
786 double hmul, vmul_c, vmul_g, vmul, szx, szy;
787 int sz, colh, guessh;
788
789 hmul = BORDER * 2.0 + /* border */
790 1.0 * 2.0 + /* vertical colour bar */
791 1.0 * params->npegs + /* guess pegs */
792 PEG_GAP * params->npegs + /* guess gaps */
793 PEG_HINT * ds->hintw + /* hint pegs */
794 PEG_GAP * (ds->hintw - 1); /* hint gaps */
795
796 vmul_c = BORDER * 2.0 + /* border */
797 1.0 * params->ncolours + /* colour pegs */
798 PEG_GAP * (params->ncolours - 1); /* colour gaps */
799
800 vmul_g = BORDER * 2.0 + /* border */
801 1.0 * (params->nguesses + 1) + /* guesses plus solution */
802 PEG_GAP * (params->nguesses + 1); /* gaps plus gap above soln */
803
804 vmul = max(vmul_c, vmul_g);
805
806 szx = *x / hmul;
807 szy = *y / vmul;
808 sz = max(min((int)szx, (int)szy), 1);
809 if (expand)
810 ds->pegsz = sz;
811 else
812 ds->pegsz = min(sz, PEG_PREFER_SZ);
813
814 ds->hintsz = (int)((double)ds->pegsz * PEG_HINT);
815 ds->gapsz = (int)((double)ds->pegsz * PEG_GAP);
816 ds->border = (int)((double)ds->pegsz * BORDER);
817
818 ds->pegrad = (ds->pegsz -1)/2; /* radius of peg to fit in pegsz (which is 2r+1) */
819 ds->hintrad = (ds->hintsz-1)/2;
820
813ca264 821 *x = (int)ceil((double)ds->pegsz * hmul);
822 *y = (int)ceil((double)ds->pegsz * vmul);
74476385 823 ds->w = *x; ds->h = *y;
824
825 colh = ((ds->pegsz + ds->gapsz) * params->ncolours) - ds->gapsz;
826 guessh = ((ds->pegsz + ds->gapsz) * params->nguesses); /* guesses */
827 guessh += ds->gapsz + ds->pegsz; /* solution */
828
829 ds->colx = ds->border;
830 ds->coly = (*y - colh) / 2;
831
832 ds->guessx = ds->solnx = ds->border + ds->pegsz * 2; /* border + colours */
833 ds->guessy = (*y - guessh) / 2;
834 ds->solny = ds->guessy + ((ds->pegsz + ds->gapsz) * params->nguesses) + ds->gapsz;
835
836 if (ds->pegsz > 0) {
837 if (ds->blit_peg) blitter_free(ds->blit_peg);
838 ds->blit_peg = blitter_new(ds->pegsz, ds->pegsz);
839 }
840}
841
842static float *game_colours(frontend *fe, game_state *state, int *ncolours)
843{
74b36224 844 float *ret = snewn(3 * NCOLOURS, float), max;
845 int i;
74476385 846
847 frontend_default_colour(fe, &ret[COL_BACKGROUND * 3]);
848
e98cc9b7 849 /* red */
850 ret[COL_1 * 3 + 0] = 1.0F;
74476385 851 ret[COL_1 * 3 + 1] = 0.0F;
e98cc9b7 852 ret[COL_1 * 3 + 2] = 0.0F;
74476385 853
e98cc9b7 854 /* yellow (toned down a bit due to pale grey background) */
855 ret[COL_2 * 3 + 0] = 0.7F;
856 ret[COL_2 * 3 + 1] = 0.7F;
74476385 857 ret[COL_2 * 3 + 2] = 0.0F;
858
e98cc9b7 859 /* green (also toned down) */
860 ret[COL_3 * 3 + 0] = 0.0F;
861 ret[COL_3 * 3 + 1] = 0.5F;
74476385 862 ret[COL_3 * 3 + 2] = 0.0F;
863
e98cc9b7 864 /* blue */
865 ret[COL_4 * 3 + 0] = 0.0F;
866 ret[COL_4 * 3 + 1] = 0.0F;
867 ret[COL_4 * 3 + 2] = 1.0F;
74476385 868
e98cc9b7 869 /* orange */
74476385 870 ret[COL_5 * 3 + 0] = 1.0F;
e98cc9b7 871 ret[COL_5 * 3 + 1] = 0.5F;
872 ret[COL_5 * 3 + 2] = 0.0F;
873
874 /* purple */
875 ret[COL_6 * 3 + 0] = 0.5F;
876 ret[COL_6 * 3 + 1] = 0.0F;
877 ret[COL_6 * 3 + 2] = 0.7F;
878
879 /* brown */
880 ret[COL_7 * 3 + 0] = 0.4F;
881 ret[COL_7 * 3 + 1] = 0.2F;
882 ret[COL_7 * 3 + 2] = 0.2F;
883
884 /* light blue */
885 ret[COL_8 * 3 + 0] = 0.4F;
886 ret[COL_8 * 3 + 1] = 0.7F;
887 ret[COL_8 * 3 + 2] = 1.0F;
888
889 /* light green */
890 ret[COL_9 * 3 + 0] = 0.5F;
891 ret[COL_9 * 3 + 1] = 0.8F;
74476385 892 ret[COL_9 * 3 + 2] = 0.5F;
893
e98cc9b7 894 /* pink */
74476385 895 ret[COL_10 * 3 + 0] = 1.0F;
e98cc9b7 896 ret[COL_10 * 3 + 1] = 0.6F;
74476385 897 ret[COL_10 * 3 + 2] = 1.0F;
898
899 ret[COL_FRAME * 3 + 0] = 0.0F;
900 ret[COL_FRAME * 3 + 1] = 0.0F;
901 ret[COL_FRAME * 3 + 2] = 0.0F;
902
c6203e43 903 ret[COL_CURSOR * 3 + 0] = 0.0F;
904 ret[COL_CURSOR * 3 + 1] = 0.0F;
905 ret[COL_CURSOR * 3 + 2] = 0.0F;
74476385 906
907 ret[COL_FLASH * 3 + 0] = 0.5F;
908 ret[COL_FLASH * 3 + 1] = 1.0F;
909 ret[COL_FLASH * 3 + 2] = 1.0F;
910
911 ret[COL_HOLD * 3 + 0] = 1.0F;
912 ret[COL_HOLD * 3 + 1] = 0.5F;
913 ret[COL_HOLD * 3 + 2] = 0.5F;
914
e98cc9b7 915 ret[COL_CORRECTPLACE*3 + 0] = 0.0F;
74476385 916 ret[COL_CORRECTPLACE*3 + 1] = 0.0F;
917 ret[COL_CORRECTPLACE*3 + 2] = 0.0F;
918
919 ret[COL_CORRECTCOLOUR*3 + 0] = 1.0F;
920 ret[COL_CORRECTCOLOUR*3 + 1] = 1.0F;
921 ret[COL_CORRECTCOLOUR*3 + 2] = 1.0F;
922
74b36224 923 /* We want to make sure we can distinguish COL_CORRECTCOLOUR
924 * (which we hard-code as white) from COL_BACKGROUND (which
925 * could default to white on some platforms).
926 * Code borrowed from fifteen.c. */
927 max = ret[COL_BACKGROUND*3];
928 for (i = 1; i < 3; i++)
929 if (ret[COL_BACKGROUND*3+i] > max)
930 max = ret[COL_BACKGROUND*3+i];
931 if (max * 1.2F > 1.0F) {
932 for (i = 0; i < 3; i++)
933 ret[COL_BACKGROUND*3+i] /= (max * 1.2F);
934 }
935
936 /* We also want to be able to tell the difference between BACKGROUND
937 * and EMPTY, for similar distinguishing-hint reasons. */
938 ret[COL_EMPTY * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 2.0 / 3.0;
939 ret[COL_EMPTY * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2.0 / 3.0;
940 ret[COL_EMPTY * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2.0 / 3.0;
941
74476385 942 *ncolours = NCOLOURS;
943 return ret;
944}
945
946static game_drawstate *game_new_drawstate(game_state *state)
947{
948 struct game_drawstate *ds = snew(struct game_drawstate);
949 int i;
950
951 memset(ds, 0, sizeof(struct game_drawstate));
952
953 ds->guesses = snewn(state->params.nguesses, pegrow);
954 ds->nguesses = state->params.nguesses;
955 for (i = 0; i < state->params.nguesses; i++) {
956 ds->guesses[i] = new_pegrow(state->params.npegs);
957 invalidate_pegrow(ds->guesses[i]);
958 }
959 ds->solution = new_pegrow(state->params.npegs);
960 invalidate_pegrow(ds->solution);
961 ds->colours = new_pegrow(state->params.ncolours);
962 invalidate_pegrow(ds->colours);
963
964 ds->hintw = (state->params.npegs+1)/2; /* must round up */
965
74476385 966 ds->blit_peg = NULL;
967
968 return ds;
969}
970
971static void game_free_drawstate(game_drawstate *ds)
972{
973 int i;
974
975 if (ds->blit_peg) blitter_free(ds->blit_peg);
976 free_pegrow(ds->colours);
977 free_pegrow(ds->solution);
978 for (i = 0; i < ds->nguesses; i++)
979 free_pegrow(ds->guesses[i]);
74476385 980 sfree(ds->guesses);
981 sfree(ds);
982}
983
385f402f 984static void draw_peg(frontend *fe, game_drawstate *ds, int cx, int cy,
985 int moving, int col)
74476385 986{
385f402f 987 /*
988 * Some platforms antialias circles, which means we shouldn't
989 * overwrite a circle of one colour with a circle of another
990 * colour without erasing the background first. However, if the
991 * peg is the one being dragged, we don't erase the background
992 * because we _want_ it to alpha-blend nicely into whatever's
993 * behind it.
994 */
995 if (!moving)
66732e7a 996 draw_rect(fe, cx-CGAP, cy-CGAP, PEGSZ+CGAP*2, PEGSZ+CGAP*2,
997 COL_BACKGROUND);
28094c81 998 if (PEGRAD > 0) {
74476385 999 draw_circle(fe, cx+PEGRAD, cy+PEGRAD, PEGRAD, 1, COL_EMPTY + col);
28094c81 1000 draw_circle(fe, cx+PEGRAD, cy+PEGRAD, PEGRAD, 0, COL_EMPTY + col);
1001 } else
74476385 1002 draw_rect(fe, cx, cy, PEGSZ, PEGSZ, COL_EMPTY + col);
66732e7a 1003 draw_update(fe, cx-CGAP, cy-CGAP, PEGSZ+CGAP*2, PEGSZ+CGAP*2);
1004}
1005
1006static void draw_cursor(frontend *fe, game_drawstate *ds, int x, int y)
1007{
1008 draw_circle(fe, x+PEGRAD, y+PEGRAD, PEGRAD+CGAP, 0, COL_CURSOR);
1009
1010 draw_update(fe, x-CGAP, y-CGAP, PEGSZ+CGAP*2, PEGSZ+CGAP*2);
74476385 1011}
1012
1013static void guess_redraw(frontend *fe, game_drawstate *ds, int guess,
66732e7a 1014 pegrow src, int *holds, int cur_col, int force)
74476385 1015{
1016 pegrow dest;
1017 int rowx, rowy, i, scol;
1018
1019 if (guess == -1) {
1020 dest = ds->solution;
1021 rowx = SOLN_OX;
1022 rowy = SOLN_OY;
1023 } else {
1024 dest = ds->guesses[guess];
1025 rowx = GUESS_X(guess,0);
1026 rowy = GUESS_Y(guess,0);
1027 }
1028 if (src) assert(src->npegs == dest->npegs);
1029
1030 for (i = 0; i < dest->npegs; i++) {
1031 scol = src ? src->pegs[i] : 0;
66732e7a 1032 if (i == cur_col)
1033 scol |= 0x1000;
1034 if (holds && holds[i])
1035 scol |= 0x2000;
1036 if ((dest->pegs[i] != scol) || force) {
1037 draw_peg(fe, ds, rowx + PEGOFF * i, rowy, FALSE, scol &~ 0x3000);
1038 /*
1039 * Hold marker.
1040 */
1041 draw_rect(fe, rowx + PEGOFF * i, rowy + PEGSZ + ds->gapsz/2,
1042 PEGSZ, 2, (scol & 0x2000 ? COL_HOLD : COL_BACKGROUND));
1043 draw_update(fe, rowx + PEGOFF * i, rowy + PEGSZ + ds->gapsz/2,
1044 PEGSZ, 2);
1045 if (scol & 0x1000)
1046 draw_cursor(fe, ds, rowx + PEGOFF * i, rowy);
1047 }
74476385 1048 dest->pegs[i] = scol;
1049 }
1050}
1051
1052static void hint_redraw(frontend *fe, game_drawstate *ds, int guess,
75953cd4 1053 pegrow src, int force, int cursor, int markable)
74476385 1054{
1055 pegrow dest = ds->guesses[guess];
1056 int rowx, rowy, i, scol, col, hintlen;
66732e7a 1057 int need_redraw;
75953cd4 1058 int emptycol = (markable ? COL_FLASH : COL_EMPTY);
74476385 1059
1060 if (src) assert(src->npegs == dest->npegs);
1061
1062 hintlen = (dest->npegs + 1)/2;
1063
66732e7a 1064 /*
1065 * Because of the possible presence of the cursor around this
1066 * entire section, we redraw all or none of it but never part.
1067 */
1068 need_redraw = FALSE;
1069
74476385 1070 for (i = 0; i < dest->npegs; i++) {
1071 scol = src ? src->feedback[i] : 0;
66732e7a 1072 if (i == 0 && cursor)
1073 scol |= 0x1000;
75953cd4 1074 if (i == 0 && markable)
1075 scol |= 0x2000;
74476385 1076 if ((scol != dest->feedback[i]) || force) {
66732e7a 1077 need_redraw = TRUE;
1078 }
1079 dest->feedback[i] = scol;
1080 }
1081
1082 if (need_redraw) {
74b36224 1083 int hinth = HINTSZ + GAP + HINTSZ;
1084 int hx,hy,hw,hh;
1085
1086 hx = HINT_X(guess)-GAP; hy = HINT_Y(guess)-GAP;
1087 hw = HINT_W+GAP*2; hh = hinth+GAP*2;
1088
66732e7a 1089 /* erase a large background rectangle */
74b36224 1090 draw_rect(fe, hx, hy, hw, hh, COL_BACKGROUND);
66732e7a 1091
1092 for (i = 0; i < dest->npegs; i++) {
1093 scol = src ? src->feedback[i] : 0;
1094 col = ((scol == FEEDBACK_CORRECTPLACE) ? COL_CORRECTPLACE :
1095 (scol == FEEDBACK_CORRECTCOLOUR) ? COL_CORRECTCOLOUR :
1096 emptycol);
1097
74476385 1098 rowx = HINT_X(guess);
1099 rowy = HINT_Y(guess);
1100 if (i < hintlen) {
1101 rowx += HINTOFF * i;
1102 } else {
1103 rowx += HINTOFF * (i - hintlen);
1104 rowy += HINTOFF;
1105 }
28094c81 1106 if (HINTRAD > 0) {
74476385 1107 draw_circle(fe, rowx+HINTRAD, rowy+HINTRAD, HINTRAD, 1, col);
28094c81 1108 draw_circle(fe, rowx+HINTRAD, rowy+HINTRAD, HINTRAD, 0, col);
1109 } else {
74476385 1110 draw_rect(fe, rowx, rowy, HINTSZ, HINTSZ, col);
28094c81 1111 }
74476385 1112 }
74b36224 1113 if (cursor) {
1114 int x1,y1,x2,y2;
1115 x1 = hx + CGAP; y1 = hy + CGAP;
1116 x2 = hx + hw - CGAP; y2 = hy + hh - CGAP;
1117 draw_line(fe, x1, y1, x2, y1, COL_CURSOR);
1118 draw_line(fe, x2, y1, x2, y2, COL_CURSOR);
1119 draw_line(fe, x2, y2, x1, y2, COL_CURSOR);
1120 draw_line(fe, x1, y2, x1, y1, COL_CURSOR);
1121 }
74476385 1122
74b36224 1123 draw_update(fe, hx, hy, hw, hh);
74476385 1124 }
1125}
1126
1127static void currmove_redraw(frontend *fe, game_drawstate *ds, int guess, int col)
1128{
1129 int ox = GUESS_X(guess, 0), oy = GUESS_Y(guess, 0), off = PEGSZ/4;
1130
1131 draw_rect(fe, ox-off-1, oy, 2, PEGSZ, col);
1132 draw_update(fe, ox-off-1, oy, 2, PEGSZ);
1133}
1134
74476385 1135static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
1136 game_state *state, int dir, game_ui *ui,
1137 float animtime, float flashtime)
1138{
66732e7a 1139 int i, new_move, last_go;
74476385 1140
1141 new_move = (state->next_go != ds->next_go) || !ds->started;
1142 last_go = (state->next_go == state->params.nguesses-1);
1143
1144 if (!ds->started) {
1145 draw_rect(fe, 0, 0, ds->w, ds->h, COL_BACKGROUND);
1146 draw_rect(fe, SOLN_OX, SOLN_OY - ds->gapsz - 1, SOLN_W, 2, COL_FRAME);
1147 draw_update(fe, 0, 0, ds->w, ds->h);
1148 }
1149
1150 if (ds->drag_col != 0) {
1151 debug(("Loading from blitter."));
1152 blitter_load(fe, ds->blit_peg, ds->blit_ox, ds->blit_oy);
1153 draw_update(fe, ds->blit_ox, ds->blit_oy, PEGSZ, PEGSZ);
1154 }
1155
1156 /* draw the colours */
1157 for (i = 0; i < state->params.ncolours; i++) {
66732e7a 1158 int val = i+1;
1159 if (ui->display_cur && ui->colour_cur == i)
1160 val |= 0x1000;
1161 if (ds->colours->pegs[i] != val) {
385f402f 1162 draw_peg(fe, ds, COL_X(i), COL_Y(i), FALSE, i+1);
66732e7a 1163 if (val & 0x1000)
1164 draw_cursor(fe, ds, COL_X(i), COL_Y(i));
1165 ds->colours->pegs[i] = val;
74476385 1166 }
1167 }
1168
1169 /* draw the guesses (so far) and the hints */
1170 for (i = 0; i < state->params.nguesses; i++) {
1171 if (state->next_go > i || state->solved) {
1172 /* this info is stored in the game_state already */
66732e7a 1173 guess_redraw(fe, ds, i, state->guesses[i], NULL, -1, 0);
74476385 1174 hint_redraw(fe, ds, i, state->guesses[i],
75953cd4 1175 i == (state->next_go-1) ? 1 : 0, FALSE, FALSE);
74476385 1176 } else if (state->next_go == i) {
1177 /* this is the one we're on; the (incomplete) guess is
1178 * stored in the game_ui. */
66732e7a 1179 guess_redraw(fe, ds, i, ui->curr_pegs,
1180 ui->holds, ui->display_cur ? ui->peg_cur : -1, 0);
1181 hint_redraw(fe, ds, i, NULL, 1,
1182 ui->display_cur && ui->peg_cur == state->params.npegs,
75953cd4 1183 ui->markable);
74476385 1184 } else {
1185 /* we've not got here yet; it's blank. */
66732e7a 1186 guess_redraw(fe, ds, i, NULL, NULL, -1, 0);
75953cd4 1187 hint_redraw(fe, ds, i, NULL, 0, FALSE, FALSE);
74476385 1188 }
1189 }
1190
74476385 1191 /* draw the 'current move' and 'able to mark' sign. */
1192 if (new_move)
1193 currmove_redraw(fe, ds, ds->next_go, COL_BACKGROUND);
1194 if (!state->solved)
1195 currmove_redraw(fe, ds, state->next_go, COL_HOLD);
1196
1197 /* draw the solution (or the big rectangle) */
1198 if ((state->solved != ds->solved) || !ds->started) {
1199 draw_rect(fe, SOLN_OX, SOLN_OY, SOLN_W, SOLN_H,
1200 state->solved ? COL_BACKGROUND : COL_EMPTY);
1201 draw_update(fe, SOLN_OX, SOLN_OY, SOLN_W, SOLN_H);
1202 }
1203 if (state->solved)
66732e7a 1204 guess_redraw(fe, ds, -1, state->solution, NULL, -1, !ds->solved);
74476385 1205 ds->solved = state->solved;
1206
74476385 1207 ds->next_go = state->next_go;
1208
1209 /* if ui->drag_col != 0, save the screen to the blitter,
1210 * draw the peg where we saved, and set ds->drag_* == ui->drag_*. */
1211 if (ui->drag_col != 0) {
1212 int ox = ui->drag_x - (PEGSZ/2);
1213 int oy = ui->drag_y - (PEGSZ/2);
1214 debug(("Saving to blitter at (%d,%d)", ox, oy));
1215 blitter_save(fe, ds->blit_peg, ox, oy);
385f402f 1216 draw_peg(fe, ds, ox, oy, TRUE, ui->drag_col);
74476385 1217
1218 ds->blit_ox = ox; ds->blit_oy = oy;
1219 }
1220 ds->drag_col = ui->drag_col;
1221
1222 ds->started = 1;
1223}
1224
1225static float game_anim_length(game_state *oldstate, game_state *newstate,
1226 int dir, game_ui *ui)
1227{
1228 return 0.0F;
1229}
1230
1231static float game_flash_length(game_state *oldstate, game_state *newstate,
1232 int dir, game_ui *ui)
1233{
1234 return 0.0F;
1235}
1236
1237static int game_wants_statusbar(void)
1238{
1239 return FALSE;
1240}
1241
1242static int game_timing_state(game_state *state)
1243{
1244 return TRUE;
1245}
1246
1247#ifdef COMBINED
1248#define thegame guess
1249#endif
1250
1251const struct game thegame = {
61072f7b 1252 "Guess", "games.guess",
74476385 1253 default_params,
1254 game_fetch_preset,
1255 decode_params,
1256 encode_params,
1257 free_params,
1258 dup_params,
1259 TRUE, game_configure, custom_params,
1260 validate_params,
1261 new_game_desc,
74476385 1262 validate_desc,
1263 new_game,
1264 dup_game,
1265 free_game,
1266 TRUE, solve_game,
1267 FALSE, game_text_format,
1268 new_ui,
1269 free_ui,
ae8290c6 1270 encode_ui,
1271 decode_ui,
74476385 1272 game_changed_state,
df11cd4e 1273 interpret_move,
1274 execute_move,
74476385 1275 game_size,
1276 game_colours,
1277 game_new_drawstate,
1278 game_free_drawstate,
1279 game_redraw,
1280 game_anim_length,
1281 game_flash_length,
1282 game_wants_statusbar,
1283 FALSE, game_timing_state,
1284 0, /* mouse_priorities */
1285};
1286
1287/* vim: set shiftwidth=4 tabstop=8: */