Created
September 16, 2020 12:58
-
-
Save FeepingCreature/c9933dba1bc539b6bb1854004eb37db4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 4f2c0ddcb3f402a4ec7dcb57dfec78c2719e4004 Mon Sep 17 00:00:00 2001 | |
From: FeepingCreature <[email protected]> | |
Date: Fri, 4 Sep 2020 14:33:17 +0000 | |
Subject: [PATCH] Mines: add mass-flag shortcut. | |
Right-click on a tiles where the count of covered adjacent tiles | |
matches the number of the tile - so that they are obviously all | |
bombs - and all covered adjacent tiles are flagged. | |
This provides symmetry with the left-click mass-reveal option. | |
--- | |
mines.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
1 file changed, 52 insertions(+) | |
diff --git a/mines.c b/mines.c | |
index ee2d5bb..83191df 100644 | |
--- a/mines.c | |
+++ b/mines.c | |
@@ -2443,6 +2443,10 @@ static char *interpret_move(const game_state *from, game_ui *ui, | |
return UI_UPDATE; | |
} | |
if (button == CURSOR_SELECT2) { | |
+ | |
+ if (v >= 0) | |
+ goto massflag; | |
+ | |
/* As for RIGHT_BUTTON; only works on covered square. */ | |
if (v != -2 && v != -1) | |
return NULL; | |
@@ -2487,6 +2491,9 @@ static char *interpret_move(const game_state *from, game_ui *ui, | |
if (cx < 0 || cx >= from->w || cy < 0 || cy >= from->h) | |
return NULL; | |
+ if (from->grid[cy * from->w + cx] >= 0) | |
+ goto massflag; | |
+ | |
/* | |
* Right-clicking only works on a covered square, and it | |
* toggles between -1 (marked as mine) and -2 (not marked | |
@@ -2533,6 +2540,51 @@ static char *interpret_move(const game_state *from, game_ui *ui, | |
} | |
return NULL; | |
+massflag: | |
+ { | |
+ /* | |
+ * Right-clicking on an uncovered tile: | |
+ * we check if the number of unrevealed tiles surrounding | |
+ * the tile is equal to its mine count, and if so then | |
+ * we mark all unrevealed tiles as mines. | |
+ */ | |
+ if (from->grid[cy * from->w + cx] > 0) { | |
+ int dy, dx, n; | |
+ | |
+ /* Count hidden fields */ | |
+ n = 0; | |
+ for (dy = -1; dy <= +1; dy++) | |
+ for (dx = -1; dx <= +1; dx++) | |
+ if (cx+dx >= 0 && cx+dx < from->w && | |
+ cy+dy >= 0 && cy+dy < from->h) { | |
+ int gridval = from->grid[(cy+dy)*from->w+(cx+dx)]; | |
+ | |
+ if (gridval == -1 || gridval == -2) | |
+ n++; | |
+ } | |
+ | |
+ if (n == from->grid[cy * from->w + cx]) { | |
+ char *p = buf; | |
+ const char *sep = ""; | |
+ /* | |
+ * Toggle all unrevealed unflagged tiles surrounding us to flagged. | |
+ */ | |
+ for (dy = -1; dy <= +1; dy++) | |
+ for (dx = -1; dx <= +1; dx++) | |
+ if (cx+dx >= 0 && cx+dx < from->w && | |
+ cy+dy >= 0 && cy+dy < from->h) { | |
+ if (from->grid[(cy+dy)*from->w+(cx+dx)] == -2) { | |
+ p += sprintf(p, "%sF%d,%d", sep, cx+dx, cy+dy); | |
+ sep = ";"; | |
+ } | |
+ } | |
+ if (p > buf) | |
+ return dupstr(buf); | |
+ } | |
+ } | |
+ } | |
+ return NULL; | |
+ | |
uncover: | |
{ | |
/* | |
-- | |
2.25.4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment