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:

 

Troubleshooting a (Royal) Kludge (RK G68): Sleep issues with my swanky new mechanical keyboard

TL;DR After a lot of testing and isolating devices, I’ve determined that the RK G68 RF receiver for my swanky new mechanical keyboard causes my Windows 10 machine to wake up immediately after putting it to sleep. And I’m not sure how to fix it.

Join me on an epic journey of heartbreak, anger, loss, triumph and sadness as I try to diagnose some sleep issues.

—-

So, the issue is that if I manually put my computer to sleep (Start Menu -> Power -> Sleep), the machine goes to sleep, fans turn off, and all that. Sweet! Then, after about 5 seconds, it wakes right back up. Uh, what?

I’ve done a number of debugging and testing steps which I’ll outline below (hopefully, this helps some folks in the future).

Let’s do a couple of finger stretches, put on our hacker pants, and open up PowerShell (with admin access). We can run a nifty command called powercfg /requests

I see the following output:

DISPLAY:
None.

SYSTEM:
None.

AWAYMODE:
None.

EXECUTION:
None.

PERFBOOST:
[DRIVER] Legacy Kernel Caller
Power Manager

ACTIVELOCKSCREEN:
None.

Great! But not really super helpful. We visit our friend, Google, and I see that there is a command to disable this:

powercfg -requestsoverride Driver "Legacy Kernel Caller" System

You haven’t lived until you’ve copy and pasted random commands from the Internet into your terminal. Let’s do it! I run that and make the computer go to sleep again. Monitor turns off, fans spool down. Yes! Yes?

Obviously, it immediately wakes up. No dice.

Ah, ha! Maybe read the command first, dude? The issue here is that the Legacy Kernel Caller is in the PERFBOOST category, not SYSTEM category. That’s easy to fix.

…but it isn’t.

Of course, you can’t actually disable the driver for items in the PERFBOOST category. Of course.

Hey, Google…

Next up: A suggestion to check waketimers. I have no idea what that is, but sure: powercfg -waketimers

There are no active wake timers in the system.

Okay.

Yo, Goooooooogle… again!

Ah, another command! powercfg -lastwake

Now we’re getting somewhere. We see that this is a USB device that is waking the computer:

Wake History Count - 1
Wake History [0]
  Wake Source Count - 1
  Wake Source [0]
    Type: Device
    Instance Path: USB\VID_25A7&PID_FA70\8&e5ec113&0&4
    Friendly Name:
    Description: USB Composite Device
    Manufacturer: (Standard USB Host Controller)

But… how do we determine what it is? Looking at the path, we see VID and PID. That means:

Vendor ID: 25A7
Product ID: FA70

Let’s Google those: It turns out, the vendor is Areson Technology Corp and it looks like they make RF receivers for various input devices, such as wireless mice. Interesting! No hits for the product ID. That’s fine, there’s probably more types of RF receivers on planet Earth than there are people.

But that gives me a starting point.

I decide to start unplugging various devices and put my computer to sleep.

  • Unplug Logitech USB receiver: Still wakes up.
  • Unplug Anker USB Bluetooth receiver / transmitter: Still wakes up. I feel like I’m not having much fun anymore.
  • Unplug this random, unlabeled RF receiver: Hey, my keyboard input stopped working from my mechanical keyboard! Ah well. Go to sleep computer…

IT DOESN’T WAKE BACK UP!!!!

Victory. Party dance. Switch out the hacker pants for party pants. Now we’re getting somewhere!

I plug the receiver back in and open device manager. I go to the keyboard section (randomly, there are like 4 different devices listed there). I open the properties dialog box for each of them, go to the Power Management tab and uncheck “Allow this device to wake the computer.

I got you now, pesky sleep problems! :blow-smoke-off-gun-gif-dot-com-dot-net:

I put the computer to sleep.

IT IMMEDIATELY WAKES BACK UP!

I’ll be honest. There was a lot of screaming, kicking, swearing. My dog got up and left the room (he never does that). I almost knocked over a coffee cup onto my keyboard and I DIDN’T CARE.

Okay, fine.

No big deal, really. I’m not okay, you’re okay.

On a hunch, I expand the Universal Serial Bus controllers section inside the device manager. Sure enough, there are a bunch of things that say USB Composite Device. You might remember from earlier (but probably not), that a “USB Composite Device” was called out using the --lastwake command.

If you open up the properties for each USB Composite Device and go to the events tab, you will see the device ID in the information section. Keep looking until you find the device ID that was called out: USB\VID_25A7&PID_FA70\8&e5ec113&0&4

