http://www.perlmonks.org?node_id=139172


in reply to YAMineSweeper

Hi,

I like the idea of a simple minesweeper, and tried to make one myself :)

Mine doesn't check user input and doesn't auto-sweep, but it fits in 5 lines :)
It tests if the user won, and if so, quits the game.

map$f[rand 8][rand 8]=1,0..9;@u=map[(',')x8],1..8;for(;$i=-2;){print$ i+++2?$i:' '," @$_\n"for[0..7],@u;($x,$y,$f)=split' ',<>;$f?$u[$y][$x ]='F':$u[$y][$x]ne'F'&&$f[$y][$x]&&die||do{$m=' ';for$z(-1..1){$y+$z> -1&&$x+$_>-1&&$f[$y+$z][$x+$_]&&$m++for-1..1}$u[$y][$x]=$m};for$z(0.. 7){for$q(0..7){$_=$u[$z][$q],$i+=$f[$z][$q]?!/^F/:/F/}}$i<8&&die"\n"}


Open (and unflag if flagged) using "x y" ("0 0"), flag with "x y 1" ("0 0 1").

Update (200201161311+0100) Bugs fixed, better checking scan
Update (200201191544+0100) A previous bugfix introduced 3 new ones, making the game a bit unpredictable ;) Fixed now.
Update (200201200039+0100) I need more sleep. Okay, I believe it's really playable now (I actually tried it this time (kick me not))
0 1 2 3 4 5 6 7 0 1 , 1 1 , , , 2 1 1 1 , , , 3 1 , , 1 , , , 4 , , , 2 1 , , , 5 , , , , , , , , 6 , , , , , 2 1 1 7 , , , , , 1 6 0 Died at mine.pl line 3, <> line 29.
As you can see, I'm not very good at this game :)

2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$