emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/mines 4bbe9a4 14/43: * mines.el (mines-dig): Fix update


From: Stefan Monnier
Subject: [elpa] externals/mines 4bbe9a4 14/43: * mines.el (mines-dig): Fix update of board when touch a bomb at first trial
Date: Mon, 30 Nov 2020 18:44:14 -0500 (EST)

branch: externals/mines
commit 4bbe9a471d343b33f528335c2b9bb202557beb46
Author: Tino Calancha <tino.calancha@gmail.com>
Commit: Tino Calancha <tino.calancha@gmail.com>

    * mines.el (mines-dig): Fix update of board when touch a bomb at first trial
---
 mines.el | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/mines.el b/mines.el
index 8ceddd2..7f55e50 100644
--- a/mines.el
+++ b/mines.el
@@ -476,7 +476,19 @@ If called again then unflag it."
                                 (let ((ok-pos (cl-position-if-not (lambda (x) 
(eq t x)) mines-grid)))
                                   (message "Avoided game over in the first 
move")
                                   (setq elt (aref mines-grid ok-pos))
-                                  (cl-rotatef (aref mines-grid idx) (aref 
mines-grid ok-pos))))
+                                  ;; Update mine positions.
+                                  (setf (nth (cl-position idx 
mines-mine-positions)
+                                             mines-mine-positions) ok-pos)
+                                  ;; We must update `mines-grid' further: the 
neighbour cells
+                                  ;; to IDX must show now a lower number of 
near bombs; the
+                                  ;; cells near the new position of the bomb 
must increase their
+                                  ;; numbers.
+                                  (setq mines-grid (make-vector 
mines-number-cells nil))
+                                  ;; Add the mine positions.
+                                  (dolist (pos mines-mine-positions)
+                                    (aset mines-grid pos t))
+                                  ;; Update the numbers on neighbour cells.
+                                  (mines-set-numbers)))
                               ;; If the cell is flagged ask for confirmation.
                               (if (and (not show-mines) (eq (following-char) 
mines-flagged-cell-char))
                                   (if (yes-or-no-p "This cell is flagged as 
having a bomb.  Uncover it? ")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]