Click to See Complete Forum and Search --> : minesweeper - have somebody algorithm.....


abab
May 1st, 2007, 09:43 AM
Have somebody algorithm or something for exposing fields- for example:
somebody exposing field where is "0" so all fields around also automatically exposing and if some field which automatically exposing have also "0" then fields around them also exposing and again and again........ ?

MrViggy
May 1st, 2007, 12:59 PM
One way would be to create a stack of fields. Push your single field to the stack. While the stack is not empty; pop the field from the stack. If that field is '0' expose it, and push it's neighbors onto the stack.

Viggy

abab
May 1st, 2007, 02:02 PM
On beginning I want exposing only the nearest neighbours the field which is "0" - I have 6x6 board so I have 36 buttons with id= 201:236 - and I made that algorithm:
In WM_COMMAND I have:
See that: http://img384.imageshack.us/my.php?image=uf3wa1.jpg


int id=LOWORD(wParam);

if (under the button which you exposed is "0")
{
id=id+1;
if(id>200 && id <237 ) ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
id=id+6;
if(id>200 && id <237) ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
id=id-1;
if(id>200 && id <237) ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
id=id-1;
if(id>200 && id <237 ) ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
id=id-6;
if(id>200 && id <237) ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
id=id-6;
if(id>200 && id <237) ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
id=id+1;
if(id>200 && id <237) ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
id=id+1;
if(id>200 && id <237) ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);

}



for example:

If under the button which you exposing with id=216 is "0", exposing also buttons with id:
id=id+1 -> id=216+1=217
id=id+6 -> id=217+6=223
id=id-1 -> id=223-1=222
id=id-1 -> id=221
id=id-6 -> id=215
id=id-6 -> id=209
id=id+1 -> id=210
id=id+1 -> id=211

So it is good BUT for button with id=201:
id=id+1 -> id=201+1=202
id=id+6 -> id=202+6=208
id=id-1 -> id=208-1=207
id=id-1 -> id=207-1=206 !!!! BUT IT ISN'T A NEIGHBOUR !!!!!!
..............

SO THIS ALGORITHM ISN'T SO GOOD !!
i DON'T KNOW how can I change it that it was good........

MrViggy
May 1st, 2007, 05:53 PM
Okay, you just need to check for edge cases (on the top, bottom, left, right). If the board will never be any bigger, I'd just hardcode the values. For example:
std::set<int> topIDs, botIDs, rightIDs, leftIDs;
rightIDs.insert(206);
rightIDs.insert(212);
rightIDs.insert(218);
rightIDs.insert(224);
rightIDs.insert(230);
rightIDs.insert(236);

...
if (rightIDs.find(id-1) != rightIDs.end())
// Tried to look for left neighbor, but we wrapped around! 'id-1' is not a neighbor
Viggy

abab
May 2nd, 2007, 02:53 AM
I see :)


In WM_COMMAND:
int id=LOWORD(wParam);
int static_id=LOWORD(wParam);



if (under the button which you exposed is "0")
{
id=id+1;
if(id>200 && id <237 && static_id!=206 && static_id!=212 && static_id!=218 && static_id!=224 && static_id!=230 && static_id!=236) ShowWindow(GetDlgItem(OknoGlowne, id), SW_HIDE);
id=id+6;
if(id>200 && id <237 && static_id!=206 && static_id!=212 && static_id!=218 && static_id!=224 && static_id!=230 && static_id!=236) ShowWindow(GetDlgItem(OknoGlowne, id), SW_HIDE);
id=id-1;
if(id>200 && id <237) ShowWindow(GetDlgItem(OknoGlowne, id), SW_HIDE);
id=id-1;
if(id>200 && id <237 && static_id!=201 && static_id!=207 && static_id!=213 && static_id!=219 && static_id!=225 && static_id!=231) ShowWindow(GetDlgItem(OknoGlowne, id), SW_HIDE);
id=id-6;
if(id>200 && id <237 && static_id!=201 && static_id!=207 && static_id!=213 && static_id!=219 && static_id!=225 && static_id!=231) ShowWindow(GetDlgItem(OknoGlowne, id), SW_HIDE);
id=id-6;
if(id>200 && id <237 && static_id!=201 && static_id!=207 && static_id!=213 && static_id!=219 && static_id!=225 && static_id!=231) ShowWindow(GetDlgItem(OknoGlowne, id), SW_HIDE);
id=id+1;
if(id>200 && id <237) ShowWindow(GetDlgItem(OknoGlowne, id), SW_HIDE);
id=id+1;
if(id>200 && id <237 && static_id!=206 && static_id!=212 && static_id!=218 && static_id!=224 && static_id!=230 && static_id!=236) ShowWindow(GetDlgItem(OknoGlowne, id), SW_HIDE);

}