Click. Close. Click. Close. Click. FOUND IT!

Device USB\VID_25A7&PID_FA70\8&e5ec113&0&4 was configured.

Driver Name: usb.inf
Class Guid: {36fc9e60-c465-11cf-8056-444553540000}
Driver Date: 06/21/2006
Driver Version: 10.0.19041.488
Driver Provider: Microsoft
Driver Section: Composite.Dev.NT
Driver Rank: 0xFF2003
Matching Device Id: USB\COMPOSITE
Outranked Drivers: 
Device Updated: false
Parent Device: USB\VID_0BDA&PID_5411\7&b8f002b&0&2.

Sweet, now to just open up the Power M…. THERE IS NO POWER MANAGEMENT TAB.

My dog came back. He immediately left again. You can probably guess why.

Back to Google again:

“Ensure drivers are updated”.

Okay. Sure. Blah, blah. But maybe it’ll work. It won’t though. I already know. Who am I kidding?

The best drivers for your device are already installed.

Fine. I’ll just uninstall the driver.

Oh, cool, now my keyboard doesn’t work.

BUT YOU KNOW WHAT?! MY COMPUTER STAYS ASLEEP!

Head, meet Desk. Desk, meet Head.

—-

A few other things to note.

    • If I have a USB-C cable plugged into the keyboard, it will stay asleep (even though the RF receiver is still plugged in).
    • If I turn off the keyboard itself, it will stay asleep.
    • If you just walk away from the computer, it will go to sleep (according to my power plan settings — 15 minutes). I suspect this is because the RK software (I’m on version 2, by the way, which I think just came out and the latest firmware) is setup to put the keyboard to sleep after about 5 minutes or so. I really haven’t tried to experiment with this because I DON’T CARE ANYMORE.

(I do care. Deeply. I just can’t right now.)

Book Review: Empire of Pain by Patrick Radden Keefe

What a fantastic book about a horrible family.

The first half of the book is a true rags-to-riches story, following the life and rise of Arthur Sackler and his brothers. The son of an immigrant, he came of age during the Great Depression. This man could hustle and there was nothing that could stop him.

The second half is about the pharmaceutical company they purchased and ran. In the 90’s, they created a ridiculously powerful pain killer (OxyContin). In an effort to maximize profit, they pushed the drug onto unsuspecting patients and physicians despite knowing (and hiding) how addictive and dangerous it was.

The damage is jaw dropping. And like most crimes involving the ultra rich, the family members who ran the company (and used it as their personal piggy bank) got away with it.

Book Review: The Code Breaker by Walter Isaacson

At first glance, this book seems to be a biography of Jennifer Doudna, a biochemist and one of the pioneers of CRISPR research.

While there is some focus on her upbringing and the things that may have driven her to become a fantastic scientist, the book is really about the wide range of characters who helped discover CRISPR DNA sequences and their potential applications in modern medicine.

I’ve heard CRISPR and CRISPR-based technology mentioned in various things I’ve read and how it is something that could potentially revolutionize medicine. But that’s really all I know about it.

This book digs into how Jennifer and her team of researchers discovered the CRISPR process — essentially duplicating the way that bacteria has fought off viruses for eons — and how it could ultimately be used for various therapies, treatments and even diagnoses.

The book briefly mentions its use in the Moderna and Pfizer vaccines for COVID-19 as well as some of the more controversial and ethically questionable uses — editing the genes of a fetus, for example, to choose certain traits (which will then be passed down to its own children).

This was an enjoyable and informative read and it covered all sorts of things from the science of CRISPR, legal issues related to patents, and the use cases for CRISPR based technologies today.

Book Review: The Plot by Jean Hanff Korelitz

Quick summary: Washed up author (Jake) teaching a writing workshop finds out a former student of his (Evan) — who had an amazing idea for a story that was guaranteed to be a best seller — suddenly died without publishing or apparently sharing his story with anyone.

Jake helps himself to the idea and ends up publishing a best selling book. Only… some Internet troll knows the truth and is sending him some anonymous, threatening letters. And so begins a wild goose chase.

I definitely enjoyed this. It starts off a bit slow, but as the story goes on the pace picks up and I couldn’t put it down

I’ll be honest: I *knew* there was going to be a plot twist around a certain character the moment we met them. I just knew it. But the deviousness of it still surprised me and I really wasn’t prepared for how things went down.

That said, some of the threats the anonymous person was making toward Jake felt a bit hollow. Knowing what we knew this person probably did, they couldn’t really threaten Jake without exposing their own crimes. So, that whole thing was kind of strange…

