]> gitweb.factorcode.org Git - factor.git/commitdiff
minesweeper: click cells around question but not flagged.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 11 Feb 2018 18:02:36 +0000 (10:02 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 11 Feb 2018 18:02:36 +0000 (10:02 -0800)
extra/minesweeper/minesweeper.factor

index c44df91f1bd2b542daf9660569214391027c4441..6ea30c432b328fa27e2bca266acb2c581033b3de 100644 (file)
@@ -29,9 +29,6 @@ TUPLE: cell #adjacent mined? state ;
 : cells-dim ( cells -- rows cols )
     [ length ] [ first length ] bi ;
 
-: unmined-cell ( cells -- cell )
-    f [ dup mined?>> ] [ drop dup random random ] do while nip ;
-
 : #mines ( cells -- n )
     [ [ mined?>> ] count ] map-sum ;
 
@@ -41,6 +38,9 @@ TUPLE: cell #adjacent mined? state ;
 : #mines-remaining ( cells -- n )
     [ #mines ] [ #flagged ] bi - ;
 
+: unmined-cell ( cells -- cell )
+    f [ dup mined?>> ] [ drop dup random random ] do while nip ;
+
 : place-mines ( cells n -- cells )
     [ dup unmined-cell t >>mined? drop ] times ;
 
@@ -81,7 +81,7 @@ DEFER: click-cell-at
     neighbors [
         first2 [ row + ] [ col + ] bi* :> ( row' col' )
         cells row' col' cell-at [
-            { [ mined?>> ] [ state>> +question+ = ] } 1|| [
+            { [ mined?>> ] [ state>> +flagged+ = ] } 1|| [
                 cells row' col' click-cell-at drop
             ] unless
         ] when*