From c41c378761224d0abb75837b7b76d03497b6b204 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Fri, 12 Jul 2024 07:50:21 +0200 Subject: [PATCH] cleaning --- checkers.c | 8 ++++---- function.c | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/checkers.c b/checkers.c index da3a8d6..42b4cf2 100644 --- a/checkers.c +++ b/checkers.c @@ -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); diff --git a/function.c b/function.c index 6b6d70f..d2fd22a 100644 --- a/function.c +++ b/function.c @@ -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; } -- 2.30.2