1. 37

My older kid loves mazes…that combined with the fact that I haven’t written code just for fun in far too long resulted in this: a maze generator in Go, compiled to WebAssembly, that generates printable mazes.

It’s nothing fancy, it’s just a fun weekend project. (Also, and this is patently obvious: my HTML, JavaScript, and design skills are terrible…)

  1. 11

    If you like mazes, there’s an excellent resource: Mazes for Programmers - Usually this is a book I choose to gift to friends of mine who can write code.

    1. 4

      That book is wonderful.

    2. 7

      At the chance of having missed it, is the source code available somewhere?

      1. 1

        Getting it cleaned up and on GitHub will be next weekend’s project. :)

      2. 4

        It’s nothing fancy, it’s just a fun weekend project. (Also, and this is patently obvious: my HTML, JavaScript, and design skills are terrible…)

        I actually miss the time when many websites looked like this. It was a good indicator nthat the site was there because of its content. Not because of the looks.

        It does what it need to do. Visual design is secondary.

        1. 3

          For my thesis, I programmed Ariadne, a tool for teaching (maze) algorithms to students. It allows you to generate and maze and then visually program an algorithm that tries to find a path to a given target.

          If you want to give it a try, click on “Generate a maze” on the left. Then choose the menu item “Algorithm” > “Load Simple Ariadne Thread Algorithm” and press the “Play” button in the top right.

          1. 3

            If you want the pages to be printable, I’d recommend adding a @media print rule to hide the generator box.

            1. 2

              Interested to hear more about the garbage collector story when compiling Go to WASM. How does that work?

              1. 2

                Tangential, but when you compile Go to webassembly, does it compile the garbage collector with it?

                1. 6

                  I asked myself the same question and I used the wabt toolkit and its excellent wasm2c tool to decompile OP’s maze generator. Yes, it does seem to embed Go’s GC:

                    static u32 w2c_runtime_gcSetTriggerRatio(u32);
                    static u32 w2c_runtime_gcEffectiveGrowthRatio(u32);
                    static u32 w2c_runtime_gcWaitOnMark(u32);
                    static u32 w2c_runtime_gcTrigger_test(u32);
                    static u32 w2c_runtime_gcStart(u32);
                    static u32 w2c_runtime_gcMarkDone(u32);
                    static u32 w2c_runtime_gcMarkTermination(u32);
                    static u32 w2c_runtime_gcBgMarkStartWorkers(u32);
                    static u32 w2c_runtime_gcBgMarkWorker(u32);
                    static u32 w2c_runtime_gcMarkWorkAvailable(u32);
                    static u32 w2c_runtime_gcMark(u32);
                    static u32 w2c_runtime_gcSweep(u32);
                    static u32 w2c_runtime_gcResetMarkState(u32);
                    static u32 w2c_runtime_clearpools(u32);
                    static u32 w2c_runtime_fmtNSAsMS(u32);
                    static u32 w2c_runtime_gcMarkRootPrepare(u32);
                    static u32 w2c_runtime_gcMarkRootCheck(u32);
                    static u32 w2c_runtime_markroot(u32);
                    static u32 w2c_runtime_markrootBlock(u32);
                    static u32 w2c_runtime_markrootFreeGStacks(u32);
                    static u32 w2c_runtime_markrootSpans(u32);
                    static u32 w2c_runtime_gcAssistAlloc(u32);
                    static u32 w2c_runtime_gcAssistAlloc1(u32);
                    static u32 w2c_runtime_gcWakeAllAssists(u32);
                    static u32 w2c_runtime_gcParkAssist(u32);
                    static u32 w2c_runtime_gcFlushBgCredit(u32);
                  
                2. 1

                  It seems to take just over a second to generate/render a 200x200 maze for me.

                  I’d love to know where the bottlenecks are – I’m v. interested in Go/Wasm.

                  1. 2

                    The lion’s share of the time is spent encoding the image to PNG to export from WASMland to JSland. I added an option to turn off PNG compression, that speeds things up considerably.

                    I think if I sent a display list to JSland and had it draw on a canvas, it would be faster but I wrote this first for the command line and just had it save images.

                    1. 2

                      Me too, Golang compiled WebAssembly isn’t inherently slow.

                      You might be interested in this roguelike game written in Golang that has been compiled for wasm and is playable in the browser here https://harmonist.tuxfamily.org/play/index.html