TowelSniffer / Anki-go

A go template for Anki
GNU General Public License v3.0
16 stars 1 forks source link

Randomised responses #3

Open TowelSniffer opened 1 year ago

TowelSniffer commented 1 year ago

I would like to have the puzzle be able to randomly choose lines to respond with.

trdischat commented 1 week ago

I think I may have figured this one out. Make these changes to the FRONT template:

function navigate(x, y, shiftKey) {
    var i, move,
        children = current.children;

    // Look for move at same location in children
    for (i = 0; i < children.length; i++) {
        move = children[i].move;
        if (move && move.x === x && move.y === y) {
            current = children[i]; // Navigate to child if found
            // Notify navigation (with no tree edits)
            notifyListeners({
                navChange: true
            });
            document.getElementsByClassName("besogo-diagram")[0].style.pointerEvents = "none";
            var myTimeout = setTimeout(nextMove, 200, current.children.length);
            return true;
        }
    }
    if (!solvedState) {
        errorCount++;
        if (errorCount === handicap) {
            errorCount = 0;
            nextMove(current.children.length);
            var myTimeout = setTimeout(nextMove, 200, current.children.length);
        }
        solvedColour = "#670A0A";
        if (Persistence.isAvailable()) { Persistence.setItem("solvedColour", solvedColour); };
    }
    return false;
}
function nextMove(siblings=1) {
    sibling = Math.floor(Math.random()*siblings);
    document.querySelector('[title="Next node"]').click();
    for (let i = 0; i < sibling; i++) {
        document.querySelector('[title="Next sibling"]').click();
    }
    document.getElementsByClassName("besogo-diagram")[0].style.pointerEvents = "auto";
}

P.S. My version of navigate above has also been modified to pass solvedColour rather than errorCheck to the BACK template. See my comments in #8.