The Chess game that comes preinstalled on the Librem 5, GNOME Chess, works great but even at the “Easy” difficulty level it is kind of hard for someone like me who is not particularly good at chess. I can beat it maybe once in three attempts, so that’s a good challenge for me, but for some kids I know it is currently too hard, they like chess but they don’t like losing all the time. So I decided to tweak it a little bit to make it easier, here is how in case someone else wants to try.
First, to be able to fetch the source code, add this line in /etc/apt/sources.list:
deb-src https://repo.pureos.net/pureos amber main
That’s identical to the first line in the file but with “deb-src” instead of “deb”. Then do this to make apt aware of the change:
sudo apt update
Get the source code of the “hoichess” package, the chess engine that is used by GNOME Chess to decide the moves of the computer player, the “artificial intelligence” if you want to call it that:
apt-get source hoichess
Install build dependencies, like compilers and libraries needed to build hoichess:
sudo apt-get build-dep hoichess
Go inside the hoichess source code directory:
cd hoichess-0.22.0/
Now we just need to change the source code in some way that makes it a little less clever. I found this part in src/chess/basic.h
to be useful for that purpose:
static const int mat_values[6] = {
100, // PAWN
300, // KNIGHT
325, // BISHOP
500, // ROOK
900, // QUEEN
0 // KING
};
The numbers there correspond to the value that it gives to the different chess pieces, with the pawns being least valuable and the queen being the best. I didn’t check how those are actually used but I suppose the numbers determine for example if the computer player will think it is a good idea to trade pieces, it will for example sacrifice a rook if it can take your queen, and so on. So changing those numbers should make it less smart. As an extreme example I tried setting almost opposite numbers, I tried this:
static const int mat_values[6] = {
900, // PAWN
500, // KNIGHT
325, // BISHOP
300, // ROOK
200, // QUEEN
0 // KING
};
Then it will think the pawns are the most valuable pieces, and it will gladly sacrifice its queen to take out one of the opponent’s pawns. This might be going too far but anyway it’s an example that should give a noticeable effect.
Having made that little change in the source code, now build the package, this takes a few minutes:
dpkg-buildpackage -us -uc -b
Finally, install the generated .deb files:
cd ..
sudo dpkg --install *.deb
Now, start the chess app and notice that it is suddenly much easier to win!
You might laugh at this effort to make the AI stupid, but I thought it could be interesting as an example of the kind of things we can do with a FOSS-based phone. Tweak any part of the software in whatever way you want. Of course the procedure above is not specific to the Librem 5 at all, it would work the same way on any other Debian-based computer.