Subj : Re: Are recursive functions ever needed? To : comp.programming From : DarkD Date : Sun Oct 02 2005 12:11 pm > Well, my problem here seems to be lack of good examples where > recursion is needed. Would anybody provide some? Its used alot in gaming for path finding. Consider a 2x2 array of data. A sprite in the game can move 6 'units'. each index in the array has a number which is how many units it costs to move over that terrain. So you want to create the possible movement area for the sprite. You call a function with the x y array index's of the position of the sprite, take the terrain value off it and recall the same function for the 4 surrouding array values (up down left right) etc. so you keep recursively calling and each recursion takes the terrain value off its passed value. If it reaches zero that recurrsion does't continue. Since you don't actually know how many you will do recursion is the only way to do this. This kind of routine will find the optimal path around any maze etc also, but its very cpu intensive and almost impossible to do non recursively. Use it all the time in games where you pick a unit and its movement range comes up and that range is inhibited by trees/mountains/other units etc. If anyoone else knows a better way to do this I would be very interested. .