Index: trunk/code/projects/traffic_navigation/mapping.c
===================================================================
--- trunk/code/projects/traffic_navigation/mapping.c	(revision 1986)
+++ trunk/code/projects/traffic_navigation/mapping.c	(revision 1987)
@@ -17,9 +17,10 @@
  * placed somewhere randomly on the map in the middle of the road*/
 char driveToNextInt(){
         char barcode; 
-        
+
+        /* Keep driving until we see a barcode */
         do {
-            barcode = (char) doDrive(200);
+                barcode = (char) doDrive(200);
         } 
         while(barcode < 0); /* Condition codes are all neg. */
 
@@ -42,8 +43,9 @@
 
         turn(type, direction);
 
+        /* Keep driving until we see a barcode */
         do {
-            barcode = (char) doDrive(200);
+                barcode = (char) doDrive(200);
         }
         while(barcode < 0); /* Condition codes are all neg. */
 
@@ -51,7 +53,7 @@
 
         newEdge->to = barcode;
         newEdge->dist = time;
-        
+
         return barcode;
 }
 
@@ -58,104 +60,93 @@
 /* This function performs mapping */
 int createMap(){
 
-    int seenout_count = 0;			/* The number of intersections we have completely seen */
+        char seen[NUM_FEATURES];		/* Have we been at this intersection before*/
+        char seenout[NUM_FEATURES];		/* Have we seen the outoging edges of this intersection? */
 
-    char seen[NUM_FEATURES];		/* Have we seen this node? */
-    char seenout[NUM_FEATURES];		/* Have we seen the outoging edges of this node? */
+        char seenall[NUM_FEATURES];     /* This is how the array should look like once we have
+                                         * seen everything */
 
-    int outEdges, currInt, chosenDir;
+        int outEdges, currInt, chosenDir, i;
 
-    initGraph(seen, seenout);
+        /* Initialize the graph to all zeros */
+        initGraph(seen, seenout);
 
-    /* Drives to the nearest intersection */
-    char barcode = driveToNextInt();
+        /* When we see all the outgoing edges for the intersections, 
+         * seenout will look as follows */
+        for(i=0; i<NUM_FEATURES; i++) 
+                seenall[i] = 1;
 
-    while(seenout_count < NUM_FEATURES)
-    {
-         currInt = getIntersectNum(barcode);
-         seen[currInt] = 1;
-    
-         /* Get the number of outgoing edges */
-         outEdges = getNumOut(getIntersectType(currInt));
+        /* First drives to the nearest intersection */
+        char barcode = driveToNextInt();
 
-        /* Randomly choose an outgoing edge that we have not seen to go down 
-         * if no such edge exists */
-        // TODO: include the appropriate header file for rand()
-        chosenDir = rand() % outEdges;
 
-        /* We have not seen all the outgoing edges */
-        if(!seenout[currInt]){
-            intersections[currInt].outSeen++;
-            /* We have finished seeing all outgoing edges of the intersection */
-            if(intersections[currInt].numOut == intersections[currInt].outSeen){
-                seenout[currInt] = 1;
-                seenout_count ++;
-            }
+        /* Randomly traverses the graph until all edges are seen */
+        while(seenout !=  seenall)
+        {
+                currInt = getIntersectNum(barcode);
+                seen[currInt] = 1;
+
+                /* Get the number of outgoing edges */
+                outEdges = getNumOut(getIntersectType(currInt));
+
+                /* Assign the number of outgoing edges for the current int */ 
+                intersections[currInt].numOut = outEdges;
+
+                /* Randomly choose an outgoing edge that we have not seen to go down 
+                 * if no such edge exists */
+                chosenDir = rand() % outEdges;
+
+                /* We have not seen all the outgoing edges for the intersection we are at */
+                if(!seenout[currInt]){
+                        intersections[currInt].outSeen++;
+                        /* We have finished seeing all outgoing edges of the intersection */
+                        if(outEdges == intersections[currInt].outSeen){
+                                seenout[currInt] = 1;
+                        }
+                }
+                
+                /* Traverses edge, stores information in struct */
+                //TODO: Does the chosendDir, correspond with what is in Priya's Code?
+                //A number between 0 and the number of outgoing edges ?
+                createEdge(&(intersections[currInt].outgoingEdges[chosenDir]),
+                                getIntersectType(currInt), chosenDir);
         }
-        /* Traverses edge, stores information in struct */
-        createEdge(&(intersections[currInt].outgoingEdges[chosenDir]),
-                    getIntersectType(currInt), chosenDir);
-    }
 
-/* We are done traversing send the graph to the robots */
-sendIntersectionGraph();
+        /* We are done traversing send the graph to the robots */
+        while(1) sendIntersectionGraph();
 
-
-return 0;
+        return 0;
 }
 
 /* Initializes the elements in the graph to 0 */
 void initGraph(char* seen, char* seenout){
 
-    int i;
+        int i, j;
 
-    /* Initialize all of these arrays */
-    for(i = 0; i<NUM_FEATURES; i++) {
-            seen[i] = 0;
-            seenout[i] = 0;
-            intersections[i].type = 0;
-            intersections[i].intNum = 0;
-            intersections[i].numOut = 0;
-            intersections[i].outSeen = 0;
-            intersections[i].outgoingEdges[0].to = 0;
-            intersections[i].outgoingEdges[0].dist = 0;
-            intersections[i].outgoingEdges[1].to = 0;
-            intersections[i].outgoingEdges[1].dist = 0;
-            intersections[i].outgoingEdges[2].to = 0;
-            intersections[i].outgoingEdges[2].dist = 0;
-            intersections[i].outgoingEdges[3].to = 0;
-            intersections[i].outgoingEdges[3].dist = 0;	
-    }
+        /* Set all graph storge elements to 0 */
+        for(i = 0; i<NUM_FEATURES; i++) {
+                seen[i] = 0;
+                seenout[i] = 0;
+                intersections[i].type = 0;
+                intersections[i].intNum = 0;
+                intersections[i].numOut = 0;
+                intersections[i].outSeen = 0;
+                for(j = 0; j<4; j++){
+                        intersections[i].outgoingEdges[0].to = 0;
+                        intersections[i].outgoingEdges[0].dist = 0;
+                }
+        }
 }
 
 
 /* Given an intersection type, returns the number of outgoing edges */
 int getNumOut(int type) {
-    switch(type){
-        case 0: return 3;
-        case 1: return -1;
-        case 2: return -1;
-        case 3: return 3;
-        case 4: return 2;
-    }
-    return -1;
+        switch(type){
+                case 0: return 3;
+                case 1: return -1;
+                case 2: return -1;
+                case 3: return 3;
+                case 4: return 2;
+        }
+        return -1;
 }
-
-/* 
- * Drives to the next intersection and returns its ID
- * If we are at a dead end, returns -1
- */
-int nextInt(){
-        return 0;
-}
-
-
-/*
- * Given an intersection node returns an integer that
- * can be sent wirelessly
- *
- */
-int encodeNode(node n){
-        return 0;
-}
-
