Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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:~$


In reply to Re: YAMineSweeper by Juerd
in thread YAMineSweeper by giulienk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2021-10-28 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (95 votes). Check out past polls.

    Notices?