/**
 * A Robot Steeple-Chase (based on CS112 Project 1, 2008)
 * 
 * @author Russell C. Bjork 
 * @version March 3, 2008
 */
import kareltherobot.*;
import objectdraw.*;

public class RobotRace implements Directions
{
    // The number of racers, width of each robot's "lane"
    
    private static final int NUMBER_OF_RACERS = 3;
    private static final int LANE_WIDTH = 7;
    
    /** Main method - set up the world and start the program
     */
    public static void main(String [] args)
    { 
        World.readWorld("SteepleRace.kwld");
        World.setVisible(true);
        
        // Create the robots.  Start each on a different street
        
        RacerRobot [] racer = new RacerRobot[NUMBER_OF_RACERS];
        
        // Create them all before starting any to give them all a fair start
        
        for (int i = 0; i < NUMBER_OF_RACERS; i ++)
            racer[i] = new RacerRobot(i * LANE_WIDTH + 1, 1, East, 0);
            
        for (int i = 0; i < NUMBER_OF_RACERS; i ++)
            World.setupThread(racer[i]); 
            
        World.setTrace(false);
        World.showSpeedControl(true);
    }
    
    /** Pause a robot for a random period of time.
     */
    public static void randomPause()
    {
        try
        {
            Thread.sleep(randomGenerator.nextValue());
        }
        catch(InterruptedException e)
        {  }
    }
    
    private static RandomIntGenerator randomGenerator = 
        new RandomIntGenerator(RacerRobot.MIN_OPERATION_MS, 
                               RacerRobot.MAX_OPERATION_MS);
}