I'm currently working on my forest class for my forest fire simulation, but I've run into trouble.
In one particular spot, it wants to say grid is not declared.
Here is a working implementation followed by the driver:
Code:
int forest::nextStatus(int i, int j) const
{
double rannum, z;
rannum = static_cast<double>(rand())/RAND_MAX;
z=(grid[i][j].getProbCatch()/grid[i][j].getWetness());
if( (grid[i][j].getStatus()==live) && (rannum<z) && (grid[i+1][j].getStatus()==burning))
{
return burning;
}
else if( (grid[i][j].getStatus()==live) && (rannum<z) && (grid[i-1][j].getStatus()==burning))
{
return burning;
}
else if( (grid[i][j].getStatus()==live) && (rannum<z) && (grid[i][j+1].getStatus()==burning))
{
return burning;
}
else if( (grid[i][j].getStatus()==live) && (rannum<z) && (grid[i][j-1].getStatus()==burning))
{
return burning;
}
else if( grid[i][j].getStatus()==burning )
{
return dead;
}
else if( grid[i][j].getStatus()==dead )
{
return dead;
}
else
return live;
}
Code:
void forest::applyNextStatus()
{
tree next_grid[FW][FH];
int i, j, stat;
for(int i=0; i<21; i++){
for(int j=0; j<21; j++){
next_grid[i][j]=grid[i][j];
}
}
for(int i=1; i<20; i++){
for(int j=1; j<20; j++){
stat=nextStatus(i, j);
next_grid[i][j].setStatus(stat);
}
}
for(int i=0; i<21; i++){
for(int j=0; j<21; j++){
grid[i][j]=next_grid[i][j];
}
}
}
Driver:
Code:
b.applyNextStatus();
However for this set, it is saying grid is not declared.
Code:
int regrowth(double growProb)
{
double rannum;
rannum=static_cast<double>(rand())/RAND_MAX;
for(int i=1; i<20; i++){
for(int j=1; j<20; j++){
if( (grid[i][j].getStatus()==dead) && (rannum<growProb)){
return live;
}
else{
return dead;
}
}
}
}
Driver: