Talks
High Performance Mario Kart On Ruby
Summarized using AI

High Performance Mario Kart On Ruby

by Michael Morris

Summary of 'High Performance Mario Kart On Ruby'

In this engaging presentation at RubyConf AU 2018, Michael Morris explores the intersection of gaming and software development through his team’s creation of a comprehensive leaderboard application for Mario Kart. This project stems from the necessity of software developers to quantify their gaming experiences amidst their serious work environment in banking.

Key Points Discussed:

- Gaming as a Relaxation Tool: Michael introduces the relevance of playing Mario Kart as a fun escape from the seriousness of his banking job.

- Development of a Leaderboard Application: The team aimed to find out who excelled at Mario Kart by building a leaderboard app that posts results on Slack, utilizing a simple Elo rating system to track wins.

- Challenges with Multi-Player Scoring: Recognizing challenges with four-player games, the team transitioned to the TrueSkill algorithm, allowing for a more accurate ranking between multiple players.

- Enhanced Functionality: The application was advanced to include the inspection of individual player stats, tracking victories, and plotting performance over time.

- Using Images and Data: The presentation outlined a three-step system: getting an image from the Nintendo Switch, analyzing it to extract gameplay data, and reconstructing the game's state using this data.

- Technical Implementation: Michael describes how different devices were used to fetch video streams from the Switch and how Ruby was employed to analyze these images to identify player positions and item information during races.

- Community and Collaboration: He emphasizes the importance of teamwork and the Ruby open-source community in the project’s success.

Examples and Illustrations:

- A demo with live players showcased the application in action, demonstrating its ability to track ongoing matches and display race results.

- The use of Google Chart Image Drawing API allowed for graphical representations of player statistics, adding an engaging visual element to the leaderboard.

Conclusions and Takeaways:

- The project illustrates innovative applications of Ruby outside of traditional uses, inspiring developers to look for creative ways to implement software in recreational contexts.

- Michael expresses appreciation for the support from his employer and encourages those interested in similar developments to explore their ideas further, noting that the project’s code is accessible for others to experiment with.

- The talk showcases the value of combining passion with technical skills, fostering a culture of creativity and playful competition among developers.

00:00:00.030 In between managing a team at Up and Ferocious, running a bank, and parenting two children, Michael finds time to play Mario Kart. This is relevant to our next talk where some people will come up on stage soon to play Mario Kart. It's cool that we’re going to watch them play games at a conference, and Michael's just going to stand there.
00:00:27.000 This taps into your enthusiasm for the game, would you say? Yes, indeed. This story was born out of banking. I work for a serious company that builds serious banking software in a serious industry. In case you hadn't gathered, it’s all very serious. So naturally, what do we do when we're looking to relax? We play Mario Kart, and we take that pretty seriously. You can tell it's serious when you see pictures like this where everyone is sitting about three or four feet from a ginormous television.
00:01:02.489 You really know you’re taking Mario Kart seriously when you start looking at the world a little differently. The software developers started with a simple question: who is the best at Mario Kart? Naturally, as software developers, we think, 'Well, we can solve this with software.' So we did. We built a little leaderboard application, and it looked something like this. I could have taken any race results, but let's pick one that's a bit flattering. It's a Slack integration with a standard Rails app.
00:01:47.460 The application posts back to Slack with the current leaderboard, showing who moved up in the rankings. You'll notice that there’s a score column there, and usually, this would elicit some sort of response. We needed a mechanism to track this leaderboard, so we started with an Elo rating algorithm, which is typically used for tracking chess games. This algorithm can track wins and losses between two players.
00:02:44.460 The problem with Mario Kart, however, is that we typically have four players in a game. To solve this, we would enter the results as a series of two-player games based on the results of one player beating another. The results indicated one person emerged as the 'king' of sorts, but clearly, that algorithm wasn't cutting it. So, we stumbled upon an algorithm called TrueSkill, developed at Microsoft Research as part of their work on Halo 2.
00:03:09.930 TrueSkill is designed to track arbitrary numbers of players and teams. One of the developers I work with, Tom Meyer, went out of his way to implement this, and he agreed that this new algorithm was indeed better. However, we wanted to go beyond simply knowing who was at the top of the leaderboard. We added functionality to inspect individual players to see how many times one player had beaten another.
00:04:32.639 We also wanted to plot a player's decline over time, so we developed the ability to generate a chart with the Google Chart Image Drawing API. The Rails app generates a chart and responds with a Google image URL, which gets displayed inline in Slack. Users can query this chart for any of these players over a specific date range. You might think this is a bit ridiculous, and it probably is, but it highlights the lengths we went to.
00:05:53.520 So let's demo it today. Jesse, please come up. We actually need a few people who can play Mario Kart. If anyone here has a Switch, come on up. Yes, you, come on up. We have a Switch set up here with four players.
00:06:16.260 So here's our system. You can see all the players as we let them play. It's exciting to see that we're detecting a match in progress. Here we go.
00:08:14.970 The system will track timings, indicating how long each player takes. This adds a Fitbit-like functionality, matching players against each other and providing statistical results, like the crown and race finish times. Mario Kart has certainly evolved into this functioning result-analysis system.
00:08:35.160 Now, how does this system work? It's broken down into three steps. First, we need to get an image off the Nintendo Switch. Second, we need to analyze the contents of that image. Third, we need to reconstruct the current state of a game from all the gathered data.
00:09:40.450 Getting an image off the Nintendo Switch involves using an HDMI splitter, an HDMI-to-Ethernet sender, and a receiving device. Normally, these devices would simply transmit video to a monitor; however, we sought to capture the network traffic instead. Using a TCP dump, we can grab the stream and write it to a series of files until disk space runs out.
00:10:48.350 Moving onto step two, extracting information from the images meant writing Ruby code to identify screens, such as the main menu. By focusing on unique identifiers and employing the pHash library to detect image similarity, I could accurately determine which screen we were encountering. This helped us extract essential game data from the images.
00:12:40.270 For the race screen, we identified player position and item information through pixel analysis and comparison against reference samples of the UI for accuracy. This method allowed us to track which player is in what position and what items they currently possess as part of their gameplay.
00:15:00.720 Additionally, I had to appropriately collect the race result screens to determine the points for each player and recognize who would wear the crown at the end of the match. This involved careful differentiation between frames to ensure that we collected the right information.
00:17:08.190 The information we gathered allowed us to efficiently reconstitute the game’s state. By establishing a data model that included matches, races, and race snapshots, we could build a coherent event stream and respond dynamically to game events.
00:19:01.960 Throughout this journey, I learned a great deal about the versatile applications of Ruby. The development process has motivated me to encourage others to look for innovative uses of Ruby and implement it on interesting projects. With the help of our outstanding open-source community, we made this entire project a reality.
00:21:05.750 In closing, I would like to express my gratitude to my workplace for supporting my attendance here. Working on building a digital bank aimed at helping people manage their money has been fulfilling. If you have ever wished for a bank that helps optimize the use of your finances, I encourage you to look into our services.
00:24:00.340 Lastly, I appreciate the opportunity to speak today and the great work put into organizing this conference. Thank you to everyone, and I'd be happy to answer any questions.
00:28:54.790 I'm open to any questions you may have about the demo or the development process. I had to pull this all together quite quickly, but it took a lot of collaboration with my colleagues to refine the code and improve the project’s scope. If you’re interested in building something similar, the code is straightforward, and I hope to see some creative implementations in the future.
Explore all talks recorded at RubyConf AU 2018
+8