+
+ /*
+ * Find the two points in the current grid square which
+ * correspond to this move.
+ */
+ mask = from->grid->squares[from->current].directions[direction];
+ if (mask == 0)
+ return -1;
+ for (i = j = 0; i < from->grid->squares[from->current].npoints; i++)
+ if (mask & (1 << i)) {
+ points[j*2] = from->grid->squares[from->current].points[i*2];
+ points[j*2+1] = from->grid->squares[from->current].points[i*2+1];
+ skey[j] = i;
+ j++;
+ }
+ assert(j == 2);
+
+ /*
+ * Now find the other grid square which shares those points.
+ * This is our move destination.
+ */
+ dest = -1;
+ for (i = 0; i < from->grid->nsquares; i++)
+ if (i != from->current) {
+ int match = 0;
+ float dist;
+
+ for (j = 0; j < from->grid->squares[i].npoints; j++) {
+ dist = (SQ(from->grid->squares[i].points[j*2] - points[0]) +
+ SQ(from->grid->squares[i].points[j*2+1] - points[1]));
+ if (dist < 0.1)
+ dkey[match++] = j;
+ dist = (SQ(from->grid->squares[i].points[j*2] - points[2]) +
+ SQ(from->grid->squares[i].points[j*2+1] - points[3]));
+ if (dist < 0.1)
+ dkey[match++] = j;
+ }
+
+ if (match == 2) {
+ dest = i;
+ break;
+ }
+ }
+
+ return dest;
+}
+
+static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
+ int x, int y, int button)
+{
+ int direction, mask, i;
+ int skey[2], dkey[2];