Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Well, look. The rule you already explained goes like this. Take any square you've already guessed. Calculate the number the program has given for that square minus the number of known mines adjacent to it: let this difference be D. Tally the number of adjacent unknown squares, let their number be S. If 0 == D, you mark all adjacent unknown squares as non-mines and guess them; if S == D, flag all of them as known mines; if D is something in between, do nothing; if D < 0 or S < D, then you've done something wrong.

(The third rule you gave is quite similar but you use the number of total mines instead of the number written on one square, and take all fields of the board instead of just the adjacent fields.)

But there's a more complicated rule that you can also apply. Take any two squares you've guessed with distance less than 3, and for each of the two, calculate the difference of the number you've got from the program for it and the number of known mines adjacent to it: this difference is D_0 for the first square and D_1 for the second. Tally the number of unknown squares adjacent to the first square, this number is S_0. Also tally the number of unknown squares adjacent to both squares at once, this number is C. Now if D_1 <= C and D_0 - D_1 == S_0 - C then you can mark as mines all squares adjacent to the first square but not adjacent to the second square, and mark as non-mine all squares adjacent to the second square but not adjacent to the first square; if D_1 <= C and D_0 - D_1 > S_0 - C then you've done something wrong. Do this also with the two squares in swapped role.


In reply to Re^2: App::SweeperBot - Perl plays minesweeper, automatically. by ambrus
in thread App::SweeperBot - Perl plays minesweeper, automatically. by pjf

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • 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?Last hourOther CB clients
    Other Users?
    Others avoiding work at the Monastery: (4)
    As of 2024-07-12 20:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.