cleaning
authorLaurent Mazet <mazet@softndesign.org>
Fri, 12 Jul 2024 05:50:21 +0000 (07:50 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Fri, 12 Jul 2024 05:50:21 +0000 (07:50 +0200)
checkers.c
function.c

index da3a8d63ab2a766fe0674d2ca79f2ab70f9689a0..42b4cf2a4cc315fefb326af009a14b9af0db80d9 100644 (file)
@@ -279,7 +279,7 @@ int main (int argc, char *argv[])
                     if (!testalljumps (board, xcursor, ycursor)) {
                         mode = 2;
                     }
-                } else if ((player == 1) && (!jump) && (getvalue (board, xcursor + 1, ycursor - 1) == '.')) {
+                } else if ((player == 1) && (!jump) && (isempty (board, xcursor, ycursor, 1, 0))) {
                     pushcache (cache, board, xcursor, ycursor);
                     board = copyboard (board);
                     dopetmove (board, &xcursor, &ycursor, 0);
@@ -306,7 +306,7 @@ int main (int argc, char *argv[])
                     if (!testalljumps (board, xcursor, ycursor)) {
                         mode = 2;
                     }
-                } else if ((player == 1) && (!jump) && (getvalue (board, xcursor - 1, ycursor - 1) == '.')) {
+                } else if ((player == 1) && (!jump) && (isempty (board, xcursor, ycursor, 1, 1))) {
                     pushcache (cache, board, xcursor, ycursor);
                     board = copyboard (board);
                     dopetmove (board, &xcursor, &ycursor, 1);
@@ -333,7 +333,7 @@ int main (int argc, char *argv[])
                     if (!testalljumps (board, xcursor, ycursor)) {
                         mode = 2;
                     }
-                } else if ((player == 0) && (!jump) && (getvalue (board, xcursor - 1, ycursor + 1) == '.')) {
+                } else if ((player == 0) && (!jump) && (isempty (board, xcursor, ycursor, 1, 2))) {
                     pushcache (cache, board, xcursor, ycursor);
                     board = copyboard (board);
                     dopetmove (board, &xcursor, &ycursor, 2);
@@ -360,7 +360,7 @@ int main (int argc, char *argv[])
                     if (!testalljumps (board, xcursor, ycursor)) {
                         mode = 2;
                     }
-                } else if ((player == 0) && (!jump) && (getvalue (board, xcursor + 1, ycursor + 1) == '.')) {
+                } else if ((player == 0) && (!jump) && (isempty (board, xcursor, ycursor, 1, 3))) {
                     pushcache (cache, board, xcursor, ycursor);
                     board = copyboard (board);
                     dopetmove (board, &xcursor, &ycursor, 3);
index 6b6d70fd0d3fed7d63b0c004153245f670409a34..d2fd22a4796f0180441ede071b77d5923de2df90 100644 (file)
@@ -386,7 +386,7 @@ int ispet (board_t *board, int xcursor, int ycursor, int id, int delta, int mode
     return (id == -1) ?
         (_testcell (board, xcursor, ycursor, '0', delta, mode) &&
         _testcell (board, xcursor, ycursor, '1', delta, mode)) :
-        _testcell (board, xcursor, ycursor, '0' + id, delta, mode);
+        _testcell (board, xcursor, ycursor, (id == 0) ? '0' : '1', delta, mode);
 }
 
 int isqueen (board_t *board, int xcursor, int ycursor, int id, int delta, int mode)
@@ -415,7 +415,7 @@ int _testjump (board_t *board, int x, int y, int delta, int mode)
         break;
     }
     if (ret) {
-        int id = getvalue (board, x, y) - '0';
+        int id = (getvalue (board, x, y) == '0') ? 0 : 1;
         ret = ispet (board, x, y, 1 - id, 1 + delta, mode) && isempty (board, x, y, 2 + delta, mode);
     }
     return ret;
@@ -442,7 +442,7 @@ int testalljumps (board_t *board, int x, int y)
 int evalmaxjumps (board_t *board, int x, int y, int id)
 {
     int maxjumps = 0;
-    if (getvalue (board, x, y) != '0' + id) {
+    if (getvalue (board, x, y) != ((id == 0) ? '1' : '0')) {
         return 0;
     }