From 37f88db18c998c57427143e6cb40af6650c8eb76 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Thu, 19 Sep 2024 08:11:42 +0200 Subject: [PATCH] put disk --- function.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/function.c b/function.c index c6c3448..63c6fcf 100644 --- a/function.c +++ b/function.c @@ -242,13 +242,37 @@ int _checklines (board_t *board, int x, int y, int id) int dy = _evaldir (dir, 1); int n = 1; + int line = 0; + VERBOSE (DEBUG, printf ("dx: %d dy: %d ", dx, dy)); while ((x + n * dx >= 0) && (x + n * dx < board->width) && - (y + n * dy >= 0) && (y + n * dy < board->height) && - (*getcell (board, x + n * dx, y + n * dy) == '0' + (id ? 0 : 1))) { - n++; - *getcell (board, x + n * dx, y + n * dy) = '0' + id; + (y + n * dy >= 0) && (y + n * dy < board->height)) { + char *cell = getcell (board, x + n * dx, y + n * dy); + VERBOSE (DEBUG, printf ("cell: 0x%02x (%c) ", *cell, *cell)); + if (*cell == (id ? '0' : '1')) { + n++; + } else if (*cell == '0' + id) { + line = n - 1; + break; + } else { + break; + } + } + if (line) { + VERBOSE (DEBUG, printf ("n: %d", n)); + n = 1; + while ((x + n * dx >= 0) && (x + n * dx < board->width) && + (y + n * dy >= 0) && (y + n * dy < board->height)) { + char *cell = getcell (board, x + n * dx, y + n * dy); + if (*cell == (id ? '0' : '1')) { + n++; + *cell = '0' + id; + } else { + break; + } + } ret = 1; } + VERBOSE (DEBUG, printf ("\n")); } return ret; -- 2.30.2