DEV Community

Cover image for I Ported Sudoku to Your URL Bar and It Plays like a Dream
Andrew Healey
Andrew Healey

Posted on • Updated on • Originally published at healeycodes.com

I Ported Sudoku to Your URL Bar and It Plays like a Dream

Zero refreshes required. This is Sudoku as you've never seen it. Away from the prying eyes of your co-workers and your boss. Powered by the dark arts of window.location.hash. So powerful that just loading the page will cause your browser's history to rue the day.

Secret Sudoku

Playable right here, Secret Suduko unlocked a series of unique experiences for me. It's not every day that you find yourself brute forcing a 19th-century newspaper puzzle. Or, better yet, getting Travis CI to do it for you.

test('app plays without error', () => {
    const game = main(this, sudoku);
    game.startGame();
    for (let i = 0; i < 20000; i++) {
        // 0-81, 0-9
        if (game.play(Math.floor(Math.random() * 82), Math.floor(Math.random() * 10)) === true) {
            /* This test will usually complete the game six times over,
               adjust the difficulty randomly on completion */
            game.startGame(Math.floor(Math.random() * 6));
        };
    }
});

It turns out that all you need are some emotes, a few eventlisteners, and a dream. Many thanks to Rob McGuire-Dale and his wonderful Sudoku generator/solver.

// Main render functions
this.squaresFilled = () => this.board.join('').match(/[^.]/g).length
this.completeness = () => `${this.squaresFilled()}/81`;
this.start = () => `Secret_Sudoku_~_${this.completeness()}_~_row:`;
this.render = (extra = '') => {
    window.location.hash = `${this.start()}${this.rowMap[this.row]}__${this.prettifyRow(this.currRow(), this.cursor)}${extra}`;
}

Secret Sudoku is the perfect project to work on to help me relax in the evenings. It makes programming feel far more fun than logic abstraction should. Taking pull-requests today and every day hereafter.

GitHub logo healeycodes / secret-sudoku

Play Sudoku in your browser's URL bar! 🎲 πŸ€„

Build Status

Secret Sudoku

Hidden from prying eyes..

secret-sudoku

Play the classic game of Sudoku in your URL bar!

A Sunday project, powered by window.location.hash and β˜•

Avaliable @ https://healeycodes.github.io/secret-sudoku/


Install

npm install

Test

npm test

  • Uses Jest to test main functions and brute-force play the game to completion on different difficulties.

  • On GitHub, uses continious integration powered by Travis CI!

Deploy

Place the project files at the directory you wish you host the game (assuming HTTP/S).

For local-use, just open index.html


Join 150+ people signed up to my newsletter on programming and personal growth!

I tweet about tech @healeycodes.

Oldest comments (2)

Collapse
 
gabrielecimato profile image
Gabriele Cimato

Hey this is a very near project! How did you come up with this? I'm so fascinated by its simplicity, well done!

Collapse
 
healeycodes profile image
Andrew Healey

I just love the interactive web! My first idea was cloning an arcade game :)