QO0oo0OQ
April 3rd, 2009, 03:23 PM
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?
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
{
PartTests++;
if (Part == 0 || Part == Parts)
{
go ();
}
if (PartTests == 5000000)
{
Parts++;
PartTests = 0;
}
}
aTiles [nRoom] [Tile] [1]++;
}
}
aRoom [nRoom] [Y] [X] = 0;
}
X++;
}
X = 0;
Y++;
}
}
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
{
PartTests++;
if (Part == 0 || Part == Parts)
{
go ();
}
if (PartTests == 5000000)
{
Parts++;
PartTests = 0;
}
}
aTiles [nRoom] [Tile] [1]++;
}
}
aRoom [nRoom] [Y] [X] = 0;
}
X++;
}
X = 0;
Y++;
}
}