Add a `jumble' key (`J') to Net, which scrambles the positions of all unlocked
[sgt/puzzles] / fifteen.c
index 74fd4fc..f6ff24a 100644 (file)
--- a/fifteen.c
+++ b/fifteen.c
@@ -6,11 +6,13 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <ctype.h>
 #include <math.h>
 
 #include "puzzles.h"
 
 const char *const game_name = "Fifteen";
+const char *const game_winhelp_topic = "games.fifteen";
 const int game_can_configure = TRUE;
 
 #define TILE_SIZE 48
@@ -19,8 +21,8 @@ const int game_can_configure = TRUE;
 #define COORD(x)  ( (x) * TILE_SIZE + BORDER )
 #define FROMCOORD(x)  ( ((x) - BORDER + TILE_SIZE) / TILE_SIZE - 1 )
 
-#define ANIM_TIME 0.1F
-#define FLASH_FRAME 0.1F
+#define ANIM_TIME 0.13F
+#define FLASH_FRAME 0.13F
 
 #define X(state, i) ( (i) % (state)->w )
 #define Y(state, i) ( (i) / (state)->w )
@@ -72,6 +74,29 @@ game_params *dup_params(game_params *params)
     return ret;
 }
 
+game_params *decode_params(char const *string)
+{
+    game_params *ret = default_params();
+
+    ret->w = ret->h = atoi(string);
+    while (*string && isdigit(*string)) string++;
+    if (*string == 'x') {
+        string++;
+        ret->h = atoi(string);
+    }
+
+    return ret;
+}
+
+char *encode_params(game_params *params)
+{
+    char data[256];
+
+    sprintf(data, "%dx%d", params->w, params->h);
+
+    return dupstr(data);
+}
+
 config_item *game_configure(game_params *params)
 {
     config_item *ret;
@@ -131,7 +156,7 @@ int perm_parity(int *perm, int n)
     return ret;
 }
 
-char *new_game_seed(game_params *params)
+char *new_game_seed(game_params *params, random_state *rs)
 {
     int gap, n, i, x;
     int x1, x2, p1, p2, parity;
@@ -149,7 +174,7 @@ char *new_game_seed(game_params *params)
         used[i] = FALSE;
     }
 
-    gap = rand_upto(n);
+    gap = random_upto(rs, n);
     tiles[gap] = 0;
     used[0] = TRUE;
 
@@ -157,7 +182,7 @@ char *new_game_seed(game_params *params)
      * Place everything else except the last two tiles.
      */
     for (x = 0, i = n-1; i > 2; i--) {
-        int k = rand_upto(i);
+        int k = random_upto(rs, i);
         int j;
 
         for (j = 0; j < n; j++)
@@ -349,7 +374,16 @@ void free_game(game_state *state)
     sfree(state);
 }
 
-game_state *make_move(game_state *from, int x, int y, int button)
+game_ui *new_ui(game_state *state)
+{
+    return NULL;
+}
+
+void free_ui(game_ui *ui)
+{
+}
+
+game_state *make_move(game_state *from, game_ui *ui, int x, int y, int button)
 {
     int gx, gy, dx, dy, ux, uy, up, p;
     game_state *ret;
@@ -519,7 +553,8 @@ static void draw_tile(frontend *fe, game_state *state, int x, int y,
 }
 
 void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
-                 game_state *state, float animtime, float flashtime)
+                 game_state *state, int dir, game_ui *ui,
+                 float animtime, float flashtime)
 {
     int i, pass, bgcolour;
 
@@ -667,12 +702,12 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
     }
 }
 
-float game_anim_length(game_state *oldstate, game_state *newstate)
+float game_anim_length(game_state *oldstate, game_state *newstate, int dir)
 {
     return ANIM_TIME;
 }
 
-float game_flash_length(game_state *oldstate, game_state *newstate)
+float game_flash_length(game_state *oldstate, game_state *newstate, int dir)
 {
     if (!oldstate->completed && newstate->completed)
         return 2 * FLASH_FRAME;