But we find out that it actually doesn’t matter, because there is a longer game at play and Jake is merely a pawn.

It’s crazy.

Book Review: Genghis Khan and the Making of the Modern World by Jack Weatherford

A few years ago, I read Conn Iggulden’s Conquerer series, a fictional account about the rise of Genghis Khan (née Temujin) and his exploits across Eurasia. It was a fascinating book and made me curious to learn more.

I picked this one up recently. While I enjoyed it, I often found myself thinking about how hard it must be to write a book about someone who lived amongst a nomadic tribe about 800 years ago.

The source material for this book is based upon notes found within a tome of (sometimes mythical) knowledge that was written shortly after Genghis Khan died — simply called The Secret History of the Mongols. It was written by an anonymous author and then passed down through the ages where the only remaining copy is a translation created some 200 years after his death.

The book is rarely critical of Genghis Khan, his followers (this is more of an “ends justify the means), and the sometimes ruthless actions they took to subdue a population.

That said, some of the most fascinating aspects of this story were how progressive the Mongols were when it came to improving the lives of the people they ruled: public schooling, accounting, trade, and communication. The book contains a fascinating comparison that puts his accomplishments in perspective:

“In American terms, the accomplishment of Genghis Khan might be understood if the United States, instead of being created by a group of educated merchants or wealthy planters, had been founded by one of its illiterate slaves, who, by the sheer force of personality, charisma, and determination, liberated America from foreign rule, united the people, created an alphabet, wrote the constitution, established universal religious freedom, invented a new system of warfare, marched an army from Canada to Brazil, and opened roads of commerce in a free-trade zone that stretched across the continents.”

Overall, this was an interesting (if skewed) story about an infamous character in history that many of us might have just misunderstood.

Book Review: The Burning by Tim Madigan

★★★★☆

This book is about the horrific, yet little known 1921 Tulsa race riot. The 100th anniversary of this tragedy and reflections on it reminded me about a book that I’ve had on my to-read list.

I first heard about this incident while reading Sam Anderson’s Boom Town, about the founding and growth of Oklahoma City. It briefly mentioned the Tulsa riot and how a white mob had destroyed an entire African American neighborhood.

Eager to learn more, I searched for a book about these riots… but then never followed up reading about them.

Set against a tapestry of racism, violence and resentment, this was a tinderbox waiting to explode (and these sorts of race riots had broken out in other parts of the country around this time as well).

I couldn’t believe the violence that was carried out, simply to put “black people in their place.” Looking at photos of the aftermath, the level of destruction is akin to photos of San Francisco after the 1906 earthquake and fire. Nothing is left standing. Thousands of houses destroyed, hundreds (!) of people dead.

Part of Greenwood District burned in Race Riots, Tulsa, Oklahoma, USA ,American National Red Cross Photograph Collection, June 1921.

And yet, the story was swept under the rug. It literally took decades before people started talking about it and publicly acknowledging that it happened.

My biggest takeaway was how easy it was for us human to become straight up barbaric animals when blinded by hatred.

Toward the later half of the book, the story recounts a young journalist who visited an internment center where people fleeing the violence (or were captured) were sent.

She found an older black woman crying, because she lost everything and had no idea where her family was. Eventually, the reporter asked, “how could this happen?”

“How could this not happen?” replied the old black woman.

The Burning: Massacre, Destruction, and the Tulsa Race Riot of 1921 by Tim Madigan

Book Review: Project Hail Mary by Andy Weir

★★★★☆

Andy Weir has clearly found a formula that works. A brilliant lone scientist stuck in space, who must overcome calamity after calamity in order to survive and hopefully get home.

This time, the story involves space fungi that are eating our sun (technically, it’s more like a space algae, but whatever). The nations of Earth band together and launch a mission to the stars in order to turn the tide on this interstellar parasite.

Our narrator wakes from a coma and doesn’t remember a thing. Where is he? How did he get there? What is his name?

Like Mark Watney before him in the Martian, our narrator is going to have to “science the shit” out of his situation in order to answer all the questions above, and also hopefully, maybe save Earth, too.

Oh, and sprinkle in a bit of first contact as well. Mark Watney never found himself a sidekick while he was on Mars.

Some parts were overly verbose, other parts were cringe-worthy and corny, but this was still an entertaining story I tore through in about 3 days.

If you liked The Martian, you’re going to like this book. If you didn’t, well, sorry. This book is more of that and then some.