From bf8490cfa99fbd41ed366bc0f82259d23199e9c5 Mon Sep 17 00:00:00 2001 From: Laurent MAZET Date: Tue, 16 Jul 2024 19:05:48 +0200 Subject: [PATCH] not fully fonctional --- checkers.c | 12 +++--- display.c | 115 ++++++++++++++++++++++++++++++++++++++++++++--------- function.c | 8 ++-- function.h | 4 +- type.h | 1 + 5 files changed, 110 insertions(+), 30 deletions(-) diff --git a/checkers.c b/checkers.c index 9c8fc07..7fcccbc 100644 --- a/checkers.c +++ b/checkers.c @@ -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; diff --git a/display.c b/display.c index bff4120..dd004a2 100644 --- 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; } diff --git a/function.c b/function.c index bac2091..a5418e5 100644 --- a/function.c +++ b/function.c @@ -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; diff --git a/function.h b/function.h index e48e4c5..5e43781 100644 --- a/function.h +++ b/function.h @@ -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 5d1e386..a62ebb5 100644 --- 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__ */ -- 2.30.2