Commits

zck committed 7ecfbea

add minesweeper-is-mine, start using it.

Comments (0)

Files changed (1)

 	('t
 	 ?-)))
 
+(defun minesweeper-is-mine (row col)
+  "Returns 't iff (row, col) is a mine."
+  (eq (minesweeper-view-mine row col 't)
+      ?X))
+
 (defun minesweeper-set-mine (row col val)
   "Inserts val into the mine at (col, row)"
   (puthash (list row col)
       (minesweeper-fill-field row col)
       (setq *minesweeper-first-move* nil))
     (minesweeper-debug "in pick, done with first-move check. Getting the value of the square.")
-    (let ((val (minesweeper-view-mine row col 't)))
-      (minesweeper-debug "view-mine called. The value at " (number-to-string col) ", " (number-to-string row) " is " (make-string 1 val))
-      (if (eq val ?X)
-	  (progn (minesweeper-lose-game row col)
-		 (throw 'game-end nil))
-	(let ((to-reveal (list (list row col))))
-	  (minesweeper-debug "The user didn't pick an X")
-	  (while to-reveal
-            (multiple-value-bind (cur-row cur-col) (pop to-reveal)
-	      (minesweeper-debug "View-mine says " (number-to-string cur-col) ", " (number-to-string cur-row) " mine = " (make-string 1 (minesweeper-view-mine cur-row cur-col 't)))
-	      (unless (or (minesweeper-is-revealed cur-row cur-col)
-			  (minesweeper-marked cur-row cur-col))
-		(minesweeper-debug "it's not revealed, so reveal it")
-		(minesweeper-reveal cur-row cur-col)
-		(if (eq (setq *minesweeper-blanks-left* (1- *minesweeper-blanks-left*))
-			0)
-		    (progn (minesweeper-win-game)
-			   (throw 'game-end nil))
-		  (when (eq (minesweeper-view-mine cur-row cur-col 't)
-			    ?0)
-		    (minesweeper-debug "pushing neighbors onto the stack")
-		    (mapc '(lambda (position)
-			     (push position
-				   to-reveal))
-			  (minesweeper-neighbors cur-row cur-col))))))))))))
+    (if (minesweeper-is-mine row col)
+        (progn (minesweeper-lose-game row col)
+               (throw 'game-end nil))
+      (let ((to-reveal (list (list row col))))
+        (minesweeper-debug "The user didn't pick an X")
+        (while to-reveal
+          (multiple-value-bind (cur-row cur-col) (pop to-reveal)
+            (minesweeper-debug "View-mine says " (number-to-string cur-col) ", " (number-to-string cur-row) " mine = " (make-string 1 (minesweeper-view-mine cur-row cur-col 't)))
+            (unless (or (minesweeper-is-revealed cur-row cur-col)
+                        (minesweeper-marked cur-row cur-col))
+              (minesweeper-debug "it's not revealed, so reveal it")
+              (minesweeper-reveal cur-row cur-col)
+              (if (eq (setq *minesweeper-blanks-left* (1- *minesweeper-blanks-left*))
+                      0)
+                  (progn (minesweeper-win-game)
+                         (throw 'game-end nil))
+                (when (eq (minesweeper-view-mine cur-row cur-col 't)
+                          ?0)
+                  (minesweeper-debug "pushing neighbors onto the stack")
+                  (mapc '(lambda (position)
+                           (push position
+                                 to-reveal))
+                        (minesweeper-neighbors cur-row cur-col)))))))))))
 
 
 (defun minesweeper-toggle-mark ()