Crestron Masters Hackathon 2023

Jeremy Weatherford
5 min readMay 24, 2023

That’s right, it’s time for the semi-demi-annual Hackathon post-mortem. This time I was privileged to attend my first European Crestron Masters in Madrid, Spain, and I was especially excited about the Hackathon after the non-starter in Orlando in 2022.

Since my usual Hackathon buddies weren’t in Madrid with me, I wasn’t sure how best to organize a team. This year we had the option to be assigned a random team, which sounded good to me. I showed up early and put up a sign saying “Team Lithium” (our randomly-assigned element-based team name) and found three of my four assigned teammates, Moment Chan, Christian Neumann, and Kyle Toczek. Our fifth was a no-show apparently.

The welcome e-mail for the Hackathon included a reference to “plenty of 🚩😉” which some people correctly decoded as a reference to Minesweeper, however that went right over my head. That was in fact our challenge: build a network client to play (and win) Minesweeper, by connecting to the server built for each team. Similar in spirit to the Great Battleship Challenge of 2018, mercifully this was not set up as a programmer relay-race. Rather, each team member got our own port number to try to play the game, with a collective score for games won.

After receiving a copy of the rules and getting clarification about where to connect, I immediately started testing some of the protocol commands using a TCP terminal utility called Hercules Setup. This is one of my favorite ways to make sure a device is actually working the way it’s documented. I was able to start a new game and get a status response, so I started a quick-and-dirty node.js (Javascript) client to do the same thing.

Once I was parsing basic responses, I decided to have my client click random squares as a first (and worst) strategy. As soon as I sent my first CLICK command, though, the server stopped talking to me, even after reconnecting. I connected on a teammate’s port and confirmed that the server worked fine until I sent a CLICK command with a row and column selection, and then it stopped responding. I flagged Chris Tatton down and he restarted our team’s server, then I confirmed that was really what happened and showed Chris and Selveno (the developers of the Hackathon challenge). Somebody told me to read the directions carefully, which I did, and was still stumped. They confirmed that somehow I was still sending the wrong command.

At some point it clicked with me that the STATUS response had returned the number of rows and columns as bytes (\x14 = 20) rather than in ASCII (\x32\x30 = 20), and that the protocol was expecting the row and column numbers in the CLICK command to be single bytes as well. This little bit of deviousness was more confusing than intended because the server failed to return an “invalid command” or “value out of range” message, and instead crashed the receive thread silently (an actual bug in the server).

Once I was able to send commands as intended, I turned my client loose and immediately lost a few games. After TRIPLE-checking that we couldn’t lose any team points by losing games, I kept running the client and watching the losses rack up. I thought surely it would be able to win at least one game by clicking randomly, but sadly that wasn’t the case.

Time for some actual strategy — although I was already happy to be dominating the scoreboard with losses, especially since they wouldn’t count against our team score. Working with Moment Chan, we decided that we could do better than random clicking by clicking near a revealed “1” that had 4 or more blank spaces near it. Unfortunately, this strategy did not result in any wins either. I hadn’t played Minesweeper in years, so after discovering that it wasn’t installed in Windows 10 (for shame) I went to Minesweeper Online and started playing a game manually, trying to remember the basics. While Moment and I worked on strategy, our other two team members were trying to get the provided user interface set up on our team server so they could play and win some games manually.

Clicking around in a Beginner game, I decided the next-least-dumb thing to try was to look around revealed 1s and flag a blank square if it was the only neighbor, and “chord” or middle-click it if it already had one flag nearby. Amazingly this was enough to win us a few games. Expanding the logic to include 2s up to 5s brought our win rate up to maybe 25%. The final strategic decision was to click a little less randomly when it got stuck: instead it would look for a blank space surrounded by blanks. This brought the win percent up to around 60%. The final speed boost was just strength in numbers — running five copies of the same client simultaneously on the five ports we had available.

This was enough to dominate the player standings, but Chris Tatton had one final evil trick up his sleeve. He had written an automated solver with a perfect algorithm (possible since none of the Minesweeper boards required guessing), and turned it loose on the scoreboards with a pre-programmed delay between solutions. He tweaked the delay up and down to make it a close race, but I wasn’t able to come up with any strategy or speed improvements that would allow me to catch him. Sometime around here we hit 4-digit losses and I was amused to see that the scoreboard was not sized to fit such large numbers.

I’m still not clear on what the bottleneck was. I had five node processes barely hitting 20% CPU on 5 different cores, and network bandwidth held steady around 2Mbit/sec. It seems possible that the code was inefficient enough at switching between I/O and CPU that it wasn’t able to max out a CPU core, or maybe the server wasn’t responding as quickly as it could have. Although my algorithm was far from perfect, it seemed like it should have been able to make up for it with brute force since losses didn’t count.

Ah well — we still placed first, and Chris was gracious enough to split the bonus prize for beating his algorithm with us (champagne). I greatly enjoyed the return to in-person Hackathon challenges. This was truly a worthy successor to previous Hackathons, and I‘m certainly not mad about placing first. Big thanks to my teammates, to Chris Tatton and Selveno Andrade for building the challenge, Chris Waldron for building the infrastructure to host it all, and to Toine Leerentveld and Rich Sasson for providing color commentary. See you next year!

--

--