skipping to a specific place in a recursive function
I wrote a recursive function that recurses Adding times, then calls go (). The entire function will call go () billions of times. When I call this function, I want to only run go () 5,000,000 times. It should run the first 5,000,000 go's if the Part variable is set to 1, the 2nd 5,000,000 go's if Part is 2, etc. The bolded code below is my attempt at implementing this. This code runs the correct 5,000,000-part pieces, but it takes too long because it is still recursing through every part, it's just not calling go () for the other ones. How can I only run the specific piece without recursing through all of the other ones?
Code:
Add (int X, int Y, int Adding)
{
int Tile;
while (Y < 12)
{
while (X < 16)
{
if (aRoom [nRoom] [Y] [X] == 0)
{
Changes [Adding - 1] [1] = X;
Changes [Adding - 1] [2] = Y;
for (Tile = 0; aTiles [nRoom] [Tile] [0] != 0; Tile++)
{
if (aTiles [nRoom] [Tile] [1] > 0)
{
aTiles [nRoom] [Tile] [1]--;
aRoom [nRoom] [Y] [X] = aTiles [nRoom] [Tile] [0];
Changes [Adding - 1] [0] = aTiles [nRoom] [Tile] [0];
if (Adding > 1)
{
Add (X + 1, Y, Adding - 1);
}
else
{
Re: skipping to a specific place in a recursive function
I'm having trouble understanding exactly what you want to achieve here. Do you think you could list the logical sequence of events you're aiming for? Then I might be able to help you.
Bookmarks