put disk
authorLaurent Mazet <mazet@softndesign.org>
Thu, 19 Sep 2024 06:11:42 +0000 (08:11 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Thu, 19 Sep 2024 06:11:42 +0000 (08:11 +0200)
function.c

index c6c3448e04f053bdc44d6f9f9c280aeb3cf58162..63c6fcf150dd9f4391a19ed64ca8f2c19d065c5c 100644 (file)
@@ -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;