Comments on Some Robi Code

Alg-3-A

 

Local variables (outer do loop):

   environs: The node-neighborhood pair returned by Environment code

                   Example: (10 (T nil T T))

                   On each iteration is value returned by whereami?

   cNodes: The set of completed nodes

                        On 1st iteration is the empty set

                   On subsequent iterations curNode is adjoined to it

   curNode: The current node = 1st element of environs

                   On each iteration is calculated from environs

   eNodes: The set of nodes robot has encountered

                   On 1st iteration is a list containing the current node

                   On subsequent iterations it gets its updated value in loop body

   myworld: The map of the world that the robot is making

                   On 1st iteration it is a list containing the current nodes environs

                   On subsequent iterations its value is updated in loop body

 

Exit Test (outer do loop):

   When the set of completed nodes is the same as the set of known nodes (in other words, all nodes have been completed (fully explored))

Action (outer do loop):

1.     Set/update local variables

2.     Execute inner do loop

3.     Execute moveToCuNode

Return Value (outer do loop):

   The map of the world that robot has constructed

  

Local variables (inner do loop):

   moves: The set of hallways available to move to at the current position

                   Example: (T nil T T)

                   On 1st iteration (and all subsequent ones) it is the 2nd of environs;

   direction: Direction to move to from curNode to next neighboring node

                        On 1st iteration is given by call to 1stGood with parameter of 0

                   On subsequent iterations:

      given by call to 1stGood with parameter of last direction+1

     neighEnvirons: The environs of the node to which robot moved

   reachedNode: The neighboring node to which robot moved;

given as 1st of neighEnvirons.

 

Exit Test (inner do loop):

   When the direction is >= 4 [that means we have checked all neighbors]

Action (inner do loop):

1.     If we have reached a new node, add node to eNodes and environs information to myworld.

2.     Record the fact that the new node is a neighbor of curNode

3.     Move robot back to curNode

Return Value (inner do loop):

   Nothing is returned, since the information gleaned has already been recorded.

 

(defun run ()

    (do* ((environs (whereami?)(whereami?))

          (cNodes nil (adjoin curNode cNodes))

          (curNode (curNodeOf environs)(curNodeOf environs))

          (eNodes (list curNode) eNodes)

          (myworld (list environs) myworld)

         )

             ((sameset eNodes cNodes) myworld)

        (do* (        (moves (2nd environs) moves)

                (direction   (1stGood moves 0)

(1stGood moves (1+ direction)))

                (neighEnvirons (moveRobi direction)(moveRobi direction))

                (reachedNode (curNodeOf neighEnvirons)

    (curNodeOf neighEnvirons))

                )

               ((>= direction 4) nil)

             (unless (member reachedNode eNodes)

                        (setf eNodes (cons reachedNode eNodes))

                        (setf myworld (cons neighEnvirons myworld))

             )

             (setf myworld

    (recordInfo curNode reachedNode direction myworld))

             (moveRobi (oppDir direction))

        )

        (moveToCUnode curNode

eNodes

(cons curNode cNodes) myworld)

    )

)

 

Function: 1stGood

Parameters:

   moves: The set of hallways

                   Example: (T nil T T)

   n: The position at which to begin looking

Exit Test:

   The value of n is at a position beyond the number of possible hallways

Action (inner do loop):

1.     If the value of n is too large, return nil

2.     If there is a T at the nth position, return n.

3.     Otherwise, call itself recursively with n+1.

[Note: Do not change the value of moves]

Result:

   Returns the position of the next unexplored hallway or else nil.

 

(defun 1stGood (moves n)

  (cond ((>= n (length moves)) n)

           ((nth n moves) n)

           (t (1stGood moves (1+ n)))

))

 

Function: curNodeOf

Parameters:

   e: The environs of a node

                   Example: (10 (T nil T T))

Returns:

   The node part of environs

                   Example: 10

 

(defun curNodeOf (e)(1st e))

 

 

[Note: more comments to come]