I was almost at the point to buy a playstation or xbox controller to use with my tablet, since they seem to be supported out-of-the-box. But actually I still have an old USB controller lying around, which would be more than good enough for playing some games. Interestingly my gamepad did in fact work partly, but only the left analog stick and one or two buttons, and the rest did not. My hacker spirit told me that this must be fixable somehow.
So I started hacking around and added support for my old USB gamepad for my android tablet. In this post, I’ll show you how I did it and how you can to add support for any gamepad to your phone or tablet as well!
I am a big fan of the old Japanese board game Go. Some time ago I wanted to get my own Go game, consisting of a Go board (goban) and black and white stones. Unfortunately, I found out that wooden Go boards are quite expensive, by far exceeding the price range I was willing to pay. Actually, gobans are quite a simple piece of equipment. It is nothing more than a (wooden) board with a grid of 19 x 19 lines on it, why should I pay over 100 euro for it? So I decided to build my own and just buy the stones, which are cheap to come by.
I recently saw a video of an implementation of Conway’s game of life written in APL which was done in just one line. And because I couldn’t sleep last night, I implemented it in python as short as I possibly could.
So here it is:
for j,i,nb in map(lambda j:(j,j+s+1,bin(life&((7|5<<s|7<<s*2)<<j))[2:].count('1')),map(lambda x:x+int(x/(s-2))*2,range(0,(1<<s-2)+1))):
next = next|(1<<i)^(1^(((('23'.count(str(nb))<<1)+'3'.count(str(nb)))>>((life>>i)&1))&1))<<i
There’s a little write-up and the source after the break.