Working Minesweeper


12

Ähnlich wie beim Generieren von Minensuchgittern , obwohl die Herausforderung darin besteht, ein funktionierendes Minensuchgitter zu erstellen. Dies wird länger Code als normal sein (ich denke) .

Weitere Informationen zu Minensuchbooten .

Minesweeper ist ein Logikspiel, das auf den meisten Betriebssystemen zu finden ist. Das Ziel des Spiels ist es, zu bestimmen, wo sich die Minen auf einem Gitter befinden. Die angegebenen Zahlen geben die Anzahl der Minen um diesen Punkt an.

Erforderliche Funktionen:

-Randomized mine generation
-8x8 field with 10 mines
-Mine and "unknown" flags
-Reveal nearby blank spaces when a blank space has been revealed.
-Input and output code: It must be playable.  (Input and output code counts in the total)

Anmerkung zur Wertung :

Anything that is needed to make the program work is counted.
If it can be deleted and not affect the program, get rid of it.
I will occasionally update the selected answer to shorter programs if needed.

Im Informatikunterricht bin ich auf eine spezifischere Version dieses Problems gestoßen: Erstellen Sie eine Arbeitsversion mit der kürzesten Anzahl von Zeilen in Visual Basic (ich habe 57 Zeilen), und ich dachte, dass dies eine interessante Herausforderung für Codegolf sein wird. Wenn es Vorschläge zur Verbesserung der Frage gibt, kommentieren Sie diese bitte. Kürzester Code in Bytes gewinnt.


Müssen wir meine und "unbekannte" Flaggen berücksichtigen? Zählt der UI-Code auch zur Gesamtsumme?
Shmiddty

Ich gehe auch davon aus, dass wir Bytes anstelle von Zeilen zählen, da dies in mehreren Sprachen als einzeiliger Zeilenumbruch möglich ist.
Shmiddty

Der ursprüngliche Beitrag wurde bearbeitet, um Unsicherheiten zu klären.
EAKAE

Ich habe den Titel bearbeitet, weil ich zuerst dachte, Sie suchen nach Lösungen nur in funktionalen Programmiersprachen. Ich wurde umbenannt in "arbeiten" statt "funktionell", während es ganz normal ist, dass wir nach funktionierenden Lösungen suchen - was sonst?
Benutzer unbekannt

Antworten:


4

Python 2.7 (487C)

"""
char meaning:
    '?': unknown flag
    '!': mine flag
    'x': default
how to play:
    Input 3 chars each time. The first char is the action
    and the rest form a position. For example, '013' means
    uncover grid (1,3), '110' means flag the grid (1,0).

    The top-left corner is (0, 0), bottom-left (7,0), etc.

    Player will lose after uncover a mine, the program will 
    output "Bom". If the Player uncovers all grid that do 
    not contain a mine, he wins and the program will output 
    "Win".
"""
import random as Z
S=sum
M=map
T=range
P=[(i,j)for i in T(8)for j in T(8)]
C=dict(zip(T(-3,9),'?!x012345678'))
m={p:-1 for p in P}
h=Z.sample(P,10)
def U(p):
 if m[p]>=0:return 0
 n=filter(lambda(c,d):0<max(abs(p[0]-c),abs(p[1]-d))<2,P)
 m[p]=s=S((x in h)for x in n)
 return(1 if s else S(M(U,n))+1,-1)[p in h]
s=u=0
while(s<54)&(u>-1):
 f,i,j=M(int,raw_input(''.join((C[m[x]]+'\n '[x[1]<7])for x in P)))
 p=i,j;c=m[p]
 if f*(c<0):m[p]=-1-(-c)%3
 else:u=U(p);s+=u
print'WBionm'[s<54::2]

Komplettes Spielerlebnis:

