

We don’t even have to imagine the process.

These conditions were already applied: one for mine checking in game()function and one for positive value in mineCount()function. And the condition to stop it is when you have neighbours with at least one mine or have no neighbours to open. I’ll simply pass the coordinates of each neighbour to itself which in return will do the same the process on that cell. Plus we don’t know if a particular neighbour count becomes 0 because if it does, we need to count the number of mines for that cell’s neighbours……Īhhhh! It seems there’s no end to it. Wait a second! We have to count again that too for each neighbour. If true, then go through the neighbours again and count their neighbours. Firstly, we will implement it using for loop: int fact(int n) For example, the following code will return the factorial of a number( factorial of a number N is N! = N x (N-1) x … x 2 x 1, hence 5! = 5 x 4 x 3 x 2 x 1 = 120). Using a recursive algorithm, certain problems can be solved quite easily. The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. How? By making the legendary MineSweeper game! But before we start, let me introduce you to recursion. In this blog, we will be learning to apply one of the most important yet interesting concepts of programming - recursion.
