shithub: puzzles

Download patch

ref: 4b02ebae717ccac8085030c6168175c88060d92b
parent: b77d727eb4a822d3ee70b6c5e0949e76e6def5ea
author: Simon Tatham <anakin@pobox.com>
date: Tue May 17 07:53:42 EDT 2005

Keyboard shortcuts for Twiddle: abcdABCD in line with the notation
Gareth and I have been using to analyse the game, and also the
number pad. They don't work sensibly for all sizes, but they'll be
handy for the most common ones.

[originally from svn r5793]

--- a/twiddle.c
+++ b/twiddle.c
@@ -604,30 +604,66 @@
 	y -= (n-1) * TILE_SIZE / 2;
 	x = FROMCOORD(x);
 	y = FROMCOORD(y);
-	if (x < 0 || x > w-n || y < 0 || y > w-n)
+	dir = (button == LEFT_BUTTON ? 1 : -1);
+	if (x < 0 || x > w-n || y < 0 || y > h-n)
 	    return NULL;
+    } else if (button == 'a' || button == 'A' || button==MOD_NUM_KEYPAD+'7') {
+        x = y = 0;
+        dir = (button == 'A' ? -1 : +1);
+    } else if (button == 'b' || button == 'B' || button==MOD_NUM_KEYPAD+'9') {
+        x = w-n;
+        y = 0;
+        dir = (button == 'B' ? -1 : +1);
+    } else if (button == 'c' || button == 'C' || button==MOD_NUM_KEYPAD+'1') {
+        x = 0;
+        y = h-n;
+        dir = (button == 'C' ? -1 : +1);
+    } else if (button == 'd' || button == 'D' || button==MOD_NUM_KEYPAD+'3') {
+        x = w-n;
+        y = h-n;
+        dir = (button == 'D' ? -1 : +1);
+    } else if (button==MOD_NUM_KEYPAD+'8' && (w-n) % 2 == 0) {
+        x = (w-n) / 2;
+        y = 0;
+        dir = +1;
+    } else if (button==MOD_NUM_KEYPAD+'2' && (w-n) % 2 == 0) {
+        x = (w-n) / 2;
+        y = h-n;
+        dir = +1;
+    } else if (button==MOD_NUM_KEYPAD+'4' && (h-n) % 2 == 0) {
+        x = 0;
+        y = (h-n) / 2;
+        dir = +1;
+    } else if (button==MOD_NUM_KEYPAD+'6' && (h-n) % 2 == 0) {
+        x = w-n;
+        y = (h-n) / 2;
+        dir = +1;
+    } else if (button==MOD_NUM_KEYPAD+'5' && (w-n) % 2 == 0 && (h-n) % 2 == 0){
+        x = (w-n) / 2;
+        y = (h-n) / 2;
+        dir = +1;
+    } else {
+        return NULL;                   /* no move to be made */
+    }
 
-	/*
-	 * This is a valid move. Make it.
-	 */
-	ret = dup_game(from);
-	ret->just_used_solve = FALSE;  /* zero this in a hurry */
-	ret->movecount++;
-	dir = (button == LEFT_BUTTON ? 1 : -1);
-	do_rotate(ret->grid, w, h, n, ret->orientable, x, y, dir);
-	ret->lastx = x;
-	ret->lasty = y;
-	ret->lastr = dir;
+    /*
+     * This is a valid move. Make it.
+     */
+    ret = dup_game(from);
+    ret->just_used_solve = FALSE;  /* zero this in a hurry */
+    ret->movecount++;
+    do_rotate(ret->grid, w, h, n, ret->orientable, x, y, dir);
+    ret->lastx = x;
+    ret->lasty = y;
+    ret->lastr = dir;
 
-	/*
-	 * See if the game has been completed. To do this we simply
-	 * test that the grid contents are in increasing order.
-	 */
-	if (!ret->completed && grid_complete(ret->grid, wh, ret->orientable))
-	    ret->completed = ret->movecount;
-	return ret;
-    }
-    return NULL;
+    /*
+     * See if the game has been completed. To do this we simply
+     * test that the grid contents are in increasing order.
+     */
+    if (!ret->completed && grid_complete(ret->grid, wh, ret->orientable))
+        ret->completed = ret->movecount;
+    return ret;
 }
 
 /* ----------------------------------------------------------------------