/* * Laura Toma * csci 210 * * This is the skeleton of a program that solves the Towers-of-Hanoi * puzzle. */ import java.util.Scanner; public class Hanoi { private Peg peg1; private Peg peg2; private Peg peg3; private int n; // how many disks public Hanoi() { // Get the number of disks System.out.println("How many disks would you like? (positive number)"); Scanner r = new Scanner(System.in); // for reading n = r.nextInt(); assert(n >= 1); //create the 3 pegs peg1 = new Peg(n, "A"); peg2 = new Peg(n, "B"); peg3 = new Peg(n, "C"); // fill up the source peg with disks. A disk is just an // integer representing the size of the disk for (int i = n; i > 0; i--) peg1.addLast(i); } //start the game public void solve() { System.out.println("-------------------------------"); System.out.println("GOAL: move " + n + " disks from " + peg1.getName() + " to " + peg2.getName()); System.out.println("Pegs at start:"); peg1.print(); peg2.print(); peg3.print(); System.out.println("Here is the sequence of moves:"); System.out.println("-------------------------------"); move(peg1, peg2, peg3, n); System.out.println("\nPegs at end:"); peg1.print(); peg2.print(); peg3.print(); } public static void main(String args[]) { //start a new game Hanoi hanoi = new Hanoi(); // solve it hanoi.solve(); //that's it System.out.println("Done"); } //moves the top d disks from source to dest using tmp as //intermediate peg and print the sequence of moves public void move(Peg source, Peg dest, Peg tmp, int d) { //FILL YOUR CODE HERE } }