From 3eb63c49ac046dd8b2b7d585ac270d17f950cfac Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Wed, 17 Jul 2024 23:43:41 +0200 Subject: [PATCH] queen fully fonctional --- checkers.c | 9 +++++++-- function.h | 6 ++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/checkers.c b/checkers.c index 7ce4e04..8035160 100644 --- a/checkers.c +++ b/checkers.c @@ -87,6 +87,7 @@ int petturn (board_t **board, cache_t *cache, int *xcursor, int *ycursor, int ju int queenturn (board_t **board, cache_t *cache, int *xcursor, int *ycursor, int queen, int direction) { + int delta; int player = getid (*board, *xcursor, *ycursor); if (isqueen (*board, *xcursor, *ycursor, player, 0, -1)) { @@ -97,10 +98,10 @@ int queenturn (board_t **board, cache_t *cache, int *xcursor, int *ycursor, int if (queen == -1) { queen = direction; } - } else if (testqueenjump (*board, *xcursor, *ycursor, direction)) { + } else if ((delta = testqueenjump (*board, *xcursor, *ycursor, direction)) != 0) { pushcache (cache, *board, *xcursor, *ycursor, queen); *board = copyboard (*board); - dopetjump (*board, xcursor, ycursor, direction); + doqueenjump (*board, xcursor, ycursor, delta - 1, direction); queen = 4 + direction; } } @@ -479,5 +480,9 @@ int main (int argc, char *argv[]) /* test: { echo jiclv; sleep 1; echo llciv; sleep 1; echo q; } | checkers.exe -f tests/queens.chk -s 1 2>_ && grep -q 0xeee384a8 _ */ /* test: { echo jiclv; sleep 1; echo llciv; sleep 1; echo q; } | checkers.exe -f tests/queens.chk -s 2 2>_ && grep -q 0xeee384a8 _ */ /* test: { echo jiclv; sleep 1; echo llciv; sleep 1; echo q; } | checkers.exe -f tests/queens.chk -s 3 2>_ && grep -q 0xeee384a8 _ */ +/* test: { echo -n iilc; sleep 1; echo iijjklv; sleep 1; echo q; } | checkers.exe -f tests/queens2.chk 2>_ && grep -q 0x0bd368fa _ */ +/* test: { echo -n iilc; sleep 1; echo jjiilkv; sleep 1; echo -n kkc; sleep 1; echo kliijv; sleep 1; echo q; } | checkers.exe -f tests/queens2.chk 2>_ && grep -q 0xede48902 _ */ +/* test: { echo -n llic; sleep 1; echo jxixlxkxkkkv; sleep 1; echo q; } | checkers.exe -f tests/queens3.chk 2>_ && grep -q 0xb5a71bd2 _ */ +/* test: { echo -n lilillc; sleep 1; echo kjv; sleep 1; echo q; } | checkers.exe -f tests/queens3.chk 2>_ && grep -q 0xcf8873bf _ */ /* vim: set ts=4 sw=4 et: */ diff --git a/function.h b/function.h index 5e43781..082ad28 100644 --- a/function.h +++ b/function.h @@ -45,6 +45,8 @@ int getid (board_t *board, int x, int y); void domove (board_t *board, int *x, int *y, int mode); +void doqueenjump (board_t *board, int *x, int *y, int delta, int mode); + void dopetjump (board_t *board, int *x, int *y, int mode); void dopetmove (board_t *board, int *x, int *y, int mode); @@ -71,10 +73,6 @@ int testqueenmove (board_t *board, int xcursor, int ycursor, int queen, int mode int testqueenjump (board_t *board, int xcursor, int ycursor, int mode); -int testqueenturn (board_t *board, int xcursor, int ycursor, int id, int queen, int mode); - -void doqueenturn (board_t *board, int *xcursor, int *ycursor, int *queen, int mode); - cache_t *initcache (board_t *board); board_t *pushcache (cache_t *cache, board_t *board, int xcursor, int ycursor, int opt); -- 2.30.2