From 641e889e05a97b2f38b04cf0b3732b082305fad9 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Thu, 18 Jul 2024 00:06:50 +0200 Subject: [PATCH] queen fully fonctional (2) --- function.c | 64 +++++++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 42 deletions(-) diff --git a/function.c b/function.c index 2341428..96ed09e 100644 --- a/function.c +++ b/function.c @@ -277,41 +277,46 @@ void domove (board_t *board, int *x, int *y, int mode) } } -void dopetjump (board_t *board, int *x, int *y, int mode) +void doqueenjump (board_t *board, int *x, int *y, int delta, int mode) { char symb = getvalue (board, *x, *y); switch (mode) { case 0: *getcell (board, *x, *y) = '.'; - *getcell (board, *x + 1, *y - 1) = '/'; - *getcell (board, *x + 2, *y - 2) = symb; - *x += 2; - *y -= 2; + *getcell (board, *x + (1 + delta), *y - (1 + delta)) = '/'; + *getcell (board, *x + (2 + delta), *y - (2 + delta)) = symb; + *x += (2 + delta); + *y -= (2 + delta); break; case 1: *getcell (board, *x, *y) = '.'; - *getcell (board, *x - 1, *y - 1) = '/'; - *getcell (board, *x - 2, *y - 2) = symb; - *x -= 2; - *y -= 2; + *getcell (board, *x - (1 + delta), *y - (1 + delta)) = '/'; + *getcell (board, *x - (2 + delta), *y - (2 + delta)) = symb; + *x -= (2 + delta); + *y -= (2 + delta); break; case 2: *getcell (board, *x, *y) = '.'; - *getcell (board, *x - 1, *y + 1) = '/'; - *getcell (board, *x - 2, *y + 2) = symb; - *x -= 2; - *y += 2; + *getcell (board, *x - (1 + delta), *y + (1 + delta)) = '/'; + *getcell (board, *x - (2 + delta), *y + (2 + delta)) = symb; + *x -= (2 + delta); + *y += (2 + delta); break; case 3: *getcell (board, *x, *y) = '.'; - *getcell (board, *x + 1, *y + 1) = '/'; - *getcell (board, *x + 2, *y + 2) = symb; - *x += 2; - *y += 2; + *getcell (board, *x + (1 + delta), *y + (1 + delta)) = '/'; + *getcell (board, *x + (2 + delta), *y + (2 + delta)) = symb; + *x += (2 + delta); + *y += (2 + delta); break; } } +void dopetjump (board_t *board, int *x, int *y, int mode) +{ + doqueenjump (board, x, y, 0, mode); +} + void dopetmove (board_t *board, int *x, int *y, int mode) { char symb = getvalue (board, *x, *y); @@ -527,31 +532,6 @@ int testqueenjump (board_t *board, int xcursor, int ycursor, int mode) return (ret) ? delta + 1 : ret; } -int testqueenturn (board_t *board, int xcursor, int ycursor, int id, int queen, int mode) -{ - int ret = 0; - if (isqueen (board, xcursor, ycursor, id, 0, -1)) { - if ((queen == mode) || (queen == -1)) { - ret = testqueenmove (board, xcursor, ycursor, queen, mode); - ret = ret || testqueenjump (board, xcursor, ycursor, mode); - } else { - ret = testqueenjump (board, xcursor, ycursor, mode); - } - } - return ret; -} - -void doqueenturn (board_t *board, int *xcursor, int *ycursor, int *queen, int mode) -{ - if (testqueenmove (board, *xcursor, *ycursor, *queen, mode)) { - dopetmove (board, xcursor, ycursor, mode); - *queen = mode; - } else if (testqueenjump (board, *xcursor, *ycursor, mode)) { - dopetjump (board, xcursor, ycursor, mode); - *queen = -1; - } -} - cache_t *initcache (board_t *board) { cache_t *cache = (cache_t *) calloc (board->width / 2 * (board->height - 1) / 2, sizeof (cache_t)); -- 2.30.2