+ if (dx)
+ sprintf(buf, "R%d,%d", cy, dx);
+ else
+ sprintf(buf, "C%d,%d", cx, dy);
+ return dupstr(buf);
+}
+
+static game_state *execute_move(game_state *from, char *move)
+{
+ int cx, cy, dx, dy;
+ int tx, ty, n;
+ game_state *ret;
+
+ if (!strcmp(move, "S")) {
+ int i;
+
+ ret = dup_game(from);
+
+ /*
+ * Simply replace the grid with a solved one. For this game,
+ * this isn't a useful operation for actually telling the user
+ * what they should have done, but it is useful for
+ * conveniently being able to get hold of a clean state from
+ * which to practise manoeuvres.
+ */
+ for (i = 0; i < ret->n; i++)
+ ret->tiles[i] = i+1;
+ ret->used_solve = TRUE;
+ ret->completed = ret->movecount = 1;
+
+ return ret;
+ }
+
+ if (move[0] == 'R' && sscanf(move+1, "%d,%d", &cy, &dx) == 2 &&
+ cy >= 0 && cy < from->h) {
+ cx = dy = 0;
+ n = from->w;
+ } else if (move[0] == 'C' && sscanf(move+1, "%d,%d", &cx, &dy) == 2 &&
+ cx >= 0 && cx < from->w) {
+ cy = dx = 0;
+ n = from->h;
+ } else
+ return NULL;
+