chiark / gitweb /
Invert the Fifteen cursor if FIFTEEN_INVERT_CURSOR ~= ^[yY].*$
[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 int flip_cursor(int button)
466 {
467     switch (button) {
468     case CURSOR_UP: return CURSOR_DOWN;
469     case CURSOR_DOWN: return CURSOR_UP;
470     case CURSOR_LEFT: return CURSOR_RIGHT;
471     case CURSOR_RIGHT: return CURSOR_LEFT;
472     }
473     return 0;
474 }
475
476 static char *interpret_move(const game_state *state, game_ui *ui,
477                             const game_drawstate *ds,
478                             int x, int y, int button)
479 {
480     int cx = X(state, state->gap_pos), nx = cx;
481     int cy = Y(state, state->gap_pos), ny = cy;
482     char buf[80];
483
484     button &= ~MOD_MASK;
485
486     if (button == LEFT_BUTTON) {
487         nx = FROMCOORD(x);
488         ny = FROMCOORD(y);
489         if (nx < 0 || nx >= state->w || ny < 0 || ny >= state->h)
490             return NULL;               /* out of bounds */
491     } else if (IS_CURSOR_MOVE(button)) {
492         static int invert_cursor = -1;
493         if (invert_cursor == -1) {
494             char *env = getenv("FIFTEEN_INVERT_CURSOR");
495             invert_cursor = (env && (env[0] == 'y' || env[0] == 'Y'));
496         }
497         button = flip_cursor(button); /* the default */
498         if (invert_cursor)
499             button = flip_cursor(button); /* undoes the first flip */
500         move_cursor(button, &nx, &ny, state->w, state->h, FALSE);
501     } else
502         return NULL;                   /* no move */
503
504     /*
505      * Any click location should be equal to the gap location
506      * in _precisely_ one coordinate.
507      */
508     if ((cx == nx) ^ (cy == ny)) {
509         sprintf(buf, "M%d,%d", nx, ny);
510         return dupstr(buf);
511     }
512
513     return NULL;
514 }
515
516 static game_state *execute_move(const game_state *from, const char *move)
517 {
518     int gx, gy, dx, dy, ux, uy, up, p;
519     game_state *ret;
520
521     if (!strcmp(move, "S")) {
522         int i;
523
524         ret = dup_game(from);
525
526         /*
527          * Simply replace the grid with a solved one. For this game,
528          * this isn't a useful operation for actually telling the user
529          * what they should have done, but it is useful for
530          * conveniently being able to get hold of a clean state from
531          * which to practise manoeuvres.
532          */
533         for (i = 0; i < ret->n; i++)
534             ret->tiles[i] = (i+1) % ret->n;
535         ret->gap_pos = ret->n-1;
536         ret->used_solve = TRUE;
537         ret->completed = ret->movecount = 1;
538
539         return ret;
540     }
541
542     gx = X(from, from->gap_pos);
543     gy = Y(from, from->gap_pos);
544
545     if (move[0] != 'M' ||
546         sscanf(move+1, "%d,%d", &dx, &dy) != 2 ||
547         (dx == gx && dy == gy) || (dx != gx && dy != gy) ||
548         dx < 0 || dx >= from->w || dy < 0 || dy >= from->h)
549         return NULL;
550
551     /*
552      * Find the unit displacement from the original gap
553      * position towards this one.
554      */
555     ux = (dx < gx ? -1 : dx > gx ? +1 : 0);
556     uy = (dy < gy ? -1 : dy > gy ? +1 : 0);
557     up = C(from, ux, uy);
558
559     ret = dup_game(from);
560
561     ret->gap_pos = C(from, dx, dy);
562     assert(ret->gap_pos >= 0 && ret->gap_pos < ret->n);
563
564     ret->tiles[ret->gap_pos] = 0;
565
566     for (p = from->gap_pos; p != ret->gap_pos; p += up) {
567         assert(p >= 0 && p < from->n);
568         ret->tiles[p] = from->tiles[p + up];
569         ret->movecount++;
570     }
571
572     /*
573      * See if the game has been completed.
574      */
575     if (!ret->completed) {
576         ret->completed = ret->movecount;
577         for (p = 0; p < ret->n; p++)
578             if (ret->tiles[p] != (p < ret->n-1 ? p+1 : 0))
579                 ret->completed = 0;
580     }
581
582     return ret;
583 }
584
585 /* ----------------------------------------------------------------------
586  * Drawing routines.
587  */
588
589 static void game_compute_size(const game_params *params, int tilesize,
590                               int *x, int *y)
591 {
592     /* Ick: fake up `ds->tilesize' for macro expansion purposes */
593     struct { int tilesize; } ads, *ds = &ads;
594     ads.tilesize = tilesize;
595
596     *x = TILE_SIZE * params->w + 2 * BORDER;
597     *y = TILE_SIZE * params->h + 2 * BORDER;
598 }
599
600 static void game_set_size(drawing *dr, game_drawstate *ds,
601                           const game_params *params, int tilesize)
602 {
603     ds->tilesize = tilesize;
604 }
605
606 static float *game_colours(frontend *fe, int *ncolours)
607 {
608     float *ret = snewn(3 * NCOLOURS, float);
609     int i;
610
611     game_mkhighlight(fe, ret, COL_BACKGROUND, COL_HIGHLIGHT, COL_LOWLIGHT);
612
613     for (i = 0; i < 3; i++)
614         ret[COL_TEXT * 3 + i] = 0.0;
615
616     *ncolours = NCOLOURS;
617     return ret;
618 }
619
620 static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state)
621 {
622     struct game_drawstate *ds = snew(struct game_drawstate);
623     int i;
624
625     ds->started = FALSE;
626     ds->w = state->w;
627     ds->h = state->h;
628     ds->bgcolour = COL_BACKGROUND;
629     ds->tiles = snewn(ds->w*ds->h, int);
630     ds->tilesize = 0;                  /* haven't decided yet */
631     for (i = 0; i < ds->w*ds->h; i++)
632         ds->tiles[i] = -1;
633
634     return ds;
635 }
636
637 static void game_free_drawstate(drawing *dr, game_drawstate *ds)
638 {
639     sfree(ds->tiles);
640     sfree(ds);
641 }
642
643 static void draw_tile(drawing *dr, game_drawstate *ds, const game_state *state,
644                       int x, int y, int tile, int flash_colour)
645 {
646     if (tile == 0) {
647         draw_rect(dr, x, y, TILE_SIZE, TILE_SIZE,
648                   flash_colour);
649     } else {
650         int coords[6];
651         char str[40];
652
653         coords[0] = x + TILE_SIZE - 1;
654         coords[1] = y + TILE_SIZE - 1;
655         coords[2] = x + TILE_SIZE - 1;
656         coords[3] = y;
657         coords[4] = x;
658         coords[5] = y + TILE_SIZE - 1;
659         draw_polygon(dr, coords, 3, COL_LOWLIGHT, COL_LOWLIGHT);
660
661         coords[0] = x;
662         coords[1] = y;
663         draw_polygon(dr, coords, 3, COL_HIGHLIGHT, COL_HIGHLIGHT);
664
665         draw_rect(dr, x + HIGHLIGHT_WIDTH, y + HIGHLIGHT_WIDTH,
666                   TILE_SIZE - 2*HIGHLIGHT_WIDTH, TILE_SIZE - 2*HIGHLIGHT_WIDTH,
667                   flash_colour);
668
669         sprintf(str, "%d", tile);
670         draw_text(dr, x + TILE_SIZE/2, y + TILE_SIZE/2,
671                   FONT_VARIABLE, TILE_SIZE/3, ALIGN_VCENTRE | ALIGN_HCENTRE,
672                   COL_TEXT, str);
673     }
674     draw_update(dr, x, y, TILE_SIZE, TILE_SIZE);
675 }
676
677 static void game_redraw(drawing *dr, game_drawstate *ds,
678                         const game_state *oldstate, const game_state *state,
679                         int dir, const game_ui *ui,
680                         float animtime, float flashtime)
681 {
682     int i, pass, bgcolour;
683
684     if (flashtime > 0) {
685         int frame = (int)(flashtime / FLASH_FRAME);
686         bgcolour = (frame % 2 ? COL_LOWLIGHT : COL_HIGHLIGHT);
687     } else
688         bgcolour = COL_BACKGROUND;
689
690     if (!ds->started) {
691         int coords[10];
692
693         draw_rect(dr, 0, 0,
694                   TILE_SIZE * state->w + 2 * BORDER,
695                   TILE_SIZE * state->h + 2 * BORDER, COL_BACKGROUND);
696         draw_update(dr, 0, 0,
697                     TILE_SIZE * state->w + 2 * BORDER,
698                     TILE_SIZE * state->h + 2 * BORDER);
699
700         /*
701          * Recessed area containing the whole puzzle.
702          */
703         coords[0] = COORD(state->w) + HIGHLIGHT_WIDTH - 1;
704         coords[1] = COORD(state->h) + HIGHLIGHT_WIDTH - 1;
705         coords[2] = COORD(state->w) + HIGHLIGHT_WIDTH - 1;
706         coords[3] = COORD(0) - HIGHLIGHT_WIDTH;
707         coords[4] = coords[2] - TILE_SIZE;
708         coords[5] = coords[3] + TILE_SIZE;
709         coords[8] = COORD(0) - HIGHLIGHT_WIDTH;
710         coords[9] = COORD(state->h) + HIGHLIGHT_WIDTH - 1;
711         coords[6] = coords[8] + TILE_SIZE;
712         coords[7] = coords[9] - TILE_SIZE;
713         draw_polygon(dr, coords, 5, COL_HIGHLIGHT, COL_HIGHLIGHT);
714
715         coords[1] = COORD(0) - HIGHLIGHT_WIDTH;
716         coords[0] = COORD(0) - HIGHLIGHT_WIDTH;
717         draw_polygon(dr, coords, 5, COL_LOWLIGHT, COL_LOWLIGHT);
718
719         ds->started = TRUE;
720     }
721
722     /*
723      * Now draw each tile. We do this in two passes to make
724      * animation easy.
725      */
726     for (pass = 0; pass < 2; pass++) {
727         for (i = 0; i < state->n; i++) {
728             int t, t0;
729             /*
730              * Figure out what should be displayed at this
731              * location. It's either a simple tile, or it's a
732              * transition between two tiles (in which case we say
733              * -1 because it must always be drawn).
734              */
735
736             if (oldstate && oldstate->tiles[i] != state->tiles[i])
737                 t = -1;
738             else
739                 t = state->tiles[i];
740
741             t0 = t;
742
743             if (ds->bgcolour != bgcolour ||   /* always redraw when flashing */
744                 ds->tiles[i] != t || ds->tiles[i] == -1 || t == -1) {
745                 int x, y;
746
747                 /*
748                  * Figure out what to _actually_ draw, and where to
749                  * draw it.
750                  */
751                 if (t == -1) {
752                     int x0, y0, x1, y1;
753                     int j;
754
755                     /*
756                      * On the first pass, just blank the tile.
757                      */
758                     if (pass == 0) {
759                         x = COORD(X(state, i));
760                         y = COORD(Y(state, i));
761                         t = 0;
762                     } else {
763                         float c;
764
765                         t = state->tiles[i];
766
767                         /*
768                          * Don't bother moving the gap; just don't
769                          * draw it.
770                          */
771                         if (t == 0)
772                             continue;
773
774                         /*
775                          * Find the coordinates of this tile in the old and
776                          * new states.
777                          */
778                         x1 = COORD(X(state, i));
779                         y1 = COORD(Y(state, i));
780                         for (j = 0; j < oldstate->n; j++)
781                             if (oldstate->tiles[j] == state->tiles[i])
782                                 break;
783                         assert(j < oldstate->n);
784                         x0 = COORD(X(state, j));
785                         y0 = COORD(Y(state, j));
786
787                         c = (animtime / ANIM_TIME);
788                         if (c < 0.0F) c = 0.0F;
789                         if (c > 1.0F) c = 1.0F;
790
791                         x = x0 + (int)(c * (x1 - x0));
792                         y = y0 + (int)(c * (y1 - y0));
793                     }
794
795                 } else {
796                     if (pass == 0)
797                         continue;
798                     x = COORD(X(state, i));
799                     y = COORD(Y(state, i));
800                 }
801
802                 draw_tile(dr, ds, state, x, y, t, bgcolour);
803             }
804             ds->tiles[i] = t0;
805         }
806     }
807     ds->bgcolour = bgcolour;
808
809     /*
810      * Update the status bar.
811      */
812     {
813         char statusbuf[256];
814
815         /*
816          * Don't show the new status until we're also showing the
817          * new _state_ - after the game animation is complete.
818          */
819         if (oldstate)
820             state = oldstate;
821
822         if (state->used_solve)
823             sprintf(statusbuf, "Moves since auto-solve: %d",
824                     state->movecount - state->completed);
825         else
826             sprintf(statusbuf, "%sMoves: %d",
827                     (state->completed ? "COMPLETED! " : ""),
828                     (state->completed ? state->completed : state->movecount));
829
830         status_bar(dr, statusbuf);
831     }
832 }
833
834 static float game_anim_length(const game_state *oldstate,
835                               const game_state *newstate, int dir, game_ui *ui)
836 {
837     return ANIM_TIME;
838 }
839
840 static float game_flash_length(const game_state *oldstate,
841                                const game_state *newstate, int dir, game_ui *ui)
842 {
843     if (!oldstate->completed && newstate->completed &&
844         !oldstate->used_solve && !newstate->used_solve)
845         return 2 * FLASH_FRAME;
846     else
847         return 0.0F;
848 }
849
850 static int game_status(const game_state *state)
851 {
852     return state->completed ? +1 : 0;
853 }
854
855 static int game_timing_state(const game_state *state, game_ui *ui)
856 {
857     return TRUE;
858 }
859
860 static void game_print_size(const game_params *params, float *x, float *y)
861 {
862 }
863
864 static void game_print(drawing *dr, const game_state *state, int tilesize)
865 {
866 }
867
868 #ifdef COMBINED
869 #define thegame fifteen
870 #endif
871
872 const struct game thegame = {
873     "Fifteen", "games.fifteen", "fifteen",
874     default_params,
875     game_fetch_preset,
876     decode_params,
877     encode_params,
878     free_params,
879     dup_params,
880     TRUE, game_configure, custom_params,
881     validate_params,
882     new_game_desc,
883     validate_desc,
884     new_game,
885     dup_game,
886     free_game,
887     TRUE, solve_game,
888     TRUE, game_can_format_as_text_now, game_text_format,
889     new_ui,
890     free_ui,
891     encode_ui,
892     decode_ui,
893     game_changed_state,
894     interpret_move,
895     execute_move,
896     PREFERRED_TILE_SIZE, game_compute_size, game_set_size,
897     game_colours,
898     game_new_drawstate,
899     game_free_drawstate,
900     game_redraw,
901     game_anim_length,
902     game_flash_length,
903     game_status,
904     FALSE, FALSE, game_print_size, game_print,
905     TRUE,                              /* wants_statusbar */
906     FALSE, game_timing_state,
907     0,                                 /* flags */
908 };