x x x x x x x x
x x x x x x x x
x x x x x x x x
x x x x x x x x
x x x x x x x x
x x x x x x x x
x x x x x x x x
x x x x x x x x
000
0 0 1 x x x x x
0 0 2 x x x x x
0 0 2 x x x x x
0 0 1 2 x x x x
0 0 0 1 x x x x
1 1 0 2 x x x x
x 1 0 2 x x x x
x 1 0 1 x x x x
070
0 0 1 x x x x x
0 0 2 x x x x x
0 0 2 x x x x x
0 0 1 2 x x x x
0 0 0 1 x x x x
1 1 0 2 x x x x
x 1 0 2 x x x x
1 1 0 1 x x x x
123
0 0 1 x x x x x
0 0 2 x x x x x
0 0 2 ! x x x x
0 0 1 2 x x x x
0 0 0 1 x x x x
1 1 0 2 x x x x
x 1 0 2 x x x x
1 1 0 1 x x x x
113
0 0 1 x x x x x
0 0 2 ! x x x x
0 0 2 ! x x x x
0 0 1 2 x x x x
0 0 0 1 x x x x
1 1 0 2 x x x x
x 1 0 2 x x x x
1 1 0 1 x x x x
003
0 0 1 1 x x x x
0 0 2 ! x x x x
0 0 2 ! x x x x
0 0 1 2 x x x x
0 0 0 1 x x x x
1 1 0 2 x x x x
x 1 0 2 x x x x
1 1 0 1 x x x x
004
0 0 1 1 1 x x x
0 0 2 ! x x x x
0 0 2 ! x x x x
0 0 1 2 x x x x
0 0 0 1 x x x x
1 1 0 2 x x x x
x 1 0 2 x x x x
1 1 0 1 x x x x
014
0 0 1 1 1 x x x
0 0 2 ! 4 x x x
0 0 2 ! x x x x
0 0 1 2 x x x x
0 0 0 1 x x x x
1 1 0 2 x x x x
x 1 0 2 x x x x
1 1 0 1 x x x x
154
0 0 1 1 1 x x x
0 0 2 ! 4 x x x
0 0 2 ! x x x x
0 0 1 2 x x x x
0 0 0 1 x x x x
1 1 0 2 ! x x x
x 1 0 2 x x x x
1 1 0 1 x x x x
044
0 0 1 1 1 x x x
0 0 2 ! 4 x x x
0 0 2 ! x x x x
0 0 1 2 x x x x
0 0 0 1 1 x x x
1 1 0 2 ! x x x
x 1 0 2 x x x x
1 1 0 1 x x x x
034
0 0 1 1 1 x x x
0 0 2 ! 4 x x x
0 0 2 ! x x x x
0 0 1 2 3 x x x
0 0 0 1 1 x x x
1 1 0 2 ! x x x
x 1 0 2 x x x x
1 1 0 1 x x x x
035
0 0 1 1 1 x x x
0 0 2 ! 4 x x x
0 0 2 ! x x x x
0 0 1 2 3 3 x x
0 0 0 1 1 x x x
1 1 0 2 ! x x x
x 1 0 2 x x x x
1 1 0 1 x x x x
045
0 0 1 1 1 x x x
0 0 2 ! 4 x x x
0 0 2 ! x x x x
0 0 1 2 3 3 x x
0 0 0 1 1 1 x x
1 1 0 2 ! x x x
x 1 0 2 x x x x
1 1 0 1 x x x x
055
0 0 1 1 1 x x x
0 0 2 ! 4 x x x
0 0 2 ! x x x x
0 0 1 2 3 3 x x
0 0 0 1 1 1 x x
1 1 0 2 ! 2 x x
x 1 0 2 x x x x
1 1 0 1 x x x x
124
0 0 1 1 1 x x x
0 0 2 ! 4 x x x
0 0 2 ! ! x x x
0 0 1 2 3 3 x x
0 0 0 1 1 1 x x
1 1 0 2 ! 2 x x
x 1 0 2 x x x x
1 1 0 1 x x x x
164
0 0 1 1 1 x x x
0 0 2 ! 4 x x x
0 0 2 ! ! x x x
0 0 1 2 3 3 x x
0 0 0 1 1 1 x x
1 1 0 2 ! 2 x x
x 1 0 2 ! x x x
1 1 0 1 x x x x
174
0 0 1 1 1 x x x
0 0 2 ! 4 x x x
0 0 2 ! ! x x x
0 0 1 2 3 3 x x
0 0 0 1 1 1 x x
1 1 0 2 ! 2 x x
x 1 0 2 ! x x x
1 1 0 1 ! x x x
074
0 0 1 1 1 x x x
0 0 2 ! 4 x x x
0 0 2 ! ! x x x
0 0 1 2 3 3 x x
0 0 0 1 1 1 x x
1 1 0 2 ! 2 x x
x 1 0 2 ! x x x
1 1 0 1 1 x x x
125
0 0 1 1 1 x x x
0 0 2 ! 4 x x x
0 0 2 ! ! ! x x
0 0 1 2 3 3 x x
0 0 0 1 1 1 x x
1 1 0 2 ! 2 x x
x 1 0 2 ! x x x
1 1 0 1 1 x x x
005
0 0 1 1 1 1 x x
0 0 2 ! 4 x x x
0 0 2 ! ! ! x x
0 0 1 2 3 3 x x
0 0 0 1 1 1 x x
1 1 0 2 ! 2 x x
x 1 0 2 ! x x x
1 1 0 1 1 x x x
015
0 0 1 1 1 1 x x
0 0 2 ! 4 4 x x
0 0 2 ! ! ! x x
0 0 1 2 3 3 x x
0 0 0 1 1 1 x x
1 1 0 2 ! 2 x x
x 1 0 2 ! x x x
1 1 0 1 1 x x x
126
0 0 1 1 1 1 x x
0 0 2 ! 4 4 x x
0 0 2 ! ! ! ! x
0 0 1 2 3 3 x x
0 0 0 1 1 1 x x
1 1 0 2 ! 2 x x
x 1 0 2 ! x x x
1 1 0 1 1 x x x
036
0 0 1 1 1 1 x x
0 0 2 ! 4 4 x x
0 0 2 ! ! ! ! x
0 0 1 2 3 3 3 x
0 0 0 1 1 1 x x
1 1 0 2 ! 2 x x
x 1 0 2 ! x x x
1 1 0 1 1 x x x
046
0 0 1 1 1 1 x x
0 0 2 ! 4 4 x x
0 0 2 ! ! ! ! x
0 0 1 2 3 3 3 2
0 0 0 1 1 1 0 0
1 1 0 2 ! 2 0 0
x 1 0 2 ! 2 0 0
1 1 0 1 1 1 0 0
127
0 0 1 1 1 1 x x
0 0 2 ! 4 4 x x
0 0 2 ! ! ! ! !
0 0 1 2 3 3 3 2
0 0 0 1 1 1 0 0
1 1 0 2 ! 2 0 0
x 1 0 2 ! 2 0 0
1 1 0 1 1 1 0 0
007
0 0 1 1 1 1 x 1
0 0 2 ! 4 4 x x
0 0 2 ! ! ! ! !
0 0 1 2 3 3 3 2
0 0 0 1 1 1 0 0
1 1 0 2 ! 2 0 0
x 1 0 2 ! 2 0 0
1 1 0 1 1 1 0 0
017
0 0 1 1 1 1 x 1
0 0 2 ! 4 4 x 3
0 0 2 ! ! ! ! !
0 0 1 2 3 3 3 2
0 0 0 1 1 1 0 0
1 1 0 2 ! 2 0 0
x 1 0 2 ! 2 0 0
1 1 0 1 1 1 0 0
016
Win

