I understood just this. Other parts with random values i didn't understand.

1. Fill up a vector with the unknown locations and marking the known bomb locations. (This is the part you understood.)2. Generate a random distribution of bombs (bl_copy) by making a copy of the known bomb locations and randomly distributing the remaining bombs (the way I think of the algorithm to do that is to have a deck whose cards are unknown locations, shuffle it and deal the required number of cards).3. Verify that the generated random distribution of bombs is consistent with all the known counts. Go back to 2 if it is not.4. Accumulate danger values in the locations where there are bombs in the random distribution.5. If we don't have enough examples (10,000 in my code), go back to 2.

although there might be more direct ways to do that.

Like what?

Restrict yourself to unknowns that are adjacent to knowns. Assume one of them is a bomb and try to find a consistent distribution of all the other bombs. Assume it is not a bomb, and do the same thing. If one of these searches for consistency fails, you know if the unknown is a bomb or not.

The consistency search can be implemented using backtracking.

You can probably speed things up a lot by identifying some common cases (e.g., if we have already located the correct number of bombs adjacent to a known square, the other adjacent squares are not bombs) before attempting all the searches for consistency.

Share this post

Link to post

Share on other sites

Can you post an example of a position where the naive algorithm I posted doesn't produce any results? I am sure I can think of some refinements to make the algorithm more practical, and having some example to test on would help.

Share this post

Link to post

Share on other sites

In your algorithm if i understood well, you put randomly all rest mines and then you check is it possible. But there could be many situations when state is not consistent for example there is a square 2 but there are 3 mines around it. Why don't we find all possible consistent combinations and then check for every square how many times there was a mine? It will be just a kind of special case of your algorithm.

Edited May 9, 2013 by Backward

0

Share this post

Link to post

Share on other sites

I am not sure I understand your suggestion. The brute-force nature of what I proposed will make it so that in many instances only a small fraction of the random distributions tried will be consistent with the known information. It is very reasonable to try to increase this fraction to make the algorithm practical, but most simple ways to that would bias the distributions so the measured probabilities might not be correct.

It can probably be done correctly, perhaps with some variation of the Metropolis algorithm, but I expect this will be tricky.

Share this post

Link to post

Share on other sites

I was thinking about finding all possible combination for squares with number.

? ? ? ? ?
? ? 2 ? ?
? 2 2 1 1
? ? 1 0 0
? ? 1 0 0

In this example i will find all possible locations for every number. For example square 2 in second row.

? X ? ? ?
? X 2 ? ?
? 2 2 1 1
? ? 1 0 0
? ? 1 0 0

? ? X ? ?
? X 2 ? ?
? 2 2 1 1
? ? 1 0 0
? ? 1 0 0

? ? ? X ?
? X 2 ? ?
? 2 2 1 1
? ? 1 0 0
? ? 1 0 0

? ? ? ? ?
? X 2 X ?
? 2 2 1 1
? ? 1 0 0
? ? 1 0 0

? X X ? ?
? ? 2 ? ?
? 2 2 1 1
? ? 1 0 0
? ? 1 0 0

? X ? X ?
? ? 2 ? ?
? 2 2 1 1
? ? 1 0 0
? ? 1 0 0

? X ? ? ?
? ? 2 X ?
? 2 2 1 1
? ? 1 0 0
? ? 1 0 0

? ? X X ?
? ? 2 ? ?
? 2 2 1 1
? ? 1 0 0
? ? 1 0 0

? ? X ? ?
? ? 2 X ?
? 2 2 1 1
? ? 1 0 0
? ? 1 0 0

? ? ? X ?
? ? 2 X ?
? 2 2 1 1
? ? 1 0 0
? ? 1 0 0

There are 10 possible locations for mines around this square. If we find possible locations for all squares with number, then we can calculate probability without guessing and also we can be sure that all possible consistent combinations are found and here in your algorithm we do random distribution and we can't be sure for bigger tables that all consistent possibilities were computed.

Share this post

Link to post

Share on other sites

You don't know if all those 10 distributions of two bombs around that "2" are equally likely or not.

What do you mean? I didn't understand you. If these 10 distributions are all possible for square "2", and if we find for rest of squares all possible distributions, we can make all combinations between all squares with numbers and only possible combinations will be found.

Share this post

Link to post

Share on other sites

These 10 possibilities are: ab,ac,ad,ae,bc,bd,be,cd,ce,de. Now we can do same thing for rest of numbers and if we pair each possibility for each square with possibilities from another squares and do intersect, we will get all possible positions of mines and not mines. I was thinking about applying this algorithm first and then we can apply your algorithm. Maybe it can give better results.

0

Share this post

Link to post

Share on other sites

The "pair each possibility for each square with possibilities from another squares and do intersect" part sounds ill defined to me. If you can describe an algorithm to do that, that would be great. Otherwise I can't tell if it would work without bias or not.

0

Share this post

Link to post

Share on other sites

The "pair each possibility for each square with possibilities from another squares and do intersect" part sounds ill defined to me. If you can describe an algorithm to do that, that would be great. Otherwise I can't tell if it would work without bias or not.