Hunt the Wumpus - Room Connection
<p>So I'm writing a version of the game <a href="http://en.wikipedia.org/wiki/Hunt%5Fthe%5FWumpus" rel="nofollow">Hunt the Wumpus</a> in C++. The only real difference is that I'm not worried about the cave having a dodecahedron shape.</p>

<p>So far I've implemented the creation of the cave and the random insertion of the hero, bat, wumpus, and pit.</p>

<pre><code>// Hunt the Wumpus

#include "std_lib_facilities.h"
#include "time.h"

class Room{
    bool is_occupied;
    bool has_wumpus;
    bool has_bat;
    bool has_pit;

public:
    Room()  // default constructor
    {
        is_occupied = false;
        has_wumpus = false;
        has_bat = false;
        has_pit = false;
    }

    void random_insert(vector&lt;Room&gt;&amp; v);
};

void Room::random_insert(vector&lt;Room&gt;&amp; v)
{
    srand(time(NULL));
    int random_room = 0;
    bool crowded = true;

    random_room = rand() % 20;  // insert hero
    v[random_room].is_occupied = true;

    while(crowded)  // insert...THE WUMPUS!
    {
        random_room = rand() % 20;
        if(v[random_room].is_occupied) ;
        else if(!v[random_room].is_occupied)
        {
             v[random_room].has_wumpus = true;
             crowded = false;
        }
    }

    crowded = true;
    while(crowded)  // insert bat
    {
        random_room = rand() % 20;
        if(v[random_room].is_occupied || v[random_room].has_wumpus) ;
        else if(!v[random_room].is_occupied &amp;&amp; !v[random_room].has_wumpus)
        {
             v[random_room].has_bat = true;
             crowded = false;
        }
    }

    crowded = true;
    while(crowded)  // insert pit
    {
        random_room = rand() % 20;
        if(v[random_room].is_occupied || v[random_room].has_wumpus || v[random_room].has_bat) ;
        else if(!v[random_room].is_occupied &amp;&amp; !v[random_room].has_wumpus &amp;&amp; !v[random_room].has_bat)
        {
             v[random_room].has_pit = true;
             crowded = false;
        }
    }
}

vector&lt;Room&gt; create(Room&amp; r)
{
    vector&lt;Room&gt; c;
    for(int i = 0; i &lt; 20; ++i)
        c.push_back(r);
    return c;
}

int main()
{
    Room r;
    vector&lt;Room&gt; cave = create(r);   // create cave
    r.random_insert(cave);    // randomly insert things

}
</code></pre>

<p>I've got a good idea of how I'm going to implement everything else with bats dropping the hero into random places, shooting, outputting current situation, etc.</p>

<p>However, I'm not sure how to deal with randomly connecting the rooms in the cave. I've considered doing some kind of random sort in the vector and then connecting the rooms to the left and right with pointers, but that is just a long hallway, not a cave. Maybe I could create some kind of coordinates system? Does anyone have any recommendations? Thanks.</p>