Der letzte Schritt ist jedoch gefährlich.


Dies ist definitiv zu alt, um irgendetwas zu tun, aber Sie können Speicherplatz entfernen -1 for...und 1 if...zwei Bytes sparen.
Zacharý

(Beachten Sie, dass die Gäste nicht die Dokumentation und die nachgestellte Newline zählen)
user202729

7

Javascript, 978 Bytes (824 ohne CSS)

http://jsbin.com/otayez/6/

Checkliste:

Randomized mine generation - yes
8x8 field with 10 mines - yes
Mine flags - Yes
"unknown" flags - no
Reveal nearby blank spaces when a blank space has been revealed. - yes
Input and output code: It must be playable. - yes

JS:

(function(){
    f=Math.floor;r=Math.random;b=8,s=[-1,0,1],o='',m='*',l=0;

    for(g=[i=b];i;)g[--i]=[0,0,0,0,0,0,0,0];
    for(i=10,a=f(r()*64);i--;g[f(a/b)][a%b]=m)while(g[f(a/b)][a%b])a=f(r()*64);
    for(i=64;i--;z.id='b'+(63-i),c.appendChild(z))z=document.createElement('button');
    for(d=b;d--;)
      for(r=b;r--;)
        s.map(function(y){
          s.map(function(x){
            if(g[d][r]!=m&&g[d+y]&&g[d+y][r+x]==m)g[d][r]++;
          });
        });

    c.onclick=function(e){
        var t=e.target,
            i=t.id.slice(1),
            x=i%b,
            y=f(i/b),
            n=t.className=='b';

      if(t.innerHTML||(n&&!e.ctrlKey))return;
      if(e.ctrlKey)return t.className=(n?'':'b')

      if(q(x,y))alert('boom')
      if(l==54)alert('win')
    };
  function q(x,y){
    if(x<0||x>7||y<0||y>7)return;

    var p=y*b+x,
        v=g[y][x],
        t=document.all['b'+p];

    if(v!=m&&!t.innerHTML){
      t.innerHTML=g[y][x];
      t.className='f';
      l++;
      if(!v){t.className='z';s.map(function(d){s.map(function(r){q(x+r,y+d)})})}
    }
    return v==m
  }
})();

