Advent of Code: The most wonderful time of year…

December is upon us! That means the latest edition of the Advent of Code is here.

The Advent of Code is essentially a daily programming challenge featuring a new problem each day through Christmas. The problems all relate to a certain theme. This year, it sounds like we’re going on an undersea adventure.

— Day 1: Sonar Sweep —

You’re minding your own business on a ship at sea when the overboard alarm goes off! You rush to see if you can help. Apparently, one of the Elves tripped and accidentally sent the sleigh keys flying into the ocean!

Before you know it, you’re inside a submarine the Elves keep ready for situations like this. It’s covered in Christmas lights (because of course it is), and it even has an experimental antenna that should be able to track the keys if you can boost its signal strength high enough; there’s a little meter that indicates the antenna’s signal strength by displaying 0-50 stars.

Your instincts tell you that in order to save Christmas, you’ll need to get all fifty stars by December 25th.

Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!

I’ll be partaking using my preferred language of choice: x86 assembly.

I kid, I kid. JavaScript.

The World of Yesterday by Stefan Zweig

This is an absolutely beautiful (yet heartbreaking) memoir written in the midst of World War II.

Completed in 1942 (and sent to his publisher just days before he and his wife took their lives), it provides an intimate and fascinating look at life in Europe during the end of the Victorian Era and through two world wars.

I think one of the most striking things about this book (especially in the later pages) is how mournful, almost hopeless, Zweig is about the state of Europe and the world as a whole. And it’s no surprise, right? He was an Austrain Jew who saw the home and the people he loved destroyed.

Take this passage, written about Paris. He lovingly describes his time in Paris after he graduated from university and how it was a city that could always make people happy.

“I had promised myself a present for the first year of my newly gained freedom—I would go to Paris. Two earlier visits had given me only a superficial knowledge of that city of inexhaustible delights, but I could tell that any young man who had spent a year there would be left with incomparably happy memories for the rest of his life. Nowhere but in Paris did you feel so strongly, with all your senses aroused, that your own youth was as one with the atmosphere around you. The city offers itself to everyone, although no one can fathom it entirely.”

And then a paragraph later, we get to the hard truth about the time period this book was written in:

“Of course I know that the wonderfully lively and invigorating Paris of my youth no longer exists; perhaps the city will never entirely recover that wonderful natural ease, now that it has felt the iron brand forcibly imprinted on it by the hardest hand on earth. Just as I began writing these lines, German armies and German tanks were rolling in, like a swarm of grey termites, to destroy utterly the divinely colourful, blessedly light-hearted lustre and unfading flowering of its harmonious structure. ”

Another powerful aspect of this book is that while reading, we know that he would soon take his life and he’d never get to see how this tragic story (World War II) ended and how the cities, art and music he loved would eventually recover.

The World of Yesterday by Stefan Zweig

Sid Meier’s Memoir!: A Life in Computer Games

The Civilization series is easily one of my favorite video games of all time. (See here, here, here, here and here). I have very fond memories of talking to my middle school teacher about various strategies to utilize within Civ I and I still vividly remember the wickedly cool box art.

So, it’s no surprise that I’d dig into the memoir of the man who created the games himself, Sid Meier.

It’s a nerdy trip through early computer gaming history and fostered a bunch of nostalgia for old DOS games that I used to play. It’s also a fantastic romp through the mind of a game designer.

There were a number of fun little quotes and life lessons, as well:

“I think that in life, as in game design, you have to find the fun. There is joy out there waiting to be discovered, but it might not be where you expected. You can’t decide what something’s going to be before you embark on it, and you shouldn’t stick with a bad idea just because you’re fond of it. Take action as quickly and repeatedly as possible, take advantage of what you already know, and take liberties with tradition. But most importantly, take the time to appreciate the possibilities, and make sure all of your decisions are interesting ones.”

Generating terrain maps

Recently, I went down a rabbit hole attempting to learn how to generate interesting looking maps for games (insert mind-blown-gif here). While I’m not going to be using Voronoi diagrams anytime soon,  I am still interested in attempting to generate Civilization-like maps.

Most map generation algorithms rely on perlin noise. I wanted to go a different route.

So far, these are the rules that I’ve come up with for my algorithm:

1. Create a grid of some given size (e.g., 100 x 50). Set all tiles to “ocean”.
2. Randomly pick 8 tiles (variable) across the map to seed as “land”.
3. Now iterate across all tiles on the map and build an array of tiles that are “ocean” tiles but have a land tile N/W/S/E of them.
4. Once you have this array, randomly pick a single value. Flip it from “ocean” to “land”
5. Repeat step 3 until a given number of tiles have been filled across the grid (e.g., for an “Earth-like planet”, 30% of tiles will be land).
6. Now, to add some additional randomness — iterate across all tiles and build an array containing all “land” tiles next to water (N/W/S/E).
7. Randomly pick 1, flip from land to ocean.
8. Repeat step 6 a given number of tries (e.g., 100).
9. Done! (Maybe)

Height maps, biomes and all that can come later. To quote Amit, whom I linked to earlier:

The most realistic approach would have been to define elevation first, and then define the coastline to be where the elevation reaches sea level. Instead, I’m starting with the goal, which is a good coastline, and working backwards from there.

Anyway, it’s been kind of neat to figure out.

Another example map, created using the above rules: