private boolean recursive(Peg x, Peg y, Peg z, int n) {
        Action newAction = null;
        if (n > 0) {

            newAction = new Action(x, z, y, getCurrAction(), 1, n-1);
            actions.push(newAction);
            if (!TowersOfHanoi.repaintAndWait()) {return false;}

            // move n-1 disks from x to z
            recursive(x, z, y, n - 1);

            actions.pop();
            if (!TowersOfHanoi.repaintAndWait()) {return false;}

            newAction = new Action(x, y, z, getCurrAction(), 2, -1);
            actions.push(newAction);
            if (!TowersOfHanoi.repaintAndWait()) {return false;}

            TowersOfHanoi.moveCount++;

            // move top disk from x to y
            TowersOfHanoi.addLog(String.format("%4d. Perkeliamas %d diskas nuo %s ant %s\n", TowersOfHanoi.moveCount, x.getTopDiskNo(), x.name, y.name));
            y.disks.push(x.disks.pop());

            if (!TowersOfHanoi.repaintAndWait()) {return false;}
            actions.pop();
            if (!TowersOfHanoi.repaintAndWait()) {return false;}

            newAction = new Action(z, y, x, getCurrAction(), 3, n-1);
            actions.push(newAction);
            if (!TowersOfHanoi.repaintAndWait()) {return false;}

            // move n-1 disks from z to y
            recursive(z, y, x, n - 1);

            actions.pop();
            if (!TowersOfHanoi.repaintAndWait()) {return false;}
        }

        return true;
    }