For fame: The story of Autofoos
Published
Knut Melvær
Head of Developer Community and Education
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.
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.
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 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:
- Each player has a currency called Fame.
- They all begin with 50 in Fame.
- You can have a minimum of 1 and a maximum of 100.
- When competing, each player “bet” a percentage of fame, the default being 10.
- The pot is divided among the winners, and the losers forfeit theirs.
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.
function makeBalancedTeams(players, options) {
const defaultSkill = accolade.getDefaultEntry().skill
const isAccoladeEntry = item => item._type === 'accoladeEntry'
const sortByFame = player =>
get(player.skill.find(isAccoladeEntry), 'skill', defaultSkill)
const sorted = sortBy(players, sortByFame)
if (players.length <= 3) {
return shuffle([[sorted[0]], sorted.slice(1)])
}
const halfIdx = Math.floor(sorted.length / 2)
const topHalf = sorted.slice(0, halfIdx)
const bottomHalf = sorted.slice(halfIdx).reverse()
return shuffle(zip(topHalf, bottomHalf)).map(team => shuffle(team))
}
Code snippet from the refactored Autofoos software showing how Accolade is used to make balanced teams.
Playing strategies
Doing some research for this post, I discovered that there is, of course, such a thing as Foosball training videos on YouTube. But I don't suspect that the later newcomers at Sanity really have been studying those. Rather, the onboarding is more like being thrown into deep water and learning by losing and serendipously winning.
So, to make it a bit easier for whoever want to play foosball at Sanity HQs, here's some strategies that can increase your streak chances.
“Open offense”
If you play offense, and the ball is on your half of the field, be sure to hold your players in the open vertical position in order to let the ball through. It's not uncommon that goals will be struck from defense if you play with a more seasoned player.
“The assertive kick”
I suspect that this technique isn't really practiced that much in professional foosball tournaments, but it's rather prevalent at Sanity HQs. It takes a bit of practice and probably days of having sore wrists, but being able to kick the ball hard can be a path to winning the game. The art is not gripping the stick with your whole hand, but use the inside of your hand to pull the one side of the handle quickly and forcefully.
“The inline serve”
This is the first move into more technical foosball playing. When you get the ball you can use the inside of your players to pass the ball horisontially to the next player on your current stick. This makes it a bit harder for the opponent to block the ball if done quickly.
“The pop”
I'll call this technique a bit controversial and you don't see it too often. It entails getting the ball stuck under your player’s foot, and apply force to the handle until the friction between the ball and the floor gives and the ball shoots forth with great speed. It's probably not very efficient since it takes a bit of times and the ball’s direction is very obvious.
“Take the ball’s side”
When playing defence, make sure to keep the players on the same side that the ball is in. And keep your eyes on the ball and not the players.
“Jiggling offense”
If you slightly jiggle the players back and forth on the stick, it's easier to move to the right direction when the ball comes, and it increases the chance of you blocking it. We can also imagine that it distracts the opponent, but more research is neeed.