queen fully fonctional
authorLaurent Mazet <mazet@softndesign.org>
Wed, 17 Jul 2024 21:43:41 +0000 (23:43 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Wed, 17 Jul 2024 21:43:41 +0000 (23:43 +0200)
checkers.c
function.h

index 7ce4e04a1162bb24a9ff6ee83d6e52fc38180599..8035160ad4d1c8635f301ccf3bcc50872a6bec58 100644 (file)
@@ -87,6 +87,7 @@ int petturn (board_t **board, cache_t *cache, int *xcursor, int *ycursor, int ju
 
 int queenturn (board_t **board, cache_t *cache, int *xcursor, int *ycursor, int queen, int direction)
 {
+    int delta;
     int player = getid (*board, *xcursor, *ycursor);
 
     if (isqueen (*board, *xcursor, *ycursor, player, 0, -1)) {
@@ -97,10 +98,10 @@ int queenturn (board_t **board, cache_t *cache, int *xcursor, int *ycursor, int
             if (queen == -1) {
                 queen = direction;
             }
-        } else if (testqueenjump (*board, *xcursor, *ycursor, direction)) {
+        } else if ((delta = testqueenjump (*board, *xcursor, *ycursor, direction)) != 0) {
             pushcache (cache, *board, *xcursor, *ycursor, queen);
             *board = copyboard (*board);
-            dopetjump (*board, xcursor, ycursor, direction);
+            doqueenjump (*board, xcursor, ycursor, delta - 1, direction);
             queen = 4 + direction;
         }
     }
@@ -479,5 +480,9 @@ int main (int argc, char *argv[])
 /* test: { echo jiclv; sleep 1; echo llciv; sleep 1; echo q; } | checkers.exe -f tests/queens.chk -s 1 2>_ && grep -q 0xeee384a8 _ */
 /* test: { echo jiclv; sleep 1; echo llciv; sleep 1; echo q; } | checkers.exe -f tests/queens.chk -s 2 2>_ && grep -q 0xeee384a8 _ */
 /* test: { echo jiclv; sleep 1; echo llciv; sleep 1; echo q; } | checkers.exe -f tests/queens.chk -s 3 2>_ && grep -q 0xeee384a8 _ */
+/* test: { echo -n iilc; sleep 1; echo iijjklv; sleep 1; echo q; } | checkers.exe -f tests/queens2.chk 2>_ && grep -q 0x0bd368fa _ */
+/* test: { echo -n iilc; sleep 1; echo jjiilkv; sleep 1; echo -n kkc; sleep 1; echo kliijv; sleep 1; echo q; } | checkers.exe -f tests/queens2.chk 2>_ && grep -q 0xede48902 _ */
+/* test: { echo -n llic; sleep 1; echo jxixlxkxkkkv; sleep 1; echo q; } | checkers.exe -f tests/queens3.chk 2>_ && grep -q 0xb5a71bd2 _ */
+/* test: { echo -n lilillc; sleep 1; echo kjv; sleep 1; echo q; } | checkers.exe -f tests/queens3.chk 2>_ && grep -q 0xcf8873bf _ */
 
 /* vim: set ts=4 sw=4 et: */
index 5e43781e248182f10b8c66d864732b9c30c232cd..082ad28a0f7a4990a0367dbd1e1f6b8c3aab7dbb 100644 (file)
@@ -45,6 +45,8 @@ int getid (board_t *board, int x, int y);
 
 void domove (board_t *board, int *x, int *y, int mode);
 
+void doqueenjump (board_t *board, int *x, int *y, int delta, int mode);
+
 void dopetjump (board_t *board, int *x, int *y, int mode);
 
 void dopetmove (board_t *board, int *x, int *y, int mode);
@@ -71,10 +73,6 @@ int testqueenmove (board_t *board, int xcursor, int ycursor, int queen, int mode
 
 int testqueenjump (board_t *board, int xcursor, int ycursor, int mode);
 
-int testqueenturn (board_t *board, int xcursor, int ycursor, int id, int queen, int mode);
-
-void doqueenturn (board_t *board, int *xcursor, int *ycursor, int *queen, int mode);
-
 cache_t *initcache (board_t *board);
 
 board_t *pushcache (cache_t *cache, board_t *board, int xcursor, int ycursor, int opt);