For fame: The story of Autofoos

Written by Knut Melvær

If you start working at Sanity.io, you’ll soon notice that every day after lunch there will be someone asking “who’s in?” and tap something on their phone. After a couple of minutes, there will be a random selection of four teammates that goes over to a foosball table for a match. You will also find yourself drinking coffee out of cups with scores on them (10–0 to be precise). And when the office has to be refactored to accommodate our growing startup, there’s no question of the foosball table’s prominence in the new plans: It’s sacred and it's runs Autofoos.

[image of the score cup]

I have never been a person that has sought up competitive sports, but not because I’m not competitive. On the contrary, I’m probably very competitive, to the level where I get stressed by it. So my inclination was to avoid the foosball table when I first started at Sanity. I also had the prejudices of it being a bit “bro-y”. Oh boy, was I wrong! Not only has the foosball table proven to be an excellent mechanism for onboarding new collegaues, it's also nerdy in several dimensions. So I’m now an Autofoos convert and I’ve started enjoying the matches and this surprisingly sophisticated game, both in terms of tactics, but no less the technology my team has augmented it with.

In this post, we will explore everything from the rules and techniques that goes into playing foosball at Sanity.io, to the software and algorithms that select the teams and keep track of scores. It's also a testament to how a company’s Slack history can reveal an interesting past for newcomers with chronical ambitions. I was able to dig up most of Autofoos’ history by peeking back in time at the chatlogs.

What is foosball?

According to Wikipedia, foosball, or table football, stems back to Harold Searles Thornton’s patent from 1921. It’s a contraption about TK x TK in size, and with 8 sticks, four sticking out on each side. On each stick you'll find some one-legged football players attached. The stick can be rotated and moved on an axis back and forth. At each end of the table there is a goal, and the point of the game is to stick the little ball in the opponent's goal to win a point. You should preferably be four players to play a match of foosball, but it’s possible to be two.

[image]

House rules

Although there is something like professional foosball tournaments with standardized rules, there is bound to be local variations. At the Sanity HQs you can’t score a goal straight from a serve, the ball has to pass another player first. And there’s no spinning of the players. If the ball bounces back out from the goal, it’s not counted as a score (this sometimes happens with people who has perfected the hard kick). For each team’s second score, the players will switch who’s playing offense and defense.

Early stages of Autofoos

The history of Sanity’s foosball table started back when Sanity was the digital consultancy Bengler. If one go deep into its Slack records, the first mentions of “foosball” appear around March 2015, with links to a spreadsheet with scores being posted regularly. The spreadsheet accounts for a couply of hundred matches between that year. Statistics about the player’s progress is shared. As we’ll see, this will be developed into the concept of Skill and Fame.

Line graphs showing each players skill percentage over time

To be expected from a digital consultancy, Bengler’s Slack history from 2015 also contains dreams about having a digital foosball table that can draw teams and keep track of scores. On December 8th, Rune introduces @bengbot which appears with a randomized drawing based on who’s available to play. This is the first prototype of part of the functionality for what will become Autofoos.

Slack message showing how to draw players with bengbot

The hardware

Early January 2016, Espen starts a new Slack channel called #autofoos. This is when stuff begins to get serious. The team discusses how to automatically track scores using optic sensors and microcontrollers. The plan is to put a sensor under the table to track when the ball passes from each side.

The inside of the Foosball table before the modifications

The team orders a Particle Photon and a pair of Adafruit IR break sensors, and after the first weekend in February the repository with the first iteration of the software is up on GitHub. The stats from the spreadsheets are transferred into a Mongo database, and the program is written in Node.js. The team also decides to close the repository with plans of making Autofoos a product startup (In my personal opinion, I’m glad that it didn’t, or else I wouldn’t be here).

[image of the modified table]

The software

Currently, Autofoos draws teams, keep track of scores, and has a web-based frontend where new players can be added. It also has interfaces where the team can explore statistics and scoreboards. When a team wins, it will be recorded for each player and the Skill will be calculated for each of them. The algorithm behind being Trueskill™ developed by Microsoft Research. Skill was used to draw balanced teams, because foosball is more fun when the stakes are high and there’s a real chance for the match to go either way — well, at least to a point.

After the first iteration of Autofoos has been running for a couple of months, the team felt that they needed a better selection algorithm. The problem was, Espen explains to me on Slack, “we usually ended up with the same teams and because the teams were so balanced we rarely saw the skill change significantly. So Thomas made Accolade, which is more much volatile”.

Accolade draws teams based on the following principles:

The scoreboard showing loads of stats

The algorithm is stateless, but the Fame of each player is recorded and saved in the Autofoos system. When drawing teams, Autofoos will randomingly select 4 players, sort them by fame, and divide them into two teams placing the highest and the lowest ranked on one team. The team kept the Trueskill™ score, but purely for statistical purposes, it doesn't affect the drawing of the teams anymore.

Internal server error