public void legalMove(Peg a, Peg b) {
        int diskOnA;
        int diskOnB;

        // get the top disk from the Peg a
        try {
            diskOnA = a.disks.peek();
        }
        catch (EmptyStackException ex) {
            diskOnA = -1;
        }

        // get the top disk from the Peg b
        try {
            diskOnB = b.disks.peek();
        }
        catch (EmptyStackException ex) {
            diskOnB = -1;
        }

        TowersOfHanoi.moveCount++;

        if (diskOnA > diskOnB) {
            // move disk from a to b
            TowersOfHanoi.addLog(String.format("%4d. Perkeliamas %d diskas nuo %s ant %s\n", TowersOfHanoi.moveCount, a.getTopDiskNo(), a.name, b.name));
            b.disks.push(a.disks.pop());
        }
        else {
            // move disk from b to a
            TowersOfHanoi.addLog(String.format("%4d. Perkeliamas %d diskas nuo %s ant %s\n", TowersOfHanoi.moveCount, b.getTopDiskNo(), b.name, a.name));
            a.disks.push(b.disks.pop());
        }
    }