Backward

Member
  • Content count

    23
  • Joined

  • Last visited

Community Reputation

127 Neutral

About Backward

  • Rank
    Member
  1. A* applied to minesweeper game

    Check your private messages.
  2. A* applied to minesweeper game

    ok, look at those 10 combinations.      ? B C D ? ? A 2 E ? ? 2 2 1 1 ? ? 1 0 0 ? ? 1 0 0   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.
  3. A* applied to minesweeper game

    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.
  4. A* applied to minesweeper game

    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. 
  5. A* applied to minesweeper game

    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.
  6. A* applied to minesweeper game

    {-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3}, {-3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-1,-1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1,-2,-1,-2, 1, 1, 1, 1, 1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1, 2, 2, 1, 1, 0, 0, 0, 1,-1,-1,-3}, {-3,-1,-1,-1,-1,-1,-1, 1, 0, 0, 0, 0, 0, 0, 1,-1,-1,-3}, {-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3} This is the table i got when i opened one field. I found 3 mines and they are flagged. I put this table in your algorithm and nothing happens. Table has 40 mines (16x16).
  7. A* applied to minesweeper game

    Can i use any other algorithm to find probabilities? Does anyone know which one gives best results for all table sizes 9x9, 16x16 and 30*16?
  8. A* applied to minesweeper game

    For bigger tables i don't get results... Is it possible to optimize it somehow?
  9. A* applied to minesweeper game

    bl_copy[b/12][b] = true;   I think these indexes are bad. Should it be bl_copy [(b - b %12)/12] [b%12] ?  
  10. A* applied to minesweeper game

    I actually posted code... Is that not enough? Is it too hard to read? Yes, you can use this to discover zero fields and bombs too, although there might be more direct ways to do that.   std::vector<int> unknowns; for (int i=0; i<12; ++i) { for (int j=0; j<12; ++j) { if (knowns[i][j] == -1) unknowns.push_back(i*12+j); bomb_locations[i][j] = (knowns[i][j] == -2); I understood just this. Other parts with random values i didn't understand.   Like what? 
  11. A* applied to minesweeper game

    I am not going to post graphics, but I can show you some crude code: #include <iostream> #include <algorithm> #include <cstdlib> #include <cstring> /* Convention: -3 : outside -2 : flag -1 : unknown >=0 : That many neighbors are bombs */ char knowns[12][12] = { {-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3}, {-3, 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -3}, {-3, 0, 2, -1, -1, -1, -1, -1, -1, -1, -1, -3}, {-3, 1, 3, -2, -1, 4, -1, -1, -1, -1, -1, -3}, {-3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -3}, {-3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -3}, {-3, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -3}, {-3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -3}, {-3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -3}, {-3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -3}, {-3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -3}, {-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3} }; int bombs_unaccounted_for = 19; int main() { bool bomb_locations[12][12]={{0}}; int danger[12][12]={{0}}; std::vector<int> unknowns; for (int i=0; i<12; ++i) { for (int j=0; j<12; ++j) { if (knowns[i][j] == -1) unknowns.push_back(i*12+j); bomb_locations[i][j] = (knowns[i][j] == -2); } } for (int count=0; count < 10000; ) { // Generate bomb distribution bool bl_copy[12][12]; std::memcpy(bl_copy, bomb_locations, sizeof(bl_copy)); for (int i=0; i<bombs_unaccounted_for; ++i) { int j = i + (std::rand() % (unknowns.size()-i)); std::swap(unknowns[i], unknowns[j]); int b = unknowns[i]; bl_copy[b/12][b] = true; } // Verify consistency for (int i=1; i<11; ++i) { for (int j=1; j<11; ++j) { if (knowns[i][j] >= 0) { int c = 0; for (int di=-1; di<=1; di++) for (int dj=-1; dj<=1; dj++) c += bl_copy[i+di][j+dj]; if (knowns[i][j] != c) goto NOT_CONSISTENT; } } } std::cout << "count=" << ++count << '\n'; // Accumulate danger values for (int i=0; i<12; ++i) { for (int j=0; j<12; ++j) { danger[i][j] += bl_copy[i][j]; std::cout << (knowns[i][j]==-1 ? danger[i][j] : -1) << ' '; } std::cout << '\n'; } NOT_CONSISTENT:; } } After running it for a while, it produces this: count=10000 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1718 1682 1692 1649 1713 1728 1746 1709 -1 -1 -1 -1 8282 4904 5001 4985 1708 1708 1736 1718 -1 -1 -1 -1 -1 5059 -1 5072 1702 1724 1721 1712 -1 -1 5023 4977 1718 4949 5068 4962 1707 1641 1652 1751 -1 -1 1640 1207 1246 1283 1669 1701 1662 1689 1693 1758 -1 -1 1671 1264 -1 1188 1714 1657 1663 1722 1672 1678 -1 -1 1661 1222 1333 1257 1659 1689 1658 1687 1697 1730 -1 -1 1615 1652 1803 1785 1762 1770 1590 1643 1628 1649 -1 -1 1716 1675 1669 1634 1556 1706 1655 1621 1694 1701 -1 -1 1711 1719 1671 1746 1617 1728 1659 1675 1738 1725 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 There is one spot marked "1188". That is the unknown spot that seems to have the lowest chance of being a bomb, so that's what I would open next. EDIT: If there were any spots marked "10000", it's a pretty sure bet that there is a bomb there, so you can just mark it. Can you write pseudocode for this algorithm? Can i use this to discover zero fields?
  12. A* applied to minesweeper game

    hahaha This looks like cheating method...If you remember of any other method write here.
  13. A* applied to minesweeper game

    What do you mean?
  14. A* applied to minesweeper game

    I wrote another algorithm which works with sets and i found all combinations like Paradigm Shifter wrote in his post in this topic and i found some intersections and finally algorithm generated all mined and all safe fields. So, there is no problem to detect safe and mined fields even in your examples.      (? ? ? 1 0 0 0 0 0) (? ? 1 1 0 0 0 1 1) (? ? 1 0 0 0 0 1 ?) (? ? 1 0 0 0 0 1 ?) (? ? 1 0 0 0 1 1 ?) (? ? 1 0 0 0 1 ? ?) (? ? 1 0 0 0 1 ? ?) (? ? 1 1 2 2 1 ? ?) (? ? ? ? ? ? ? ? ?)     ?  S  *  1  0  0  0  0  0 ?  S  1  1  0  0  0  1  1 ?  S  1  0  0  0  0  1  * ?  *   1  0  0  0  0  1  S ?  S  1  0  0  0  1  1  S ?  S  1  0  0  0  1   *  S  ?  *   1  0  0  0  1  S  ? ?  S  1  1  2  2  1  S  ? ?  S  S  S  *   *  S  S  ?   First minefield is starting minefield for my algorithm and second algorithm is what i got after my algorithm was finished. As you can see i found everything i could find and now i have to open next "S" field. But which one should i choose to open :) ? For example in this case which one would you choose? There is no rule. Maybe i can check which "S" field has the least number of flagged fields in 5x5 area around that "S" field???
  15. A* applied to minesweeper game

    OK it is for a case that at some moment of the game i will HAVE to guess what field to open because i didn't find any. But, what if i know that i will find more than 1 safe field? I already said that one fact i can use in this task is that test cases for this algorithm will always be solvable WITHOUT guessing. So i will always be able to find at least 1 safe field. And now what i want is which field i should choose to open? If i found 6 safe fields  how to choose a field which will enables my algorithm to find highest number of mines in next step. For example until this moment algorithm found 3 mines and they are flagged. Also 6 safe fields were found.  For example if i open first of 6 safe fields, i will be able to flag 2 mined fields. if i open second safe field i will be able to find 3 mines etc etc etc... if i open for example 5th safe field i will be able to find 6 mines in next step.   So, i will choose to open 5th field because it is a field which will leads me to find the highest number of mines in next step.But how to find that 5th safe field is field i have to open?