James Stanley


Cheating at chess with a computer for my shoes

Sat 30 July 2022
Tagged: software, 3dprinting, chess, electronics

I have come up with a new way to win at chess: I have connected up a Raspberry Pi Zero in my pocket to some buttons and vibration motors in my shoes, so that I can surreptitiously communicate with a chess engine running on the Pi. The project is called "Sockfish" because it's a way to operate Stockfish with your socks.

The feet are ideal for this sort of thing, because they're the only part of your body that has any sensible degree of dexterity while still being invisible to casual observers.

There is prior art for phones taped to legs and some sort of TV remote control (?) and lots of cases of just going to the toilet and looking at chess positions on phones, but I think Sockfish may be the first hands-free method that does not require third-party assistance.

Each shoe insert has two force-sensing resistors and one vibration motor. The force-sensing resistors are used as buttons to allow me to input my opponent's moves. The vibration motors are used for haptic feedback of accepted button presses, and to communicate the engine's moves to me so that I can play them on the board.

On Tuesday evening I finally had a chance to deploy Sockfish in a real game against an unsuspecting opponent! Owen is quite a bit better at chess than I am. I talked him into playing a game with time control of 15 minutes per side, which is longer than the blitz & bullet that we normally play, but necessary to give me enough time to type the moves with my feet.

First game

Owen was very confused about why it took me 20 seconds of intense concentration to decide on my very first move. He eventually surmised that I must have "revised" and was concentrating hard to make sure I remembered the theory. In actual fact I was concentrating very hard to make sure I understood Sockfish's outputs correctly and gave my inputs correctly! I found that I concentrated much harder operating Sockfish than I do when I'm playing chess the hard way. Maybe I'd play better if I concentrated harder.

It was all going well until we reached a position where Sockfish was telling me to make an illegal move. The game (as understood by Sockfish) proceeded as https://lichess.org/cmcYJF7G (with me playing black). It wanted me to play 20... Qxe6.

But on the real board the position was different. Ruari was spectating, and already knew about the ruse, so he had contrived to record parts of the game. From his video, the real position was this:

The difference from the Sockfish version is that my g pawn has moved to g6, and my light-squared bishop has not captured on g2.

I think what must have happened is that when the computer asked me to play Bxg2 I instead played g6. This is not as crazy as it sounds: normally Sockfish tells me the starting square and destination square for the move it wants me to make, but since only one piece could move to g2, Sockfish only needed to communciate the destination square. So it sent g2, but I heard g6. This is because a "2" is transmitted as 2 short pulses of vibration on the right foot, and to save time a "6" is transmitted as a long pulse (representing 5) followed by a short pulse. I simply mistook the first short pulse on the right foot for a long pulse, and assumed I should play g6.

