import Robot.*;

public class hanoi {    
    
    	private Microbot    robot = new Microbot("COM1");   
    	int towersize=3;
	double puckdiameter=0.45;
	int counter=0;
	double spacing=1.45;
	Location spokes[];
     	

	//COMPILER GENERATED CODE; DO NOT MODIFY
	Location highPoint = new Location(7.0,0.0,7.0,-90.0,0.0,"highPoint");
	Location A = new Location(10.55,5.2,7.75,0.0,0.0,"A");
	Location C = new Location(10.45,-5.3,7.75,0.0,0.0,"C");
	Location B = new Location(10.48,0.0,7.75,0.0,0.0,"B");
	//COMPILER GENERATED CODE; DO NOT MODIFY

	public hanoi() {
		spokes=new Location[3];
		spokes[0]=A;
		spokes[1]=B;
		spokes[2]=C;
		
		robot.move(highPoint);
		
		//calibrate(C);
		solve(towersize,1,0,2);		
		
		robot.move(highPoint);
		robot.ready();
	  	robot.closePort();        
    }

private void calibrate(Location loc) {
		robot.movet(loc,2);
		robot.depart(-spacing);
		robot.depart(-spacing);
		robot.grasp();
		robot.open();
		robot.depart(spacing);
		robot.depart(spacing);
}

private void solve(int n, int source, int auxil, int dest) {
		if (n==0) return;
		solve(n-1,source, dest, auxil);
		movedisc(source,dest);
		solve(n-1,auxil,source,dest);
};

private void movedisc(int source, int dest) {
		robot.move(spokes[source]);
		robot.open();
		robot.depart(-spacing);
		lift();
		robot.depart(spacing);
		robot.move(spokes[dest]);
		robot.depart(-spacing);
		robot.open();
		robot.depart(spacing);		
		counter++;
};

private void lift() {
		robot.depart(-spacing);
		if (robot.grasp()<puckdiameter) {
			robot.open();
			lift();
		};
		robot.depart(spacing);
};
    
    public static void main(String args[]) {new hanoi();};
}
