not fully fonctional
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Tue, 16 Jul 2024 17:05:48 +0000 (19:05 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Tue, 16 Jul 2024 17:05:48 +0000 (19:05 +0200)
checkers.c
display.c
function.c
function.h
type.h

index 9c8fc07d755785f84a130a40b133da24d71de701..7fcccbc9e2af3970104f7912b1fde37d0ac462ce 100644 (file)
@@ -64,7 +64,7 @@ int petturn (board_t **board, cache_t *cache, int *xcursor, int *ycursor, int ju
     int mode = 1;
     if (ispet (*board, *xcursor, *ycursor, player, 0, -1)) {
         if ((jump) && (testjump (*board, *xcursor, *ycursor, direction))) {
-            pushcache (cache, *board, *xcursor, *ycursor);
+            pushcache (cache, *board, *xcursor, *ycursor, -1);
             *board = copyboard (*board);
             dopetjump (*board, xcursor, ycursor, direction);
             if (!testalljumps (*board, *xcursor, *ycursor)) {
@@ -74,7 +74,7 @@ int petturn (board_t **board, cache_t *cache, int *xcursor, int *ycursor, int ju
             int petmove = (((player == 0) && ((direction == 2) || (direction == 3))) ||
                            ((player == 1) && ((direction == 0) || (direction == 1))));
             if (petmove && isempty (*board, *xcursor, *ycursor, 1, direction)) {
-                pushcache (cache, *board, *xcursor, *ycursor);
+                pushcache (cache, *board, *xcursor, *ycursor, -1);
                 *board = copyboard (*board);
                 dopetmove (*board, xcursor, ycursor, direction);
                 mode = 2;
@@ -91,15 +91,15 @@ int queenturn (board_t **board, cache_t *cache, int *xcursor, int *ycursor, int
 
     if (isqueen (*board, *xcursor, *ycursor, player, 0, -1)) {
         if (testqueenmove (*board, *xcursor, *ycursor, queen, direction)) {
-            pushcache (cache, *board, *xcursor, *ycursor);
+            pushcache (cache, *board, *xcursor, *ycursor, queen);
             *board = copyboard (*board);
             dopetmove (*board, xcursor, ycursor, direction);
             queen = direction;
         } else if (testqueenjump (*board, *xcursor, *ycursor, direction)) {
-            pushcache (cache, *board, *xcursor, *ycursor);
+            pushcache (cache, *board, *xcursor, *ycursor, queen);
             *board = copyboard (*board);
             dopetjump (*board, xcursor, ycursor, direction);
-            queen = -1;
+            queen = 4 + direction;
         }
     }
 
@@ -412,7 +412,7 @@ int main (int argc, char *argv[])
         case '\b':
         case 'x':
             if (cache->board) {
-                board = popcache (cache, &xcursor, &ycursor);
+                board = popcache (cache, &xcursor, &ycursor, &queen);
                 mode = 1;
             }
             break;
index bff4120293f2ed1cc4502a41f3eec21c6ff1a784..dd004a202bcb59a49ad8ca2a663cfd3fdbb3708b 100644 (file)
--- a/display.c
+++ b/display.c
@@ -380,6 +380,7 @@ int cursorwindow (board_t *board, int x, int y, int queen, int mode)
         break;
     }
     if (mode) {
+        int d;
         switch (id) {
         case '0':
         case '1':
@@ -422,25 +423,101 @@ int cursorwindow (board_t *board, int x, int y, int queen, int mode)
             break;
         case '6':
         case '7':
-            if (((queen ==-1) || (queen == 0)) && isempty (board, x, y, 1, 0)) {
-                _element (board, x + 1, y - 1, 'S');
-            } else if (testjump (board, x, y, 0)) {
-                _element (board, x + 2, y - 2, 'S');
-            }
-            if (((queen == -1) || (queen == 1)) && isempty (board, x, y, 1, 1)) {
-                _element (board, x - 1, y - 1, 'S');
-            } else if (testjump (board, x, y, 1)) {
-                _element (board, x - 2, y - 2, 'S');
-            }
-            if (((queen == -1) || (queen == 2)) && isempty (board, x, y, 1, 2)) {
-                _element (board, x - 1, y + 1, 'S');
-            } else if (testjump (board, x, y, 2)) {
-                _element (board, x - 2, y + 2, 'S');
-            }
-            if (((queen == -1) || (queen == 3)) && isempty (board, x, y, 1, 3)) {
-                _element (board, x + 1, y + 1, 'S');
-            } else if (testjump (board, x, y, 3)) {
-                _element (board, x + 2, y + 2, 'S');
+            switch (queen) {
+            case -1:
+                if (isempty (board, x, y, 1, 0)) {
+                    _element (board, x + 1, y - 1, 'S');
+                } else if (testjump (board, x, y, 0)) {
+                     _element (board, x + 2, y - 2, 'S');
+                }
+                if (isempty (board, x, y, 1, 1)) {
+                    _element (board, x - 1, y - 1, 'S');
+                } else if (testjump (board, x, y, 1)) {
+                     _element (board, x - 2, y - 2, 'S');
+                }
+                if (isempty (board, x, y, 1, 2)) {
+                    _element (board, x - 1, y + 1, 'S');
+                } else if (testjump (board, x, y, 2)) {
+                     _element (board, x - 2, y + 2, 'S');
+                }
+                if (isempty (board, x, y, 1, 3)) {
+                    _element (board, x + 1, y + 1, 'S');
+                } else if (testjump (board, x, y, 3)) {
+                     _element (board, x + 2, y + 2, 'S');
+                }
+                break;
+            case 0:
+                if (isempty (board, x, y, 1, 0)) {
+                    _element (board, x + 1, y - 1, 'S');
+                } else if (testjump (board, x, y, 0)) {
+                     _element (board, x + 2, y - 2, 'S');
+                }
+                break;
+            case 1:
+                if (isempty (board, x, y, 1, 1)) {
+                    _element (board, x - 1, y - 1, 'S');
+                } else if (testjump (board, x, y, 1)) {
+                     _element (board, x - 2, y - 2, 'S');
+                }
+                break;
+            case 2:
+                if (isempty (board, x, y, 1, 2)) {
+                    _element (board, x - 1, y + 1, 'S');
+                } else if (testjump (board, x, y, 2)) {
+                     _element (board, x - 2, y + 2, 'S');
+                }
+                break;
+            case 3:
+                if (isempty (board, x, y, 1, 3)) {
+                    _element (board, x + 1, y + 1, 'S');
+                } else if (testjump (board, x, y, 3)) {
+                    _element (board, x + 2, y + 2, 'S');
+                }
+                break;
+            case 4: /* 0 -> 1, 3*/
+                if (isempty (board, x, y, 1, 0)) {
+                    _element (board, x + 1, y - 1, 'S');
+                }
+                if ((d = testqueenjump (board, x, y, 1)) != 0) {
+                    _element (board, x - (1 + d), y - (1 + d), 'S');
+                }
+                if ((d = testqueenjump (board, x, y, 3)) != 0) {
+                    _element (board, x + (1 + d), y + (1 + d), 'S');
+                }
+                break;
+            case 5: /* 1 -> 0, 2*/
+                if (isempty (board, x, y, 1, 1)) {
+                    _element (board, x - 1, y - 1, 'S');
+                }
+                if ((d = testqueenjump (board, x, y, 0)) != 0) {
+                    _element (board, x + (1 + d), y - (1 + d), 'S');
+                }
+                if ((d = testqueenjump (board, x, y, 2)) != 0) {
+                    _element (board, x - (1 + d), y + (1 + d), 'S');
+                }
+                break;
+            case 6: /* 2 -> 1, 3 */
+                if (isempty (board, x, y, 1, 2)) {
+                    _element (board, x - 1, y + 1, 'S');
+                }
+                if ((d = testqueenjump (board, x, y, 1)) != 0) {
+                    _element (board, x - (1 + d), y - (1 + d), 'S');
+                }
+                if ((d = testqueenjump (board, x, y, 3)) != 0) {
+                    _element (board, x + (1 + d), y + (1 + d), 'S');
+                }
+                break;
+            case 7: /* 3 -> 0, 2*/
+                if (isempty (board, x, y, 1, 3)) {
+                    _element (board, x + 1, y + 1, 'S');
+                }
+                if ((d = testqueenjump (board, x, y, 0)) != 0) {
+                    _element (board, x + (1 + d), y - (1 + d), 'S');
+                }
+                if ((d = testqueenjump (board, x, y, 2)) != 0) {
+                    _element (board, x - (1 + d), y + (1 + d), 'S');
+                }
+                break;
             }
             break;
         }
index bac20911b1acb839c643404de6a5a4ba6c9f985b..a5418e5a0fa497700225e42067bde1ef5fdd9c1d 100644 (file)
@@ -506,7 +506,7 @@ int globalmaxjumps (board_t *board, int id)
 int testqueenmove (board_t *board, int xcursor, int ycursor, int queen, int mode)
 {
     int ret = 0;
-    if ((queen == mode) || (queen == -1)) {
+    if ((queen == 4 + mode) || (queen == mode) || (queen == -1)) {
         ret = isempty (board, xcursor, ycursor, 1, mode);
     }
     return ret;
@@ -557,7 +557,7 @@ cache_t *initcache (board_t *board)
     return cache;
 }
 
-board_t *pushcache (cache_t *cache, board_t *board, int xcursor, int ycursor)
+board_t *pushcache (cache_t *cache, board_t *board, int xcursor, int ycursor, int opt)
 {
     while (cache->board != NULL) {
         cache++;
@@ -565,10 +565,11 @@ board_t *pushcache (cache_t *cache, board_t *board, int xcursor, int ycursor)
     cache->board = board;
     cache->xcursor = xcursor;
     cache->ycursor = ycursor;
+    cache->opt = opt;
     return board;
 }
 
-board_t *popcache (cache_t *cache, int *xcursor, int *ycursor)
+board_t *popcache (cache_t *cache, int *xcursor, int *ycursor, int *opt)
 {
     board_t *board = NULL;
     if (cache->board != NULL) {
@@ -578,6 +579,7 @@ board_t *popcache (cache_t *cache, int *xcursor, int *ycursor)
         board = cache->board;
         *xcursor = cache->xcursor;
         *ycursor = cache->ycursor;
+        *opt = cache->opt;
         cache->board = NULL;
     }
     return board;
index e48e4c5fa43368184343f70026092d7d359a4259..5e43781e248182f10b8c66d864732b9c30c232cd 100644 (file)
@@ -77,9 +77,9 @@ void doqueenturn (board_t *board, int *xcursor, int *ycursor, int *queen, int mo
 
 cache_t *initcache (board_t *board);
 
-board_t *pushcache (cache_t *cache, board_t *board, int xcursor, int ycursor);
+board_t *pushcache (cache_t *cache, board_t *board, int xcursor, int ycursor, int opt);
 
-board_t *popcache (cache_t *cache, int *xcursor, int *ycursor);
+board_t *popcache (cache_t *cache, int *xcursor, int *ycursor, int *opt);
 
 void emptycache (cache_t *cache);
 
diff --git a/type.h b/type.h
index 5d1e386218faad8a4b04ba42d12db74d5a77081c..a62ebb580b1a4def22264f5b2b9f9661717d5c4e 100644 (file)
--- a/type.h
+++ b/type.h
@@ -17,6 +17,7 @@ typedef struct {
     board_t *board;
     int xcursor;
     int ycursor;
+    int opt;
 } cache_t;
 
 #endif /* __TYPE_H__ */