From: Laurent Mazet Date: Thu, 19 Sep 2024 06:11:42 +0000 (+0200) Subject: put disk X-Git-Tag: v1.0~12 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=37f88db18c998c57427143e6cb40af6650c8eb76;p=reversi.git put disk --- 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;