Computer Science II --- Haas --- Karel Project sortBot

Objective: Create a Karel J Robot program which sorts piles of beepers!

Use the code below as a starting point.

Below is an example of  sort world before sorting.

Below is an example of  sort world after sorting.



/**
 * <<< This code is NOT complete >>>
 * SortBot should move two robots back and forth along a row 
 * and sort piles of beepers.
 * 
 * Complete the methods below to make the robots sort!
 */
import kareltherobot.*;

class SortBot extends Robot implements Directions
{   
    public SortBot()    {   
      super(1,1,North,0);
    }
  
    public SortBot(int street, int avenue, Direction dir, int numberOfBeepers)    {   
      super(street, avenue, dir, numberOfBeepers);
    }
 
    /*** makes robot world display ***/
    public void showWorld() {
        World.setVisible(true);  // Makes world display
        World.setDelay(1);     // pause for 1/100 second between robot actions
        World.readWorld("sort.wld");  // Define world
    }

    /** 
     * moves a robot noth one space
     */
    public void moveNorth() {
        while(!facingNorth()) {
            turnLeft();
        }
        move();
    }
    
    /** 
     * moves a robot east one space
     */
    public void moveEast() {
        while(!facingEast()) {
            turnLeft();
        }
        move();
    }
    
    /**
     * moves a robot west one space
     */
    public void moveWest() {
        while(!facingWest()) {
            turnLeft();
        }
        move();
    }
   
    /*** <<< THIS CODE IS NOT COMPLETE >>>
     * This method has a robot count the number of beepers
     * in a pile.  I then puts the beepers back down
     * and returns the number counter.
     ***/
    public int countBeepers()
    {

        /*** <<< COMPLETE THE CODE >>> ***/
                
    }

    /**  <<< THIS CODE IS NOT COMPLETE >>>
     * picks up all of the beepers in a pile
     */
     public void pickAllBeepers() {
         
        /*** <<< COMPLETE THE CODE >>> ***/
        
     }

    /**  <<< THIS CODE IS NOT COMPLETE >>>
     * puts down all beepers that a robot is holding
     */
    public void putAllBeepers() {

        /*** <<< COMPLETE THE CODE >>> ***/

     }
     
    /**  <<< THIS CODE IS NOT COMPLETE >>>
     *  moves a robot back to position 1,1
     */
    public void goHome() {
        
        /*** <<< COMPLETE THE CODE >>> ***/
        
    }
    
    /** <<< THIS CODE IS NOT COMPLETE >>>
     *  This method makes two robots move back and forth along 
     *  a row of beepers swaping piles until all of the 
     *  piles of beepers are in sotted order
     */
    public void sortBeepers(SortBot other) {
        
        /*** <<< COMPLETE THE CODE >>> ***/
        
    }
    

   /***  <<< THIS CODE IS NOT COMPLETE >>>
     * This method makes two robots next to each other
     * pick up the piles of beepers they are on and 
     * swap them with the robot next to them
     */
    public void swapBeepers(SortBot other) {
        
                
        /*** <<< COMPLETE THE CODE >>> ***/
       
      }
}

/**** ADD OTHER METHODS AS NEEDED *****/




/************************************************************
***  This code is complete:
***  It creates two robots A and B, and starts them out 
***  with no beepers at position 1,1.
***  Robots A and B then sort a line of Beepers
*************************************************************/
import kareltherobot.*;
 
public class SortBotTester implements Directions
{
    public static void main(String args[]) 
    {
        SortBot A = new SortBot(1,1,North,0);
        A.showWorld();
        SortBot B = new SortBot(1,1,North,0);
        A.sortBeepers(B);
        A.moveNorth();
        B.moveNorth();
    }
}