MiniJS 812 Bytes :

f=Math.floor;r=Math.random;b=8,s=[-1,0,1],o='',m='*',l=0,h='b';for(g=[i=b];i;)g[--i]=[0,0,0,0,0,0,0,0];for(i=10,a=f(r()*64);i--;g[f(a/b)][a%b]=m)while(g[f(a/b)][a%b])a=f(r()*64);for(i=64;i--;z.id=h+(63-i),c.appendChild(z))z=document.createElement('button');for(d=b;d--;)for(r=b;r--;)s.map(function(y){s.map(function(x){if(g[d][r]!=m&&g[d+y]&&g[d+y][r+x]==m)g[d][r]++})});c.onclick=function(e){var t=e.target,i=t.id.slice(1),n=t.className==h;if(t.innerHTML||(n&&!e.ctrlKey))return;if(e.ctrlKey)return t.className=(n?'':h);if(q(i%b,f(i/b)))alert('boom');if(l==54)alert('win')};function q(x,y){if(x<0||x>7||y<0||y>7)return;var p=y*b+x,v=g[y][x],t=document.all[h+p];if(v!=m&&!t.innerHTML){t.innerHTML=g[y][x];t.className='f';l++;if(!v){t.className='z';s.map(function(d){s.map(function(r){q(x+r,y+d)})})}}return v==m}

HTML 12 Bytes

<div id="c">

Das CSS ist vom Standpunkt der Funktionalität aus nicht erforderlich, aber vom Standpunkt der Benutzerfreundlichkeit aus:

