Recursive minesweeper

Hi, i need to code parts of a minesweeper game but these parts must be coded with recursive methodes. So what follows is to replace an element of a the vector matrix by CHIFFRE (which is NUMBER in french). How could i make this recursive because obviously it is not?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  void Carte::UpdateCarte()
{
    // A completer
	for (int i = 0; i < GetNbLigne(); i++)
	{
		for (int j = 0; j < GetNbColonne(); j++)
		{
			if (cases[i][j]  == Case::Mine)
			{
				cases[i -= 1].swap(cases[Case::Chiffre]);
				cases[i += 1].swap(cases[Case::Chiffre]);
				cases[j -= 1].swap(cases[Case::Chiffre]);
				cases[j += 1].swap(cases[Case::Chiffre]);
			}
			
			
		}
	}
}
You should first start with working code. There is a bug in the function you've shown. You don't mean to say i -= 1, but instead just i - 1. The first one actually modifies i, subtracting one from it, and then evaluating to the result which it uses as an index. But then the following i += 1 adds 1 back to i which makes it equal to i again, but you want it to equal i + 1. So it should be:
1
2
3
4
5
6
7
8
9
10
11
12
void Carte::UpdateCarte()
{
    for (int i = 0; i < GetNbLigne(); i++)
        for (int j = 0; j < GetNbColonne(); j++)
            if (cases[i][j]  == Case::Mine)
            {
                cases[i - 1].swap(cases[Case::Chiffre]);
                cases[i + 1].swap(cases[Case::Chiffre]);
                cases[j - 1].swap(cases[Case::Chiffre]);
                cases[j + 1].swap(cases[Case::Chiffre]);
            }
}

Other than that I find the code incomprehensible (swapping? and what about out-of-bound access? (maybe you have a border?)) so I can't help you with the recursion.
Last edited on
Topic archived. No new replies allowed.