queen fully fonctional (2)
authorLaurent Mazet <mazet@softndesign.org>
Wed, 17 Jul 2024 22:06:50 +0000 (00:06 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Wed, 17 Jul 2024 22:06:50 +0000 (00:06 +0200)
function.c

index 2341428f1d3274770470efb64bd6d0022f6d8087..96ed09eac9af39afefc44cdebac93ac3d56247bc 100644 (file)
@@ -277,41 +277,46 @@ void domove (board_t *board, int *x, int *y, int mode)
     }
 }
 
-void dopetjump (board_t *board, int *x, int *y, int mode)
+void doqueenjump (board_t *board, int *x, int *y, int delta, int mode)
 {
     char symb = getvalue (board, *x, *y);
     switch (mode) {
     case 0:
         *getcell (board, *x, *y) = '.';
-        *getcell (board, *x + 1, *y - 1) = '/';
-        *getcell (board, *x + 2, *y - 2) = symb;
-        *x += 2;
-        *y -= 2;
+        *getcell (board, *x + (1 + delta), *y - (1 + delta)) = '/';
+        *getcell (board, *x + (2 + delta), *y - (2 + delta)) = symb;
+        *x += (2 + delta);
+        *y -= (2 + delta);
         break;
     case 1:
         *getcell (board, *x, *y) = '.';
-        *getcell (board, *x - 1, *y - 1) = '/';
-        *getcell (board, *x - 2, *y - 2) = symb;
-        *x -= 2;
-        *y -= 2;
+        *getcell (board, *x - (1 + delta), *y - (1 + delta)) = '/';
+        *getcell (board, *x - (2 + delta), *y - (2 + delta)) = symb;
+        *x -= (2 + delta);
+        *y -= (2 + delta);
         break;
     case 2:
         *getcell (board, *x, *y) = '.';
-        *getcell (board, *x - 1, *y + 1) = '/';
-        *getcell (board, *x - 2, *y + 2) = symb;
-        *x -= 2;
-        *y += 2;
+        *getcell (board, *x - (1 + delta), *y + (1 + delta)) = '/';
+        *getcell (board, *x - (2 + delta), *y + (2 + delta)) = symb;
+        *x -= (2 + delta);
+        *y += (2 + delta);
         break;
     case 3:
         *getcell (board, *x, *y) = '.';
-        *getcell (board, *x + 1, *y + 1) = '/';
-        *getcell (board, *x + 2, *y + 2) = symb;
-        *x += 2;
-        *y += 2;
+        *getcell (board, *x + (1 + delta), *y + (1 + delta)) = '/';
+        *getcell (board, *x + (2 + delta), *y + (2 + delta)) = symb;
+        *x += (2 + delta);
+        *y += (2 + delta);
         break;
     }
 }
 
+void dopetjump (board_t *board, int *x, int *y, int mode)
+{
+    doqueenjump (board, x, y, 0, mode);
+}
+
 void dopetmove (board_t *board, int *x, int *y, int mode)
 {
     char symb = getvalue (board, *x, *y);
@@ -527,31 +532,6 @@ int testqueenjump (board_t *board, int xcursor, int ycursor, int mode)
     return (ret) ? delta + 1 : ret;
 }
 
-int testqueenturn (board_t *board, int xcursor, int ycursor, int id, int queen, int mode)
-{
-    int ret = 0;
-    if (isqueen (board, xcursor, ycursor, id, 0, -1)) {
-        if ((queen == mode) || (queen == -1)) {
-            ret = testqueenmove (board, xcursor, ycursor, queen, mode);
-            ret = ret || testqueenjump (board, xcursor, ycursor, mode);
-        } else {
-            ret = testqueenjump (board, xcursor, ycursor, mode);
-        }
-    }
-    return ret;
-}
-
-void doqueenturn (board_t *board, int *xcursor, int *ycursor, int *queen, int mode)
-{
-    if (testqueenmove (board, *xcursor, *ycursor, *queen, mode)) {
-        dopetmove (board, xcursor, ycursor, mode);
-        *queen = mode;
-    } else if (testqueenjump (board, *xcursor, *ycursor, mode)) {
-        dopetjump (board, xcursor, ycursor, mode);
-        *queen = -1;
-    }
-}
-
 cache_t *initcache (board_t *board)
 {
     cache_t *cache = (cache_t *) calloc (board->width / 2 * (board->height - 1) / 2, sizeof (cache_t));