#c{
  width:300px;
  height:300px;
}
button{
  width:12.5%;
  height:12.5%;
  line-height:30px;
}
.f,.z{
  background:#fff;
  border:solid 1px #fff;
}
.z{
  color:#fff;
}
.b{background:#f00}

Mini CSS 154 Bytes :

#c{width:300px;height:300px}button{width:12.5%;height:12.5%;line-height:30px}.f,.z{background:#fff;border:solid 1px #fff}.z{color:#fff}.b{background:#f00}

mit "unbekannten" Flaggen: jsbin.com/otayez/10
Shmiddty

4

C 568, 557, 537

Checklist:
  Randomized mine generation - yes
  8x8 field with 10 mines - yes
  Mine and "unknown" flags - yes
  Reveal nearby blank spaces when a blank space has been revealed. - yes
  Input and output code: It must be playable. - yes

Further to playable: 
  Win detection (found all mines, or revealed all empties)
  Bang detection (hit a mine)
  Game terminates.

Output format:
  # - unrevealed
  ! - a flagged mine
  * - a mine
  (number) - number of neighbouring mines
  ? - unknown flag

Input format:
  x y f 
  - where x is 0..7, y is 0..7 (origin upper-left)
  - f is 0 to open up, 1 to flag a mine, and 2 to flag a unknown

Beispielspiel:

./a.out
5 5 0
# 1 0 0 0 2 # #
# 1 0 0 0 2 # #
# 1 0 0 0 1 1 1
# 1 0 0 0 0 0 0
# # 1 0 0 0 1 1
# # 1 0 0 0 1 #
# # # 1 2 1 # #
# # # # # # # #
6 1 1
# 1 0 0 0 2 # #
# 1 0 0 0 2 ! #
# 1 0 0 0 1 1 1
# 1 0 0 0 0 0 0
# # 1 0 0 0 1 1
# # 1 0 0 0 1 #
# # # 1 2 1 # #
# # # # # # # #
7 5 0
# 1 0 0 0 2 # #
# 1 0 0 0 2 ! #
# 1 0 0 0 1 1 1
# 1 0 0 0 0 0 0
# # 1 0 0 0 1 1
# # 1 0 0 0 1 *
# # # 1 2 1 # 1
# # # # # # # #
bang!

Code:

// 8x8 grid but with padding before first row, after last row, and after last column, i.e. its 9x10
m[99]; // 0=empty,1=mine
u[99]; // 0=revealed,1=unrevealed,2=flag,3=unknown

// count neighbouring mines (8way)
c(i){return m[i-8]+m[i-9]+m[i-10]+m[i+8]+m[i+9]+m[i+10]+m[i-1]+m[i+1];}

// reveal (4way)
r(i){
    if(u[i]){
        u[i]=0;
        if(!c(i))r(i-9),r(i+9),r(i+1),r(i-1);
    }
}

i,x,y,f,e;
main(){
    // place 10 mines
    for(srand(time(0));i<10;){
        x=rand()%64;
        x+=9+x/8;
        if(!m[x]){
            m[x]=1;
            i++;
        }
    }
    for(;y<64;y++)u[y+9+y/8]=1; // mark visible grid as being unrevealed

    while(!e){
        // read input 0..7 0..7 0..2
        scanf("%d%d%d",&x,&y,&f);
        i=x+9+y*9;
        if(f)u[i]=f==1?2:u[i]==3?1:3;else r(i); // flag, toggle unknown/unrevealed, open

        // show grid and calc score
        for(y=f=x=0;x<64;x++){
            i=x+9+x/8;
            putchar(u[i]?" #!?"[u[i]]:m[i]?42:48+c(i)); // 42='*', 48='0'
            putchar(x%8==7?10:32);
            if(!u[i])y+=m[i]?-99:1;   // y = number of correctly open
            if(u[i]==2)f+=m[i]?1:-99; // f = number of correct mines
        }
        if(y<0||y==54||f==10)e=puts(y<0?"bang!":"win!"); // 54 = 64-10
    }
}

Ich habe versucht, die Rasterauffüllung hinzuzufügen, aber dadurch wurde mein Programm länger: P Gute Arbeit.
beary605

tut for(x=64;x--;)...Arbeit für c?
Shmiddty

4

Mathematica 566 548 1056

Bearbeiten : Dies ist eine vollständige Umschreibung. Ich gab den Versuch auf, den kürzesten Code zu erhalten, und beschloss stattdessen, die Funktionen einzubauen, die am sinnvollsten waren.

rgibt die Anzahl der Zeilen im Raster an. cgibt die Anzahl der Spalten im Raster an. m: Anzahl der Minen.

Das Spiel wird durch Mausklick auf die Schaltflächen gespielt. Wenn der Spieler auf eine Mine klickt, wird die Zelle schwarz und das Programm gibt "You Lose!"

Das Kontrollkästchen "u" ermöglicht es dem Spieler, jederzeit einen Blick auf die vollständige Lösung zu werfen. Die Fahnen "?" und "!" kann nach Belieben in eine beliebige Zelle gelegt werden.

DynamicModule[{s, x, f, l},
Manipulate[
Column[{
Grid[s],
If[u, Grid@f, Null]
}],
Grid[{{Control@{{r, 8}, 4, 16, 1, PopupMenu}, 
 Control@{{c, 8}, 4, 16, 1, PopupMenu},
 Control@{{m, 10}, 1, 50, 1, PopupMenu}},
{Button["New", i], 
 Control@{{e, 0}, {0 -> "play", 1 -> "?", 2 -> "!"}, SetterBar}, 
 Control@{{u, False}, {True, False}}}}],
 Deployed -> True,

 Initialization :>
 (p = ReplacePart;
  q = ConstantArray;
  z = Yellow;
  w = White;    
  b := Array[Button["  ", v[{#, #2}], Background -> z] &, {r, c}];
  a := RandomSample[l = Flatten[Array[List, {r, c}], 1], m];
  d[m1_] := 
   p[ListConvolve[BoxMatrix@1, p[q[0, {r, c}], (# -> 1) & /@ m1], 2,
    0], (# -> "*") & /@ (x)];
  n[y_] := Complement[Select[l, ChessboardDistance[y, #] == 1 &], x];
  d[m1_] := 
  p[ListConvolve[BoxMatrix@1, p[q[0, {r, c}], (# -> 1) & /@ m1], 2,
    0], (# -> "*") & /@ (x)];

  v[{r_, c_}] :=
   Switch[e,
    1, If[s[[r, c, 3, 2]] == z, 
     s = p[s, {{r, c, 1} -> If[s[[r, c, 1]] == "?", "  ", "?"]}], 
     Null],

    2, If[s[[r, c, 3, 2]] == z, 
    s = p[s, {{r, c, 1} -> If[s[[r, c, 1]] == "!", "  ", "!"]}], 
    Null],
    3, Null,


    0, Switch[f[[r, c]],
     "*", (Print["You lose!"]; (s = p[s, {r, c, 3, 2} -> Black])),
     0, (s = p[s, {{r, c, 1} -> "  ", {r, c, 3, 2} -> w}]; 
      f = p[f, {{r, c} -> ""}]; v /@ n[{r, c}]),
     "  ", Null,
     _, (s = p[s, {{r, c, 1} -> f[[r, c]], {r, c, 3, 2} -> w}])]];

   i :=
   (x = a;s = b;f = d[x]);i) ] ]

Ausgangszustand

pic1

Zu einem späteren Zeitpunkt ...

pic2


Die Schaltfläche "Neu" kostet Sie wahrscheinlich eine Menge Zeichen.
Shmiddty

Und es sieht nicht so aus, als hätten Sie das Markieren noch implementiert.
Shmiddty

Ich bin mir nicht sicher, was Sie damit meinen. Meinen Sie eine Option, mit der der Spieler ein Fragezeichen auf eine Zelle setzen kann? Übrigens kostet der "New Button" ca. 25 Zeichen.
DavidC

Der Spieler sollte in der Lage sein, eine "Flagge" auf einem Feld zu platzieren, das er für eine Mine hält, oder ein "?" Auf einem Platz sind sie unsicher.
Shmiddty

@Shmiddty Flags sind jetzt implementiert (zusammen mit ein paar anderen Dingen).
DavidC

2

Python ( 502 566)

Checkliste:

Randomized mine generation - yes
8x8 field with 10 mines - yes
Mine and "unknown" flags - yes
Reveal nearby blank spaces when a blank space has been revealed. - yes
Input and output code: It must be playable. - yes

Es hat auch einen Win-Detektor.

Die Eingabe erfolgt bei laufendem Spiel mit (f, x, y). (x, y)sind die Koordinaten der Rasterauswahl, fob Sie markieren möchten oder nicht. (0, 0, 0)würde sich öffnen (0, 0)und (1, 2, 3)markieren (2, 3). Das Markieren funktioniert in einem Zyklus: Das zweimalige Markieren eines Quadrats gibt ein Fragezeichen.

(Anzahl) - Anzahl der Minen
(Weltraum) - unerforscht
. - 0 Minen
! - flag
"- frage

import random
A=[-1,0,1]
R=lambda x:[x+i for i in[-9,-8,-7,-1,1,7,8,9]if(0<x+i<64)&([i,x%8]not in([7,0],[-7,7],[-1,0],[1,7]))]
M=lambda p:sum(G[i]=='*'for i in R(p))
def V(p):
 m=M(p);G[p]=`m`if m else'.'
 if m>0:return
 for c in R(p):
  if' '!=G[c]:continue
  m=M(c);G[c]=`m`
  if m==0:G[c]='.';V(c)
G=[' ']*54+['*']*10
random.shuffle(G)
while' 'in`G`:
 for i in range(8):print[j.replace('*',' ')[0]for j in G[8*i:8*i+8]]
 i=input()[::-1];a=i[0]*8+i[1];b=G[a]
 if i[2]:G[a]=(chr(ord(b[0])+1)if'"'!=b[0]else' ')+b[1:];continue
 if'*'==b:print'L';break
 if'!'!=b:V(a)

Verbesserungsbedürftig: Funktion R [Alle Quadrate um Punkt p abrufen] (101 Zeichen), Drucken (69 Zeichen), Markieren (72 Zeichen)


1

Dyalog APL, 113 Bytes

{⎕←1 0⍕c+○○h⋄10=+/,h:1⋄m⌷⍨i←⎕:0⋄∇{~⍵⌷h:0⋄(⍵⌷h)←0⋄0=⍵⌷c:∇¨(,⍳⍴m)∩⍵∘+¨,2-⍳3 3⋄0}i}h←=⍨c←{⍉3+/0,⍵,0}⍣2⊢m←8 8⍴10≥?⍨64

Nicht konkurrierend: keine "Mine" - und "Unknown" -Flaggen

Drucke *für ungeöffnete Zellen und Ziffern für geöffnete (einschließlich 0)

Fordert den Benutzer wiederholt auf, die 1-basierten Koordinaten einer zu öffnenden Zelle einzugeben

Letztendlich gibt es 0bei einem Fehler (Mine geöffnet) oder 1bei einem Erfolg (nur 10 ungeöffnete übrig)

sieht aus wie das:

********
********
********
********
********
********
********
********
⎕:
      1 1
00000000
11012321
*112****
********
********
********
********
********
⎕:
      3 8
00000000
11012321
*112***1
********
********
********
********
********
⎕:
      4 7
00000000
11012321
*112***1
******3*
********
********
********
********
⎕:

...

Durch die Nutzung unserer Website bestätigen Sie, dass Sie unsere Cookie-Richtlinie und Datenschutzrichtlinie gelesen und verstanden haben.
Licensed under cc by-sa 3.0 with attribution required.