-
debug...
can't figure out what's wrong with this program...
it's minesweeper program..
input of (0, 0) is automatic win...
if I uncover some area that doesn't have mines, it opens all area.
can't figure out what's wrong..
PHP Code:
int calculate(int i, int j)
{
int sum = 0;
/* Calculate values of cells surounding mines */
if (mines[i][j] != '*')
{
if(mines[i+1][j] == '*')
{
sum = 1 + calculate(i, j);
}
else if(mines[i+1][j+1] == '*')
{
sum = 1 + calculate(i, j);
}
else if(mines[i+1][j] == '*')
{
sum = 1 + calculate(i, j);
}
else if(mines[i+1][j-1] == '*')
{
sum = 1 + calculate(i, j);
}
else if(mines[i][j-1] == '*')
{
sum = 1 + calculate(i, j);
}
else if(mines[i-1][j-1] == '*')
{
sum = 1 + calculate(i, j);
}
else if(mines[i-1][j] == '*')
{
sum = 1 + calculate(i, j);
}
else
{
sum = 1 + calculate(i, j);
}
}
return sum;
}
-
Please don't post hundreds of lines of code at a time. Attach a file if you insist on showing the entire program. This is one problem I spotted before I got tired of reading and quit:
Code:
for( x = 0; x < 9; x++ )
for( y = 0; y < 9; y++ )
mines[x][y] = '0';
You declare mines as a 10 x 10 array. Here however, you only initialize 9 x 9. This is not what you want. Try this:
for( x = 0; x < 10; x++ )
Remember, arrays go from 0 to size-1. Thus, valid array cells are 0 to 9. If you stop before 9, then your nineth column and nineth row never get filled.
Quzah.
-
i reduced the code above..
sorry about that..
i narrowed down to those two functions..
I found another problem: calculating portion does not work..