After a long hiatus of not many side-projects, partially because I haven't had much of a drive for extra-work projects, also because I've been learning violin, I have found a project that I wish to see to completion: using Rust and WebAssembly to show a replay of thousands of Go games simultaneously, inside of a browser. I'm curious what the visual result will look like, and I want to get more practice using Rust in a web browser. My setup is simple enough: A minimal webpack project that uses wasm-pack as a webpack plugin to auto-compile and reload rust code into the browser, and I'm very pleased with how fast everything is: less than a second for full compilation.

Sep 8 2020, Tuesday: Go Games Swarm: Beginnings of UI

Building without a framework is something I find to be a useful challenge, because it forces me to think about the basic structure and breakdown of a soon-to-be-complex application without the help of libraries of frameworks. In a live rendering application like the parallel Go game replayer I'm building, I want to separate the App state from the UI details at least, because I'm anticipating wanting a fast update path for drawing points at a time without re-drawing the entire canvas every frame. I'll of course need a way to redraw when the canvas size changes, but all in due time.

For now, I've made a good deal of progress in getting a grid sized correctly (19x19 pixels is pretty small on a moniter these days) based on the canvas size within the browser window, set to fill the entirety of a web page. Still rough, but very definitely forward progress:

Preview of the canvas with cell rectangles

Sep 11 2020, Friday: Go Games Swarm: Sgf files

One challenge with this project is to access the thousands of Go game files that I plan on replaying, saved in a common format called "SGF", or Smart Game Format, most commonly used for saving Go games. Given that this is a web project, and a web api to access a native file system doesn't seem very stable right now (but is being worked on), and I didn't feel like using Electron for a project like this at the present time, the easiest workable approach I can think of is to use the Rust macro include_str!() to embed the contents of many Sgf files inside the WebAssembly bundle itself. It helps that the text-based files are minimal and small; embedding about 20,000 of these files only increased the app .wasm file size up to 50 MB, which while large for a web application, is certainly tolerable for my purposes. I was also able to use the println!()-like console.log binding I borrowed from the wasm_bindgen docs to verify that the app was able to access the files. From here, we can load the file contents into an SGF parser library, and start replaying games using another library that is able to do things like remove captured stones.

Progress: the contents of an SGF file from KGS high-dan archives

Sep 16 2020, Wednesday

More progress: after learning about the thiserror crate, I found it easy enough to define a bit of code to store a collection of sgf strings, ready to parse and use on-demand, with a function that returns the next game each time, looping around when it gets to the end. From here, I'm pretty close to getting an actual visual result, so I'll see about that next time.