Results 1 to 3 of 3

Thread: University Robot Project - *URGENT HELP Plez*

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    140

    University Robot Project - *URGENT HELP Plez*

    Code:
    /*
     * File:    Ex14.java
     * Created: 25 October 2004, 21:05
     * Author:  Hiren Shah
     */
    
    import uk.ac.warwick.dcs.maze.logic.IRobot;
    
    public class Ex14
    {
        public void controlRobot(IRobot robot) 
        
        {
      
        robot.look(IRobot.NORTH);
        
        NorthController(robot);
        }
        
      private byte isTargetNorth(IRobot robot)
      {
            byte result = 0;
            int a = robot.getLocationY();
            int b = robot.getTargetLocation().y;
            if (a>b) result = -1;
            else if (a<b) result = 1;
            else result = 0;
            return result;
      }
      
      private byte isTargetEast(IRobot robot)
      {
    	byte result = 0;
    	int a = robot.getLocationX();		
    	int b = robot.getTargetLocation().x;	
    	if (a>b) result = -1;			
    	else if (a<b) result = 1;		
    	else result = 0;			
    	return result;
      }
      
      private int NorthController(IRobot robot)
      {
           int direction = 0;	
           int randno;
       
           int d1 = isTargetNorth(robot);
           int d2 = isTargetEast(robot);  
        
        if (d1 == 1 & d2 == 0)
        {   do {
                direction = IRobot.AHEAD; 
               } while (robot.look(IRobot.AHEAD)!=IRobot.WALL);
        
            do {
                randno = (int) Math.round(Math.random()*3);
                
                if (randno == 0)
                    direction = IRobot.LEFT;
                else if (randno == 1)
                    direction = IRobot.RIGHT;
                else if (randno == 2)
                    direction = IRobot.BEHIND;
               } while (robot.look(IRobot.AHEAD)==IRobot.WALL);
        }
        
        else if (d1 == 1 & d2 == 1)
        {   do {
                randno = (int) Math.round(Math.random()*2);
                
                if (randno == 0)
                    direction = IRobot.AHEAD;
                else if (randno == 1)
                    direction = IRobot.RIGHT;
               } while ((robot.look(IRobot.AHEAD)!=IRobot.WALL) & (robot.look(IRobot.RIGHT)!=IRobot.WALL));
            
            do {
                direction = IRobot.AHEAD;
               } while ((robot.look(IRobot.AHEAD)!=IRobot.WALL) & (robot.look(IRobot.RIGHT)==IRobot.WALL));
            
            do {
                direction = IRobot.RIGHT;
               } while ((robot.look(IRobot.AHEAD)==IRobot.WALL) & (robot.look(IRobot.RIGHT)!=IRobot.WALL));
        
            do {
                randno = (int) Math.round(Math.random()*2);
                
                if (randno == 0)
                    direction = IRobot.LEFT;
                else if (randno == 1)
                    direction = IRobot.BEHIND;
               } while ((robot.look(IRobot.AHEAD)==IRobot.WALL) & (robot.look(IRobot.RIGHT)==IRobot.WALL));
        }
        
        else if (d1 == 1 & d2 == -1)
        {   do {
                randno = (int) Math.round(Math.random()*2);
                
                if (randno == 0)
                    direction = IRobot.AHEAD;
                else if (randno == 1)
                    direction = IRobot.LEFT;
               } while ((robot.look(IRobot.AHEAD)!=IRobot.WALL) & (robot.look(IRobot.LEFT)!=IRobot.WALL));
            
            do {
                direction = IRobot.AHEAD;
               } while ((robot.look(IRobot.AHEAD)!=IRobot.WALL) & (robot.look(IRobot.LEFT)==IRobot.WALL));
            
            do {
                direction = IRobot.LEFT;
               } while ((robot.look(IRobot.AHEAD)==IRobot.WALL) & (robot.look(IRobot.LEFT)!=IRobot.WALL));
        
            do {
                randno = (int) Math.round(Math.random()*2);
                
                if (randno == 0)
                    direction = IRobot.RIGHT;
                else if (randno == 1)
                    direction = IRobot.BEHIND;
               } while ((robot.look(IRobot.AHEAD)==IRobot.WALL) & (robot.look(IRobot.LEFT)==IRobot.WALL));
        }
        
        else if (d1 == 0 & d2 == 1)
        {   do {
                direction = IRobot.RIGHT;
               } while (robot.look(IRobot.RIGHT)!=IRobot.WALL);
        
            do {
                randno = (int) Math.round(Math.random()*3);
                
                if (randno == 0)
                    direction = IRobot.LEFT;
                else if (randno == 1)
                    direction = IRobot.AHEAD;
                else if (randno == 2)
                    direction = IRobot.BEHIND;
               } while (robot.look(IRobot.RIGHT)==IRobot.WALL);
        }
        
        else if (d1 == 0 & d2 == -1)
        {   do {
                direction = IRobot.LEFT;
               } while (robot.look(IRobot.LEFT)!=IRobot.WALL);
        
            do {
                randno = (int) Math.round(Math.random()*3);
                
                if (randno == 0)
                    direction = IRobot.RIGHT;
                else if (randno == 1)
                    direction = IRobot.AHEAD;
                else if (randno == 2)
                    direction = IRobot.BEHIND;
               } while (robot.look(IRobot.LEFT)==IRobot.WALL);  
        }
        
        else if (d1 == -1 & d2 == 1)
        {   do {
               randno = (int) Math.round(Math.random()*2);
               
               if (randno == 0)
                   direction = IRobot.BEHIND;
               else if (randno == 1)
                   direction = IRobot.RIGHT;
              } while ((robot.look(IRobot.BEHIND)!=IRobot.WALL) & (robot.look(IRobot.RIGHT)!=IRobot.WALL));
            
            do {
                direction = IRobot.BEHIND;
               } while ((robot.look(IRobot.BEHIND)!=IRobot.WALL) & (robot.look(IRobot.RIGHT)==IRobot.WALL));
            
            do {
                direction = IRobot.RIGHT;
               } while ((robot.look(IRobot.BEHIND)==IRobot.WALL) & (robot.look(IRobot.RIGHT)!=IRobot.WALL));
        
            do {
                randno = (int) Math.round(Math.random()*2);
                
                if (randno == 0)
                    direction = IRobot.LEFT;
                else if (randno == 1)
                    direction = IRobot.AHEAD;
               } while ((robot.look(IRobot.BEHIND)==IRobot.WALL) & (robot.look(IRobot.RIGHT)==IRobot.WALL));
        }
        
        else if (d1 == -1 & d2 == 0)
        {   do {
                direction = IRobot.BEHIND; 
               } while (robot.look(IRobot.BEHIND)!=IRobot.WALL);
        
            do {
                randno = (int) Math.round(Math.random()*3);
                
                if (randno == 0)
                    direction = IRobot.LEFT;
                else if (randno == 1)
                    direction = IRobot.RIGHT;
                else if (randno == 2)
                    direction = IRobot.AHEAD;
               } while (robot.look(IRobot.BEHIND)==IRobot.WALL);  
        }
        
        else if (d1 == -1 & d2 == -1)
        {   do {
                randno = (int) Math.round(Math.random()*2);
                
                if (randno == 0)
                    direction = IRobot.BEHIND;
                else if (randno == 1)
                    direction = IRobot.LEFT;
               } while ((robot.look(IRobot.BEHIND)!=IRobot.WALL) & (robot.look(IRobot.LEFT)!=IRobot.WALL));
            
            do {
                direction = IRobot.BEHIND;
               } while ((robot.look(IRobot.BEHIND)!=IRobot.WALL) & (robot.look(IRobot.LEFT)==IRobot.WALL));
            
            do {
                direction = IRobot.LEFT;
               } while ((robot.look(IRobot.BEHIND)==IRobot.WALL) & (robot.look(IRobot.LEFT)!=IRobot.WALL));
        
            do {
                randno = (int) Math.round(Math.random()*2);
                
                if (randno == 0)
                    direction = IRobot.RIGHT;
                else if (randno == 1)
                    direction = IRobot.AHEAD;
               } while ((robot.look(IRobot.BEHIND)==IRobot.WALL) & (robot.look(IRobot.LEFT)==IRobot.WALL));
        }
           return direction;
      }
    }
    Can anyone see anything wrong with that?

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    hshah. Please be specific. Does the code compile? If not what errors are you getting?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    140
    It all compiles fine, but it does not work!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width