I am attempting to teach myself python and have hit a rough spot once it has come to recursion. I have done the classic recursive functions (factorial, fibonacci numbers...) but I am going back over old code and trying to convert most of my iterative functions to recursive functions for practice.
This is the wall that I have hit:
I made a dungeon crawler a while back and I am trying to replace a for loop I used to reveal the squares near my sprite. So when the sprite is placed, he/she sees the tile he/she is on as well as the adjacent and diagonal squares (9 in total including the one the avatar is on).The other tiles making up the room are hidden. This I deemed view radius 1. For view radius 2, I wanted the char to see radius 1 squares plus all the tiles adjacent to those tiles. At the time I could not figure out how to do it with a for loop so I just implemented a simpler scheme.
I feel this visibility function could be written recursively but I am having a hard time coming up with a base case and what my recursive step would be. My for loop just took avatar pos and iterated over a range to avatar pos + radius and I did that for the x,y coordinates.
As far as translating this over to a recursive function I am really confused. I have done many searches trying to get a lead but only come up with complicated subjects such as: FOV using recursive shadowcasting which is way beyond me.
Any help would be greatly appreciated.
I find it helps a LOT to express recursions in words. What the algorithm says is basically "what's visible at radius N is what's visible from radius N-1". Like, uh, the edge gets bigger.
Recursive Function To Help Clear Tiles (Field Of View)