import java.util.Scanner;

/**
 * Print the steps required to solve the towers of Hanoi problem for any size.
 *
 * @author Mark Young (A00000000)
 */
public class SimpleHanoi {

    /** The total number of moves made so far */
    private static int numMoves = 0;

    public static void main(String[] args) {
        // introduce yourself
        System.out.print("\n\n"
                + "Simple Hanoi\n"
                + "----------\n\n"
                + "This application tells you how to solve "
                + "the Towers of Hanoi problem.\n\n");

        // get the number of disks from the user
        Scanner kbd = new Scanner(System.in);
        System.out.print("How many disks? ");
        int numDisks = kbd.nextInt();
        kbd.nextLine();

        // show all the moves required
        showMoves(numDisks, "A", "C", "B");

        // report the total number of moves made
        System.out.print("\n"
                + "Total moves: " + numMoves + "\n\n");
    }

    /**
     * Show all the moves required to solve the towers of Hanoi problem.
     *
     * @param numDisks     the number of disks needing to be moved
     * @param start     the name of the starting peg
     * @param finish     the name of the ending peg
     * @param extra     the name of the extra peg
     */
    private static void showMoves(int numDisks, 
            String start, String finish, String extra) {
        // if there are any disks to move
        if (numDisks > 0) {
            // show how to move the smaller disks out of the way
            showMoves(numDisks - 1, start, extra, finish);

            // show moving the base disk to its final position
            System.out.printf("Move top disk from %s to %s.\n", start, finish);

            // count that move
            numMoves++;

            // show how to move the smaller disks back on top of the base
            showMoves(numDisks - 1, extra, finish, start);
        }
    }
}