Maybe this diagram of the vibration pulses will help (or maybe it won't):

Anyway, with Sockfish now out the window, I had to continue on my own.

Instead of illegally capturing the queen on e6 (which I judged that I would be unlikely to get away with), I blocked the check with the rook. This was foolish in the extreme! The rook is simply captured with no compensation. In my defence I had been concentrating so hard on communicating with Sockfish that I scarcely had any comprehension of the actual chess position. We soon ended up at this position and I resigned:

Second game

Thankfully, the jig still wasn't up, and Owen agreed to a rematch.

Ruari filmed almost the entire game this time. I remember being paranoid that it would be obvious that I was fidgeting, but in the video it just looks like I'm thinking really hard. I don't think anyone would guess that I was using trick shoes.

At one point during this game I made an input mistake, but I noticed it before it became a problem! I was seen to mouth a swear word, think hard for 30 seconds, start laughing, and then ask Owen to remind me about the previous couple of moves. It's a wonder he didn't suspect anything.

After spending 70 seconds secretly undoing and redoing moves with my toes (all while trying to act natural) I eventually convinced myself that I had recovered the position and proceeded, with an audible "phew!" and an announcement that I needed to stay focused.

Unfortunately, a couple of moves later, disaster struck once more! Sockfish again asked me to play an illegal move. The position in Sockfish was this:

But the position on the real board was this:

Basically 27... Qxe1 and 28. Rxe1 had gone missing from Sockfish's version while I was undoing and redoing moves. I must have undone 1 ply too far and failed to reconstruct it. In this position Sockfish was asking me to play Rd8+, but since I didn't have a rook on the d file, this proved challenging. I announced that I was now "off-piste" (without explaining what that meant), and started playing manually.

Fortunately, being a queen up, the game pretty much won itself, and Owen resigned a few moves later. Not exactly the great success that I had in mind for Sockfish, but at least it was a win! 50% of the time, it wins every time.

Grand reveal

Immediately after winning the game, I explained the ruse to Owen. His first reaction was incredulity, until I showed him the shoe inserts and computer. Overall he took it pretty well.

I told him that I was planning to recruit a "plausibly-good" chess player to use the shoes to win the world championship, but he considered that this may "bring the game into disrepute" and said he would definitely dob me in. I think I'd be more interested in the Netflix adaptation than the real-life story anyway.

Details

In my pocket is a plastic box containing the Raspberry Pi Zero, a 4-channel ADC for reading the force-sensing resistors, some transistors to switch power to the vibration motors, and a trimpot for each vibration motor to adjust the strength. Without the trimpots they are very loud and might give the game away (so to speak) prematurely. This is what's inside the plastic box:

There's also a USB powerbank in my pocket to run the Pi.

The Pi is running a Python script that reads from the GPIO pins and writes to stdout, which is consumed by a Perl script that reads button presses from stdin, reconstructs chess positions, and runs Stockfish, and then writes vibration pulses to its stdout, which are then sent to GPIO pins by a second Python script.

(Why this crazy architecture? I am happier writing the actual program in Perl, but all the Raspberry Pi GPIO examples use Python... it was just easier this way).

This whole contrivance is running inside screen with -L so that the output is logged for perusal later. It's started by /etc/rc.local when the Pi boots up.

If you have the shoe inserts plugged in while the Pi is booting, then one of the vibration motors stays stuck on for about a minute, because it turns out that the GPIO pin that drives it is initialised to +5v while the Pi boots up. Doesn't really matter, but you can feel the vibration get weaker over the course of the minute as it heats up and the resistance increases.

I used a soldering iron to poke a hole in the cargo pocket of the trousers so that the wires can run down the insides of my trouser legs.

Originally I was using 4-pin TRRS connectors to connect the Pi to the shoes, but I found these were very flakey and unreliable. I replaced them with 4-pin waterproof ebike connectors which work much better and are not significantly larger.

At first I was printing the shoe inserts in PLA, which is too stiff and makes it very difficult to walk. I replaced these with flexible TPU plastic, which worked much better. I also started out with ordinary microswitches, which got damaged when I walked on them, and replacing them with the force-sensing resistors solved this problem, with the added bonus that I can now adjust the activation force in software.

Jez pointed out that Sockfish is reminiscent of the Eudaemons' roulette-beating shoe computer, which is a very impressive project considering the primitive electronics available in the 1970s.

Sockfish-ng

Don't tell anyone, but I already have plans for a better version of Sockfish that will be much harder to detect!

This proof-of-concept only needed to fool my mates, in a pub, for the duration of 2 games. To win the world championships we're going to have to get much more serious.

I'm thinking we'd integrate the Pi and all the other electronics onto a single PCB, instead of having a normal Pi plugged into 2 pieces of stripboard. We'd put this compute PCB in one of the shoes. Each of the shoes would have its own battery and Bluetooth (or similar) radio inside, and all of the electronics would be hidden under the in-sole which would be glued down. Even strip-searching the player would not reveal any secrets.

The interface would work similarly to how it already does, maybe with better distinction between a long pulse and a short pulse, except the communication from the secondary shoe would go over the radio instead of a wire.

You'd probably have to X-ray the shoes to find out something is up. If that is a realistic threat then I think the plan is to have the player walk in wearing ordinary shoes, have someone else smuggle in the hacked shoes through a different route, and have the player swap shoes once he's already been scanned.



If you like my blog, please consider subscribing to the RSS feed or the mailing list: