chiark / gitweb /
Add a midend function to return the current random seed, parallel to
authorSimon Tatham <anakin@pobox.com>
Sat, 30 Mar 2013 16:59:19 +0000 (16:59 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 30 Mar 2013 16:59:19 +0000 (16:59 +0000)
the existing one that returns the game id. No front end has so far
needed this, but one is about to.

[originally from svn r9778]

devel.but
midend.c
puzzles.h

index 96686515dabc168b50e87459dabb4b5b119571dd..02f9cfa32c7b4efbe6e02c7be931d72ed6069b89 100644 (file)
--- a/devel.but
+++ b/devel.but
@@ -3091,6 +3091,17 @@ Returns a descriptive game ID (i.e. one in the form
 \cq{params:description}) describing the game currently active in the
 mid-end. The returned string is dynamically allocated.
 
+\H{midend-get-random-seed} \cw{midend_get_random_seed()}
+
+\c char *midend_get_random_seed(midend *me)
+
+Returns a random game ID (i.e. one in the form \cq{params#seedstring})
+describing the game currently active in the mid-end, if there is one.
+If the game was created by entering a description, no random seed will
+currently exist and this function will return \cw{NULL}.
+
+The returned string, if it is non-\cw{NULL}, is dynamically allocated.
+
 \H{midend-can-format-as-text-now} \cw{midend_can_format_as_text_now()}
 
 \c int midend_can_format_as_text_now(midend *me);
index 53dca21fdcae2ece381b60b777d0afa83c6f09c4..fddf01d8e6bc65226df6d7c32fddfb559afb3fbc 100644 (file)
--- a/midend.c
+++ b/midend.c
@@ -1304,6 +1304,21 @@ char *midend_get_game_id(midend *me)
     return ret;
 }
 
+char *midend_get_random_seed(midend *me)
+{
+    char *parstr, *ret;
+
+    if (!me->seedstr)
+        return NULL;
+
+    parstr = me->ourgame->encode_params(me->curparams, TRUE);
+    assert(parstr);
+    ret = snewn(strlen(parstr) + strlen(me->seedstr) + 2, char);
+    sprintf(ret, "%s#%s", parstr, me->seedstr);
+    sfree(parstr);
+    return ret;
+}
+
 char *midend_set_config(midend *me, int which, config_item *cfg)
 {
     char *error;
index e8a75c20f7c343919a945a780214f9ebe40879ba..fbd1828e2fc54147f9d7e12ba12ade30c9db5698 100644 (file)
--- a/puzzles.h
+++ b/puzzles.h
@@ -251,6 +251,7 @@ config_item *midend_get_config(midend *me, int which, char **wintitle);
 char *midend_set_config(midend *me, int which, config_item *cfg);
 char *midend_game_id(midend *me, char *id);
 char *midend_get_game_id(midend *me);
+char *midend_get_random_seed(midend *me);
 int midend_can_format_as_text_now(midend *me);
 char *midend_text_format(midend *me);
 char *midend_solve(midend *me);