Random Walk Code

It’s been a while since I’ve coded anything. I’ve been thinking about my old word game “1,000 Word Quest” and wanted to make a daily puzzle out of it like Circuit Board Square. Unfortunately, due to the nature of the puzzle, doing data-driven graphics seems impossible as the path you take to solve the puzzle is different for each puzzle.

So the code I wrote, which is extremely inefficient and relies on randomness to achieve the goal, will randomly walk a 3x3 grid to produce a path that will touch each circle once and only once, moving in orthogonal directions only.

var puzzleWidth = 3;
var puzzleHeight = 3;
var walkLength = puzzleWidth * puzzleHeight;
var walkCount = 1;
var walkArr1 = [0, 0, 0];
var walkArr2 = [0, 0, 0];
var walkArr3 = [0, 0, 0];
var walkArr = [walkArr1, walkArr2, walkArr3];
var directionArr = ["UL", "U", "UR", "L", "R", "DL", "D", "DR"];
var walkedArr = [];

var solutionTotal = 1;
var solutionCount = 0;

var errorLimit = 10;
var errorCount = 0;
var errorLog = 0;

var startX = 0;
var startY = 0;

var currentX = 0;
var currentY = 0;

function getRandomInt(max) {
    return Math.floor(Math.random() * Math.floor(max));
}

function setupArray() {

}

function updateText() {
    document.write("--- final walkArr #" + solutionCount + "---" + "<br>");
    document.write(walkArr[0] + "<br>");
    document.write(walkArr[1] + "<br>");
    document.write(walkArr[2] + "<br>");
    //document.write(walkArr[0][1]);
}

function createStartPoint() {
    // Create a start point for x and y
    // push that into the path array
    startX = getRandomInt(3);
    startY = getRandomInt(3);

    currentX = startX;
    currentY = startY;

    walkArr[currentY][currentX] = walkCount;

    walkCheck();
}

function walkCheck() {
    // walk a random direction:
    // 1. check if the next spot is open
    // 2. if it is, move to that spot. increase count by 1.
    var nextDirection = directionArr[getRandomInt(directionArr.length)];
    //console.log("nextDirection: " + nextDirection);
    switch (nextDirection) {
        case "UL":
            if ((currentY > 0) && (currentX > 0)) {
                walk(-1, -1);
            } else {
                walkCheck();
            }
            // check;
            break;
        case "U":
            if ((currentY > 0)) {
                walk(0, -1);
            } else {
                walkCheck();
            }
            // check;
            break;
        case "UR":
            if ((currentY > 0) && (currentX < 2)) {
                walk(1, -1);
            } else {
                walkCheck();
            }
            break;
        case "L":
            if ((currentX > 0)) {
                walk(-1, 0);
            } else {
                walkCheck();
            }
            break;
        case "R":
            if ((currentX < 2)) {
                walk(1, 0);
            } else {
                walkCheck();
            }
            break;
        case "DL":
            if ((currentY < 2) && (currentX > 0)) {
                walk(-1, 1);
            } else {
                walkCheck();
            }
            break;
        case "D":
            if ((currentY < 2)) {
                walk(0, 1);
            } else {
                walkCheck();
            }
            break;
        case "DR":
            if ((currentY < 2) && (currentX < 2)) {
                walk(1, 1);
            } else {
                walkCheck();
            }
            break;
    }
}

function walk(nextX, nextY) {
    /*
    console.log("------------");
    console.log("func: walk()");
    console.log("currentX: " + currentX);
    console.log("currentY: " + currentY);
    console.log("nextX: " + nextX);
    console.log("nextY: " + nextY);
    console.log("walkCount: " + walkCount);
    console.log("ErrorCount: " + errorCount);
    */

    if (walkCount <= walkLength) {
        if (walkArr[currentY + nextY][currentX + nextX] == 0) // if the next area is empty
        {
            walkCount++;
            walkArr[currentY + nextY][currentX + nextX] = walkCount;
            errorCount = 0;
            currentX = currentX + nextX;
            currentY = currentY + nextY;
            // updateText();

            walkCheck();
        } else {
            if (walkCount == walkLength) {
                console.log("-- complete #" + solutionCount + " --");
                solutionCount++;
                updateText();
                if (solutionCount < solutionTotal) {
                    resetPuzzle();
                }
            } else {
                if (errorCount < errorLimit) {
                    errorCount++;
                    walkCheck();
                } else {
                    console.log("-- dead end #" + errorLog + " steps #" + walkCount + "--");
                    errorLog++;
                    resetPuzzle();
                }
            }
        }
    }
}

function resetPuzzle() {
    walkCount = 1;
    walkArr1 = [0, 0, 0];
    walkArr2 = [0, 0, 0];
    walkArr3 = [0, 0, 0];
    walkArr = [walkArr1, walkArr2, walkArr3];
    createStartPoint();
}

//sayHello();
createStartPoint();

Sadie Cat and Mao Visual Novel

46407182_918492581690118_7778577087526338560_o.jpg

Been toying with the idea of having Sadie Cat and Mao present their stories in a format like a visual novel or dialogue scene from video games. That would actually be a lot of work to switch it up between things like a messaging app, an old Lucasarts style game, or even a modern day visual novel game.

While I figure that out I’ve been writing down jokes/ideas so I’ll have things to put pen to paper without having to sit there, staring at a blank screen, and thinking, “what is a funny joke…”.

Projects Analogy to Food and Drink

I was thinking about it the other day and have figured out the main three projects I’m focusing on can be described as follows:

  • Circuit Board Square is like coffee. It appears daily and is consistent in what it is. I used Excel and a little know-how to produce all the puzzles. Posts are automated through Later and post to Instagram, Facebook, and Twitter. It is what it is.

  • Shenbot Draws is like a piece of candy from a candy bowl. It’s a nice treat. Looks (tastes) nice and it’s nice to come into it now and then. You don’t need it to live, but it brightens up (hopefully) your day.

  • Sadie Cat and Mao is like a mystery stew. A lot of stuff goes into it and I’m toying with the recipe to this day. I don’t know who will like it it or order it off the menu at the end of the day. Will it be adults? Kids? Adults with kids? This is the hardest one to figure out and ultimately the most complicated.

Time to work on that soup.