// Random ant walk starting at middle of ''grid,''// an array of bools initialized to ''false.''unsigned int dir = rand(0, 3);unsigned int antX = GRID_X/2;unsigned int antY = GRID_Y/2;for(unsigned int i = 0; i < NUM_ITERATIONS; ++i){ grid[antX][antY] = true; if(rand(0, 100) > PROB_TURN_PERCENT) { dir = rand(0, 3); } switch(dir) { case 0: ++antX; break; case 1: --antX; break; case 2: ++antY; break; case 3: --antY; break; } //TODO: Add code to prevent ant from walking // off grid, or to make it wrap around.}
Note that there''s nothing to stop an ant from going where it has already been.
With a low PROB_TURN_PERCENT you get more paths, which are generally straighter, and fewer, smaller rooms. Larger PROB_TURN_PERCENT values give shorter, more twisting paths, and larger rooms. A large PROB_TURN_PERCENT will produce what appear to be continents linked together by one or more isthmi. Use more than one ant if you want seperate islands.