From 5a394532d4f310acc61884ae2a9fcc524ee980f5 Mon Sep 17 00:00:00 2001 From: Laurent MAZET Date: Thu, 18 Jul 2024 18:16:00 +0200 Subject: [PATCH] remove best move evaluation (only avaliable for pet) --- checkers.c | 25 +++++++++++-------------- display.c | 3 +-- display.h | 2 +- function.c | 13 ------------- function.h | 2 -- 5 files changed, 13 insertions(+), 32 deletions(-) diff --git a/checkers.c b/checkers.c index 8035160..c5032b3 100644 --- a/checkers.c +++ b/checkers.c @@ -57,13 +57,13 @@ int usage (int ret) return ret; } -int petturn (board_t **board, cache_t *cache, int *xcursor, int *ycursor, int jump, int direction) +int petturn (board_t **board, cache_t *cache, int *xcursor, int *ycursor, int direction) { int player = getid (*board, *xcursor, *ycursor); int mode = 1; if (ispet (*board, *xcursor, *ycursor, player, 0, -1)) { - if ((jump) && (testjump (*board, *xcursor, *ycursor, direction))) { + if (testjump (*board, *xcursor, *ycursor, direction)) { pushcache (cache, *board, *xcursor, *ycursor, -1); *board = copyboard (*board); dopetjump (*board, xcursor, ycursor, direction); @@ -258,27 +258,24 @@ int main (int argc, char *argv[]) while (!stop) { char msg[128] = {0}; char *ptr = NULL; - int nbmaxjumps = 0; - int jump = 0; boardwindow (board); if (1) { /* not end of game */ sprintf (msg, "Player %s: ", (player == 0) ? "One": "Two"); switch (mode) { case 0: - jump = cursorwindow (board, xcursor, ycursor, queen, 0); - nbmaxjumps = globalmaxjumps (board, player); - sprintf (msg + strlen (msg), "Begin turn (%d)", nbmaxjumps); + cursorwindow (board, xcursor, ycursor, queen, 0); + sprintf (msg + strlen (msg), "Begin turn"); break; case 1: - jump = cursorwindow (board, xcursor, ycursor, queen, 1); - sprintf (msg + strlen (msg), "Choose next (%d)", nbmaxjumps); + cursorwindow (board, xcursor, ycursor, queen, 1); + sprintf (msg + strlen (msg), "Choose next"); break; case 2: sprintf (msg + strlen (msg), "Validate turn"); break; case 3: - jump = cursorwindow (board, xcursor, ycursor, queen, 1); + cursorwindow (board, xcursor, ycursor, queen, 1); sprintf (msg + strlen (msg), "Continue or validate turn"); break; } @@ -328,7 +325,7 @@ int main (int argc, char *argv[]) domove (board, &xcursor, &ycursor, 0); break; case 1: - mode = petturn (&board, cache, &xcursor, &ycursor, jump, 0); + mode = petturn (&board, cache, &xcursor, &ycursor, 0); break; case 3: queen = queenturn (&board, cache, &xcursor, &ycursor, queen, 0); @@ -342,7 +339,7 @@ int main (int argc, char *argv[]) domove (board, &xcursor, &ycursor, 1); break; case 1: - mode = petturn (&board, cache, &xcursor, &ycursor, jump, 1); + mode = petturn (&board, cache, &xcursor, &ycursor, 1); break; case 3: queen = queenturn (&board, cache, &xcursor, &ycursor, queen, 1); @@ -356,7 +353,7 @@ int main (int argc, char *argv[]) domove (board, &xcursor, &ycursor, 2); break; case 1: - mode = petturn (&board, cache, &xcursor, &ycursor, jump, 2); + mode = petturn (&board, cache, &xcursor, &ycursor, 2); break; case 3: queen = queenturn (&board, cache, &xcursor, &ycursor, queen, 2); @@ -370,7 +367,7 @@ int main (int argc, char *argv[]) domove (board, &xcursor, &ycursor, 3); break; case 1: - mode = petturn (&board, cache, &xcursor, &ycursor, jump, 3); + mode = petturn (&board, cache, &xcursor, &ycursor, 3); break; case 3: queen = queenturn (&board, cache, &xcursor, &ycursor, queen, 3); diff --git a/display.c b/display.c index 8a28544..5150caa 100644 --- a/display.c +++ b/display.c @@ -357,7 +357,7 @@ void boardwindow (board_t *board) } } -int cursorwindow (board_t *board, int x, int y, int queen, int mode) +void cursorwindow (board_t *board, int x, int y, int queen, int mode) { int jump = 0; char id = getvalue (board, x, y); @@ -522,7 +522,6 @@ int cursorwindow (board_t *board, int x, int y, int queen, int mode) break; } } - return jump; } char *savewindow (int length, int xoffset, int yoffset) diff --git a/display.h b/display.h index a298325..52c3c25 100644 --- a/display.h +++ b/display.h @@ -10,7 +10,7 @@ int helpwindow (char *msg, int xoffset, int yoffset); void boardwindow (board_t *board); -int cursorwindow (board_t *board, int x, int y, int queen, int mode); +void cursorwindow (board_t *board, int x, int y, int queen, int mode); char *savewindow (int length, int xoffset, int yoffset); diff --git a/function.c b/function.c index 96ed09e..429a036 100644 --- a/function.c +++ b/function.c @@ -497,19 +497,6 @@ int evalmaxjumps (board_t *board, int x, int y, int id) return maxjumps; } -int globalmaxjumps (board_t *board, int id) -{ - int i, j; - int maxjumps = 0; - for (i = 0; i < board->width; i++) { - for (j = 0; j < board->height; j++) { - int nb = evalmaxjumps (board, i, j, id); - maxjumps = max (nb, maxjumps); - } - } - return maxjumps; -} - int testqueenmove (board_t *board, int xcursor, int ycursor, int queen, int mode) { int ret = 0; diff --git a/function.h b/function.h index 082ad28..5d7f40b 100644 --- a/function.h +++ b/function.h @@ -67,8 +67,6 @@ int testalljumps (board_t *board, int x, int y); int evalmaxjumps (board_t *board, int x, int y, int id); -int globalmaxjumps (board_t *board, int id); - int testqueenmove (board_t *board, int xcursor, int ycursor, int queen, int mode); int testqueenjump (board_t *board, int xcursor, int ycursor, int mode); -- 2.30.2