Actually the best way to go about doing collision detection like that is to use a quad tree algo or a BSP algo. However for pure 2D grids quad trees work much better.
Essentially generate all of your dudes. Now build your starting quadtree from that.
Here is the idea of a quadtree. Start with a large area or large square. Split into 4 smaller squares. Split until desired resolution is reached or no more splitting can be done. This is the leaf. Place all objects that are inside of this square or bounding area in the leaf. Do this for the entire scene or world.
Now when you search do this:
Start at the root of the tree.
Move down into the tree until you reach a leaf. Check all those objects against each other for collision. Repeat for each bounding area in your scene or world.
To illustrate I'll show some code that will draw boxes on the screen in a quad tree fashion. DrawBox() is simply a function that draws a solid colored square to the screen.
Code:
void QuadTreeDemo(int depth,int left,int top,int right,int bottom,RGBA color)
{
if (depth<1) return;
//For actual tree code would look like this
//if (depth<desired_depth) { AddObjectsToLeaf();return; }
mid_horiz=(left+right)>>1;
mid_vert=(top+bottom)>>1;
//Draw square for this recursion
DrawBox(left,top,right,bottom,color);
//Recurse into upper left
QuadTreeDemo(depth-1,left,top,mid_horiz,mid_vert,color);
//Recurse into upper right
QuadTreeDemo(depth-1,mid_horiz,top,right,mid_vert,color);
//Recurse into lower left
QuadTreeDemo(depth-1,left,mid_vert,mid_horiz,bottom,color);
//Recurse into lower right
QuadTreeDemo(depth-1,mid_horiz,mid_vert,right,bottom,color);
}
This is a log(n) algorithm and is very fast at VSD and collision detection.