chiark / gitweb /
Allow marking of clues as exhausted in Unequal.
[sgt-puzzles.git] / fifteen.c
1 /*
2  * fifteen.c: standard 15-puzzle.
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 PREFERRED_TILE_SIZE 48
15 #define TILE_SIZE (ds->tilesize)
16 #define BORDER    (TILE_SIZE / 2)
17 #define HIGHLIGHT_WIDTH (TILE_SIZE / 20)
18 #define COORD(x)  ( (x) * TILE_SIZE + BORDER )
19 #define FROMCOORD(x)  ( ((x) - BORDER + TILE_SIZE) / TILE_SIZE - 1 )
20
21 #define ANIM_TIME 0.13F
22 #define FLASH_FRAME 0.13F
23
24 #define X(state, i) ( (i) % (state)->w )
25 #define Y(state, i) ( (i) / (state)->w )
26 #define C(state, x, y) ( (y) * (state)->w + (x) )
27
28 enum {
29     COL_BACKGROUND,
30     COL_TEXT,
31     COL_HIGHLIGHT,
32     COL_LOWLIGHT,
33     NCOLOURS
34 };
35
36 struct game_params {
37     int w, h;
38 };
39
40 struct game_state {
41     int w, h, n;
42     int *tiles;
43     int gap_pos;
44     int completed;
45     int used_solve;                    /* used to suppress completion flash */
46     int movecount;
47 };
48
49 static game_params *default_params(void)
50 {
51     game_params *ret = snew(game_params);
52
53     ret->w = ret->h = 4;
54
55     return ret;
56 }
57
58 static int game_fetch_preset(int i, char **name, game_params **params)
59 {
60     if (i == 0) {
61         *params = default_params();
62         *name = dupstr("4x4");
63         return TRUE;
64     }
65     return FALSE;
66 }
67
68 static void free_params(game_params *params)
69 {
70     sfree(params);
71 }
72
73 static game_params *dup_params(const game_params *params)
74 {
75     game_params *ret = snew(game_params);
76     *ret = *params;                    /* structure copy */
77     return ret;
78 }
79
80 static void decode_params(game_params *ret, char const *string)
81 {
82     ret->w = ret->h = atoi(string);
83     while (*string && isdigit((unsigned char)*string)) string++;
84     if (*string == 'x') {
85         string++;
86         ret->h = atoi(string);
87     }
88 }
89
90 static char *encode_params(const game_params *params, int full)
91 {
92     char data[256];
93
94     sprintf(data, "%dx%d", params->w, params->h);
95
96     return dupstr(data);
97 }
98
99 static config_item *game_configure(const game_params *params)
100 {
101     config_item *ret;
102     char buf[80];
103
104     ret = snewn(3, config_item);
105
106     ret[0].name = "Width";
107     ret[0].type = C_STRING;
108     sprintf(buf, "%d", params->w);
109     ret[0].sval = dupstr(buf);
110     ret[0].ival = 0;
111
112     ret[1].name = "Height";
113     ret[1].type = C_STRING;
114     sprintf(buf, "%d", params->h);
115     ret[1].sval = dupstr(buf);
116     ret[1].ival = 0;
117
118     ret[2].name = NULL;
119     ret[2].type = C_END;
120     ret[2].sval = NULL;
121     ret[2].ival = 0;
122
123     return ret;
124 }
125
126 static game_params *custom_params(const config_item *cfg)
127 {
128     game_params *ret = snew(game_params);
129
130     ret->w = atoi(cfg[0].sval);
131     ret->h = atoi(cfg[1].sval);
132
133     return ret;
134 }
135
136 static char *validate_params(const game_params *params, int full)
137 {
138     if (params->w < 2 || params->h < 2)
139         return "Width and height must both be at least two";
140
141     return NULL;
142 }
143
144 static int perm_parity(int *perm, int n)
145 {
146     int i, j, ret;
147
148     ret = 0;
149
150     for (i = 0; i < n-1; i++)
151         for (j = i+1; j < n; j++)
152             if (perm[i] > perm[j])
153                 ret = !ret;
154
155     return ret;
156 }
157
158 static char *new_game_desc(const game_params *params, random_state *rs,
159                            char **aux, int interactive)
160 {
161     int gap, n, i, x;
162     int x1, x2, p1, p2, parity;
163     int *tiles, *used;
164     char *ret;
165     int retlen;
166
167     n = params->w * params->h;
168
169     tiles = snewn(n, int);
170     used = snewn(n, int);
171
172     for (i = 0; i < n; i++) {
173         tiles[i] = -1;
174         used[i] = FALSE;
175     }
176
177     gap = random_upto(rs, n);
178     tiles[gap] = 0;
179     used[0] = TRUE;
180
181     /*
182      * Place everything else except the last two tiles.
183      */
184     for (x = 0, i = n-1; i > 2; i--) {
185         int k = random_upto(rs, i);
186         int j;
187
188         for (j = 0; j < n; j++)
189             if (!used[j] && (k-- == 0))
190                 break;
191
192         assert(j < n && !used[j]);
193         used[j] = TRUE;
194
195         while (tiles[x] >= 0)
196             x++;
197         assert(x < n);
198         tiles[x] = j;
199     }
200
201     /*
202      * Find the last two locations, and the last two pieces.
203      */
204     while (tiles[x] >= 0)
205         x++;
206     assert(x < n);
207     x1 = x;
208     x++;
209     while (tiles[x] >= 0)
210         x++;
211     assert(x < n);
212     x2 = x;
213
214     for (i = 0; i < n; i++)
215         if (!used[i])
216             break;
217     p1 = i;
218     for (i = p1+1; i < n; i++)
219         if (!used[i])
220             break;
221     p2 = i;
222
223     /*
224      * Determine the required parity of the overall permutation.
225      * This is the XOR of:
226      * 
227      *  - The chessboard parity ((x^y)&1) of the gap square. The
228      *    bottom right counts as even.
229      * 
230      *  - The parity of n. (The target permutation is 1,...,n-1,0
231      *    rather than 0,...,n-1; this is a cyclic permutation of
232      *    the starting point and hence is odd iff n is even.)
233      */
234     parity = ((X(params, gap) - (params->w-1)) ^
235               (Y(params, gap) - (params->h-1)) ^
236               (n+1)) & 1;
237
238     /*
239      * Try the last two tiles one way round. If that fails, swap
240      * them.
241      */
242     tiles[x1] = p1;
243     tiles[x2] = p2;
244     if (perm_parity(tiles, n) != parity) {
245         tiles[x1] = p2;
246         tiles[x2] = p1;
247         assert(perm_parity(tiles, n) == parity);
248     }
249
250     /*
251      * Now construct the game description, by describing the tile
252      * array as a simple sequence of comma-separated integers.
253      */
254     ret = NULL;
255     retlen = 0;
256     for (i = 0; i < n; i++) {
257         char buf[80];
258         int k;
259
260         k = sprintf(buf, "%d,", tiles[i]);
261
262         ret = sresize(ret, retlen + k + 1, char);
263         strcpy(ret + retlen, buf);
264         retlen += k;
265     }
266     ret[retlen-1] = '\0';              /* delete last comma */
267
268     sfree(tiles);
269     sfree(used);
270
271     return ret;
272 }
273
274 static char *validate_desc(const game_params *params, const char *desc)
275 {
276     const char *p;
277     char *err;
278     int i, area;
279     int *used;
280
281     area = params->w * params->h;
282     p = desc;
283     err = NULL;
284
285     used = snewn(area, int);
286     for (i = 0; i < area; i++)
287         used[i] = FALSE;
288
289     for (i = 0; i < area; i++) {
290         const char *q = p;
291         int n;
292
293         if (*p < '0' || *p > '9') {
294             err = "Not enough numbers in string";
295             goto leave;
296         }
297         while (*p >= '0' && *p <= '9')
298             p++;
299         if (i < area-1 && *p != ',') {
300             err = "Expected comma after number";
301             goto leave;
302         }
303         else if (i == area-1 && *p) {
304             err = "Excess junk at end of string";
305             goto leave;
306         }
307         n = atoi(q);
308         if (n < 0 || n >= area) {
309             err = "Number out of range";
310             goto leave;
311         }
312         if (used[n]) {
313             err = "Number used twice";
314             goto leave;
315         }
316         used[n] = TRUE;
317
318         if (*p) p++;                   /* eat comma */
319     }
320
321     leave:
322     sfree(used);
323     return err;
324 }
325
326 static game_state *new_game(midend *me, const game_params *params,
327                             const char *desc)
328 {
329     game_state *state = snew(game_state);
330     int i;
331     const char *p;
332
333     state->w = params->w;
334     state->h = params->h;
335     state->n = params->w * params->h;
336     state->tiles = snewn(state->n, int);
337
338     state->gap_pos = 0;
339     p = desc;
340     i = 0;
341     for (i = 0; i < state->n; i++) {
342         assert(*p);
343         state->tiles[i] = atoi(p);
344         if (state->tiles[i] == 0)
345             state->gap_pos = i;
346         while (*p && *p != ',')
347             p++;
348         if (*p) p++;                   /* eat comma */
349     }
350     assert(!*p);
351     assert(state->tiles[state->gap_pos] == 0);
352
353     state->completed = state->movecount = 0;
354     state->used_solve = FALSE;
355
356     return state;
357 }
358
359 static game_state *dup_game(const game_state *state)
360 {
361     game_state *ret = snew(game_state);
362
363     ret->w = state->w;
364     ret->h = state->h;
365     ret->n = state->n;
366     ret->tiles = snewn(state->w * state->h, int);
367     memcpy(ret->tiles, state->tiles, state->w * state->h * sizeof(int));
368     ret->gap_pos = state->gap_pos;
369     ret->completed = state->completed;
370     ret->movecount = state->movecount;
371     ret->used_solve = state->used_solve;
372
373     return ret;
374 }
375
376 static void free_game(game_state *state)
377 {
378     sfree(state->tiles);
379     sfree(state);
380 }
381
382 static char *solve_game(const game_state *state, const game_state *currstate,
383                         const char *aux, char **error)
384 {
385     return dupstr("S");
386 }
387
388 static int game_can_format_as_text_now(const game_params *params)
389 {
390     return TRUE;
391 }
392
393 static char *game_text_format(const game_state *state)
394 {
395     char *ret, *p, buf[80];
396     int x, y, col, maxlen;
397
398     /*
399      * First work out how many characters we need to display each
400      * number.
401      */
402     col = sprintf(buf, "%d", state->n-1);
403
404     /*
405      * Now we know the exact total size of the grid we're going to
406      * produce: it's got h rows, each containing w lots of col, w-1
407      * spaces and a trailing newline.
408      */
409     maxlen = state->h * state->w * (col+1);
410
411     ret = snewn(maxlen+1, char);
412     p = ret;
413
414     for (y = 0; y < state->h; y++) {
415         for (x = 0; x < state->w; x++) {
416             int v = state->tiles[state->w*y+x];
417             if (v == 0)
418                 sprintf(buf, "%*s", col, "");
419             else
420                 sprintf(buf, "%*d", col, v);
421             memcpy(p, buf, col);
422             p += col;
423             if (x+1 == state->w)
424                 *p++ = '\n';
425             else
426                 *p++ = ' ';
427         }
428     }
429
430     assert(p - ret == maxlen);
431     *p = '\0';
432     return ret;
433 }
434
435 static game_ui *new_ui(const game_state *state)
436 {
437     return NULL;
438 }
439
440 static void free_ui(game_ui *ui)
441 {
442 }
443
444 static char *encode_ui(const game_ui *ui)
445 {
446     return NULL;
447 }
448
449 static void decode_ui(game_ui *ui, const char *encoding)
450 {
451 }
452
453 static void game_changed_state(game_ui *ui, const game_state *oldstate,
454                                const game_state *newstate)
455 {
456 }
457
458 struct game_drawstate {
459     int started;
460     int w, h, bgcolour;
461     int *tiles;
462     int tilesize;
463 };
464
465 static char *interpret_move(const game_state *state, game_ui *ui,
466                             const game_drawstate *ds,
467                             int x, int y, int button)
468 {
469     int gx, gy, dx, dy;
470     char buf[80];
471
472     button &= ~MOD_MASK;
473
474     gx = X(state, state->gap_pos);
475     gy = Y(state, state->gap_pos);
476
477     if (button == CURSOR_RIGHT && gx > 0)
478         dx = gx - 1, dy = gy;
479     else if (button == CURSOR_LEFT && gx < state->w-1)
480         dx = gx + 1, dy = gy;
481     else if (button == CURSOR_DOWN && gy > 0)
482         dy = gy - 1, dx = gx;
483     else if (button == CURSOR_UP && gy < state->h-1)
484         dy = gy + 1, dx = gx;
485     else if (button == LEFT_BUTTON) {
486         dx = FROMCOORD(x);
487         dy = FROMCOORD(y);
488         if (dx < 0 || dx >= state->w || dy < 0 || dy >= state->h)
489             return NULL;               /* out of bounds */
490         /*
491          * Any click location should be equal to the gap location
492          * in _precisely_ one coordinate.
493          */
494         if ((dx == gx && dy == gy) || (dx != gx && dy != gy))
495             return NULL;
496     } else
497         return NULL;                   /* no move */
498
499     sprintf(buf, "M%d,%d", dx, dy);
500     return dupstr(buf);
501 }
502
503 static game_state *execute_move(const game_state *from, const char *move)
504 {
505     int gx, gy, dx, dy, ux, uy, up, p;
506     game_state *ret;
507
508     if (!strcmp(move, "S")) {
509         int i;
510
511         ret = dup_game(from);
512
513         /*
514          * Simply replace the grid with a solved one. For this game,
515          * this isn't a useful operation for actually telling the user
516          * what they should have done, but it is useful for
517          * conveniently being able to get hold of a clean state from
518          * which to practise manoeuvres.
519          */
520         for (i = 0; i < ret->n; i++)
521             ret->tiles[i] = (i+1) % ret->n;
522         ret->gap_pos = ret->n-1;
523         ret->used_solve = TRUE;
524         ret->completed = ret->movecount = 1;
525
526         return ret;
527     }
528
529     gx = X(from, from->gap_pos);
530     gy = Y(from, from->gap_pos);
531
532     if (move[0] != 'M' ||
533         sscanf(move+1, "%d,%d", &dx, &dy) != 2 ||
534         (dx == gx && dy == gy) || (dx != gx && dy != gy) ||
535         dx < 0 || dx >= from->w || dy < 0 || dy >= from->h)
536         return NULL;
537
538     /*
539      * Find the unit displacement from the original gap
540      * position towards this one.
541      */
542     ux = (dx < gx ? -1 : dx > gx ? +1 : 0);
543     uy = (dy < gy ? -1 : dy > gy ? +1 : 0);
544     up = C(from, ux, uy);
545
546     ret = dup_game(from);
547
548     ret->gap_pos = C(from, dx, dy);
549     assert(ret->gap_pos >= 0 && ret->gap_pos < ret->n);
550
551     ret->tiles[ret->gap_pos] = 0;
552
553     for (p = from->gap_pos; p != ret->gap_pos; p += up) {
554         assert(p >= 0 && p < from->n);
555         ret->tiles[p] = from->tiles[p + up];
556         ret->movecount++;
557     }
558
559     /*
560      * See if the game has been completed.
561      */
562     if (!ret->completed) {
563         ret->completed = ret->movecount;
564         for (p = 0; p < ret->n; p++)
565             if (ret->tiles[p] != (p < ret->n-1 ? p+1 : 0))
566                 ret->completed = 0;
567     }
568
569     return ret;
570 }
571
572 /* ----------------------------------------------------------------------
573  * Drawing routines.
574  */
575
576 static void game_compute_size(const game_params *params, int tilesize,
577                               int *x, int *y)
578 {
579     /* Ick: fake up `ds->tilesize' for macro expansion purposes */
580     struct { int tilesize; } ads, *ds = &ads;
581     ads.tilesize = tilesize;
582
583     *x = TILE_SIZE * params->w + 2 * BORDER;
584     *y = TILE_SIZE * params->h + 2 * BORDER;
585 }
586
587 static void game_set_size(drawing *dr, game_drawstate *ds,
588                           const game_params *params, int tilesize)
589 {
590     ds->tilesize = tilesize;
591 }
592
593 static float *game_colours(frontend *fe, int *ncolours)
594 {
595     float *ret = snewn(3 * NCOLOURS, float);
596     int i;
597
598     game_mkhighlight(fe, ret, COL_BACKGROUND, COL_HIGHLIGHT, COL_LOWLIGHT);
599
600     for (i = 0; i < 3; i++)
601         ret[COL_TEXT * 3 + i] = 0.0;
602
603     *ncolours = NCOLOURS;
604     return ret;
605 }
606
607 static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state)
608 {
609     struct game_drawstate *ds = snew(struct game_drawstate);
610     int i;
611
612     ds->started = FALSE;
613     ds->w = state->w;
614     ds->h = state->h;
615     ds->bgcolour = COL_BACKGROUND;
616     ds->tiles = snewn(ds->w*ds->h, int);
617     ds->tilesize = 0;                  /* haven't decided yet */
618     for (i = 0; i < ds->w*ds->h; i++)
619         ds->tiles[i] = -1;
620
621     return ds;
622 }
623
624 static void game_free_drawstate(drawing *dr, game_drawstate *ds)
625 {
626     sfree(ds->tiles);
627     sfree(ds);
628 }
629
630 static void draw_tile(drawing *dr, game_drawstate *ds, const game_state *state,
631                       int x, int y, int tile, int flash_colour)
632 {
633     if (tile == 0) {
634         draw_rect(dr, x, y, TILE_SIZE, TILE_SIZE,
635                   flash_colour);
636     } else {
637         int coords[6];
638         char str[40];
639
640         coords[0] = x + TILE_SIZE - 1;
641         coords[1] = y + TILE_SIZE - 1;
642         coords[2] = x + TILE_SIZE - 1;
643         coords[3] = y;
644         coords[4] = x;
645         coords[5] = y + TILE_SIZE - 1;
646         draw_polygon(dr, coords, 3, COL_LOWLIGHT, COL_LOWLIGHT);
647
648         coords[0] = x;
649         coords[1] = y;
650         draw_polygon(dr, coords, 3, COL_HIGHLIGHT, COL_HIGHLIGHT);
651
652         draw_rect(dr, x + HIGHLIGHT_WIDTH, y + HIGHLIGHT_WIDTH,
653                   TILE_SIZE - 2*HIGHLIGHT_WIDTH, TILE_SIZE - 2*HIGHLIGHT_WIDTH,
654                   flash_colour);
655
656         sprintf(str, "%d", tile);
657         draw_text(dr, x + TILE_SIZE/2, y + TILE_SIZE/2,
658                   FONT_VARIABLE, TILE_SIZE/3, ALIGN_VCENTRE | ALIGN_HCENTRE,
659                   COL_TEXT, str);
660     }
661     draw_update(dr, x, y, TILE_SIZE, TILE_SIZE);
662 }
663
664 static void game_redraw(drawing *dr, game_drawstate *ds,
665                         const game_state *oldstate, const game_state *state,
666                         int dir, const game_ui *ui,
667                         float animtime, float flashtime)
668 {
669     int i, pass, bgcolour;
670
671     if (flashtime > 0) {
672         int frame = (int)(flashtime / FLASH_FRAME);
673         bgcolour = (frame % 2 ? COL_LOWLIGHT : COL_HIGHLIGHT);
674     } else
675         bgcolour = COL_BACKGROUND;
676
677     if (!ds->started) {
678         int coords[10];
679
680         draw_rect(dr, 0, 0,
681                   TILE_SIZE * state->w + 2 * BORDER,
682                   TILE_SIZE * state->h + 2 * BORDER, COL_BACKGROUND);
683         draw_update(dr, 0, 0,
684                     TILE_SIZE * state->w + 2 * BORDER,
685                     TILE_SIZE * state->h + 2 * BORDER);
686
687         /*
688          * Recessed area containing the whole puzzle.
689          */
690         coords[0] = COORD(state->w) + HIGHLIGHT_WIDTH - 1;
691         coords[1] = COORD(state->h) + HIGHLIGHT_WIDTH - 1;
692         coords[2] = COORD(state->w) + HIGHLIGHT_WIDTH - 1;
693         coords[3] = COORD(0) - HIGHLIGHT_WIDTH;
694         coords[4] = coords[2] - TILE_SIZE;
695         coords[5] = coords[3] + TILE_SIZE;
696         coords[8] = COORD(0) - HIGHLIGHT_WIDTH;
697         coords[9] = COORD(state->h) + HIGHLIGHT_WIDTH - 1;
698         coords[6] = coords[8] + TILE_SIZE;
699         coords[7] = coords[9] - TILE_SIZE;
700         draw_polygon(dr, coords, 5, COL_HIGHLIGHT, COL_HIGHLIGHT);
701
702         coords[1] = COORD(0) - HIGHLIGHT_WIDTH;
703         coords[0] = COORD(0) - HIGHLIGHT_WIDTH;
704         draw_polygon(dr, coords, 5, COL_LOWLIGHT, COL_LOWLIGHT);
705
706         ds->started = TRUE;
707     }
708
709     /*
710      * Now draw each tile. We do this in two passes to make
711      * animation easy.
712      */
713     for (pass = 0; pass < 2; pass++) {
714         for (i = 0; i < state->n; i++) {
715             int t, t0;
716             /*
717              * Figure out what should be displayed at this
718              * location. It's either a simple tile, or it's a
719              * transition between two tiles (in which case we say
720              * -1 because it must always be drawn).
721              */
722
723             if (oldstate && oldstate->tiles[i] != state->tiles[i])
724                 t = -1;
725             else
726                 t = state->tiles[i];
727
728             t0 = t;
729
730             if (ds->bgcolour != bgcolour ||   /* always redraw when flashing */
731                 ds->tiles[i] != t || ds->tiles[i] == -1 || t == -1) {
732                 int x, y;
733
734                 /*
735                  * Figure out what to _actually_ draw, and where to
736                  * draw it.
737                  */
738                 if (t == -1) {
739                     int x0, y0, x1, y1;
740                     int j;
741
742                     /*
743                      * On the first pass, just blank the tile.
744                      */
745                     if (pass == 0) {
746                         x = COORD(X(state, i));
747                         y = COORD(Y(state, i));
748                         t = 0;
749                     } else {
750                         float c;
751
752                         t = state->tiles[i];
753
754                         /*
755                          * Don't bother moving the gap; just don't
756                          * draw it.
757                          */
758                         if (t == 0)
759                             continue;
760
761                         /*
762                          * Find the coordinates of this tile in the old and
763                          * new states.
764                          */
765                         x1 = COORD(X(state, i));
766                         y1 = COORD(Y(state, i));
767                         for (j = 0; j < oldstate->n; j++)
768                             if (oldstate->tiles[j] == state->tiles[i])
769                                 break;
770                         assert(j < oldstate->n);
771                         x0 = COORD(X(state, j));
772                         y0 = COORD(Y(state, j));
773
774                         c = (animtime / ANIM_TIME);
775                         if (c < 0.0F) c = 0.0F;
776                         if (c > 1.0F) c = 1.0F;
777
778                         x = x0 + (int)(c * (x1 - x0));
779                         y = y0 + (int)(c * (y1 - y0));
780                     }
781
782                 } else {
783                     if (pass == 0)
784                         continue;
785                     x = COORD(X(state, i));
786                     y = COORD(Y(state, i));
787                 }
788
789                 draw_tile(dr, ds, state, x, y, t, bgcolour);
790             }
791             ds->tiles[i] = t0;
792         }
793     }
794     ds->bgcolour = bgcolour;
795
796     /*
797      * Update the status bar.
798      */
799     {
800         char statusbuf[256];
801
802         /*
803          * Don't show the new status until we're also showing the
804          * new _state_ - after the game animation is complete.
805          */
806         if (oldstate)
807             state = oldstate;
808
809         if (state->used_solve)
810             sprintf(statusbuf, "Moves since auto-solve: %d",
811                     state->movecount - state->completed);
812         else
813             sprintf(statusbuf, "%sMoves: %d",
814                     (state->completed ? "COMPLETED! " : ""),
815                     (state->completed ? state->completed : state->movecount));
816
817         status_bar(dr, statusbuf);
818     }
819 }
820
821 static float game_anim_length(const game_state *oldstate,
822                               const game_state *newstate, int dir, game_ui *ui)
823 {
824     return ANIM_TIME;
825 }
826
827 static float game_flash_length(const game_state *oldstate,
828                                const game_state *newstate, int dir, game_ui *ui)
829 {
830     if (!oldstate->completed && newstate->completed &&
831         !oldstate->used_solve && !newstate->used_solve)
832         return 2 * FLASH_FRAME;
833     else
834         return 0.0F;
835 }
836
837 static int game_status(const game_state *state)
838 {
839     return state->completed ? +1 : 0;
840 }
841
842 static int game_timing_state(const game_state *state, game_ui *ui)
843 {
844     return TRUE;
845 }
846
847 static void game_print_size(const game_params *params, float *x, float *y)
848 {
849 }
850
851 static void game_print(drawing *dr, const game_state *state, int tilesize)
852 {
853 }
854
855 #ifdef COMBINED
856 #define thegame fifteen
857 #endif
858
859 const struct game thegame = {
860     "Fifteen", "games.fifteen", "fifteen",
861     default_params,
862     game_fetch_preset,
863     decode_params,
864     encode_params,
865     free_params,
866     dup_params,
867     TRUE, game_configure, custom_params,
868     validate_params,
869     new_game_desc,
870     validate_desc,
871     new_game,
872     dup_game,
873     free_game,
874     TRUE, solve_game,
875     TRUE, game_can_format_as_text_now, game_text_format,
876     new_ui,
877     free_ui,
878     encode_ui,
879     decode_ui,
880     game_changed_state,
881     interpret_move,
882     execute_move,
883     PREFERRED_TILE_SIZE, game_compute_size, game_set_size,
884     game_colours,
885     game_new_drawstate,
886     game_free_drawstate,
887     game_redraw,
888     game_anim_length,
889     game_flash_length,
890     game_status,
891     FALSE, FALSE, game_print_size, game_print,
892     TRUE,                              /* wants_statusbar */
893     FALSE, game_timing_state,
894     0,                                 /* flags */
895 };