JSFiddle - React, Tailwind, and code Playground

by eTiger13

JavaScript

$('.move').live(
            'click',
            function ()
            {
                // If the solver isn't running, make a manual move.
                if (!running)
                {
                    console.log(parseInt($(this).data('tower'));
                    move(parseInt($(this).data('tower')));
                }
            }
        );

function move(tower, undoing, redoing, restoring)
{

    if (solved)
    {
        setup();
        return;
    }
    tower = cycle(tower);
    /*
    If no manual moves have been made up to this point, store the current
    number of moves.
    */
    if (!manual.length)
    {
        oldmoves = moves;
    }
    // If a disk has been popped off a tower
    if (popped)
    {
        var color = new_color(popped, undoing);
        if (!can_move(popped, tower, undoing))
        {
            // Show an error message with the real tower numbers.
            alert('Invalid move: ' + (popped.tower + 1) + '-' + (tower + 1));
            stop(true);
            // Place the disk on the tower it came from.
            tower = popped.tower;
        }
        /*
        Else, if the move is different tower than the one it was popped off
        from
        */
        else if (popped.tower != tower)
        {
            // Adjust the color.
            popped.color = color;
            if (undoing)
            {
                // Reduce the number of moves accordingly.
                moves--;
                if (!restoring)
                {
                    // Add this move to a list of moves that can be redone.
                    redo.push(popped.tower);
                    redo.push(tower);
                }
            }
            else
            {
                // Increase the number of moves accordingly.
                moves++;
                // Add this move to a list.
                list.push(popped.tower);
                list.push(tower);
                if (!redoing)
                {
         ...