tempvy.push_back(y);
/* if the east square is occupied and not handled, call process on that square */
if(x<width-1 && occupy[x+1][y] && !handled[x+1][y])
process(x+1,y);
/* if the west square is occupied and not handled, call process on that square */
if(x>0 && occupy[x-1][y] && !handled[x-1][y])
process(x-1,y);
/* if the north square is occupied and not handled, call process on that square */
if(y<height-1 && occupy[x][y+1] && !handled[x][y+1])
process(x,y+1);
/* if the south square is occupied and not handled, call process on that square */
if(y>0 && occupy[x][y-1] && !handled[x][y-1])
process(x,y-1);
}

This program does minimal error-checking, and you can enhance it so that no matter what the input file looks like, your program will handle it properly. You can also write a program to generate random input files to test your program.

Inside process() we see that the if statements take advantage of the short-circuit evaluation, which is discussed in Chapter 16.5.

Note that array-out-of-bounds errors are easy to make in this program; so be careful.Next let’s look at an interesting game – the game of Nim!