Rat in a maze problem

how to calculate all the numbers of paths in this problem

Just maintain a global counter. Increment the counter by 1 in the base case. And return false in the base case.