Now all neighbours field which is "0" exposing very good, but how can I do that neighbours with also "0" of neighbours which was expose also will expose ?

MrViggy
May 2nd, 2007, 03:49 PM
Like I said before:

Push the button pressed onto a stack
while the stack is not empty:

Pop the stack.
Make button invisible.
Push all 0 neighbors of popped button onto the stack
Go back to beginning of loop


Viggy

abab
May 2nd, 2007, 04:02 PM
I don't understand so everything what I made before was unnecessary ? And what give me stock ?

TheCPUWizard
May 2nd, 2007, 04:33 PM
If the board will never be any bigger, I'd just hardcode the values


Nitpicky, but the board size is dependant on level for the "real" game...(and can also be custom,

MrViggy
May 2nd, 2007, 06:35 PM
Nitpicky, but the board size is dependant on level for the "real" game...(and can also be custom,
Nitpickier, I didn't see the specs for the game; and didn't want to assume the OP was talking about the Microsoft version.

:D

Viggy

VladimirF
May 2nd, 2007, 08:02 PM
Nitpickier, I didn't see the specs for the game; and didn't want to assume the OP was talking about the Microsoft version.

:D

Viggy
Offtop: I would LOVE to watch the person converting this to 7x7 board! You could actually sell tickets for that!

abab
May 3rd, 2007, 04:29 AM
I have that but is complicated but it runs very good:


In WM_COMMAND:


int id=LOWORD(wParam);
int static_id;

int element=-1;
int stock[40]={0};
if(under the button which you exposed is "0")
{

element=0;
stock[element]=id;
}

while(element>=0)
{
id=stock[element]+1;
static_id=id-1;
if(id>200 && id <237 && static_id!=206 && static_id!=212 && static_id!=218 && static_id!=224 && static_id!=230 && static_id!=236 && IsWindowVisible(GetDlgItem(hwnd, id))!=0)
{
if(under the button which you exposed is "0") {stock[element]=id; element++;}

ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
};
id=id+6;
if(id>200 && id <237 && static_id!=206 && static_id!=212 && static_id!=218 && static_id!=224 && static_id!=230 && static_id!=236 && IsWindowVisible(GetDlgItem(hwnd, id))!=0)
{
if(under the button which you exposed is "0") {stock[element]=id; element++;}
ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
};
id=id-1;
if(id>200 && id <237 && IsWindowVisible(GetDlgItem(hwnd, id))!=0)
{
if(under the button which you exposed is "0") {stock[element]=id; element++;}
ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
};
id=id-1;
if(id>200 && id <237 && static_id!=201 && static_id!=207 && static_id!=213 && static_id!=219 && static_id!=225 && static_id!=231 && IsWindowVisible(GetDlgItem(hwnd, id))!=0)
{
if(under the button which you exposed is "0") {stock[element]=id; element++;}
ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
};
id=id-6;
if(id>200 && id <237 && static_id!=201 && static_id!=207 && static_id!=213 && static_id!=219 && static_id!=225 && static_id!=231 && IsWindowVisible(GetDlgItem(hwnd, id))!=0)
{
if(under the button which you exposed is "0") {stock[element]=id; element++;}
ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
};
id=id-6;
if(id>200 && id <237 && static_id!=201 && static_id!=207 && static_id!=213 && static_id!=219 && static_id!=225 && static_id!=231 && IsWindowVisible(GetDlgItem(hwnd, id))!=0)
{
if(under the button which you exposed is "0") {stock[element]=id; element++;}
ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
};
id=id+1;
if(id>200 && id <237 && IsWindowVisible(GetDlgItem(hwnd, id))!=0)
{
if(under the button which you exposed is "0") {stock[element]=id; element++;}
ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
};
id=id+1;
if(id>200 && id <237 && static_id!=206 && static_id!=212 && static_id!=218 && static_id!=224 && static_id!=230 && static_id!=236 && IsWindowVisible(GetDlgItem(hwnd, id))!=0)
{
if(under the button which you exposed is "0") {stock[element]=id; element++;}
ShowWindow(GetDlgItem(hwnd, id), SW_HIDE);
};
element--;
}




but convert it to 7x7 board or something else it will be difficult - so have you any idea how can I make this better for convert board ?