Tweaking difficulty level of Chess to make it easier, via minor source code change

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 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! :smiley:

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.


I did laugh, not at your effort but because of what you turned the computer opponent into.


And I always thought it was just me…
There are apparently some others with this challenge, with some workarounds.

1 Like

I need one that makes Checkers easier. :rofl:

chess is a game of positional-strategy … not exactly for little children
it requires patience and the willingness to improve upon losses … besides it has an undo button when playing against the ''Ai" … unless it’s check-mate on the next move and you don’t see it coming :wink:

Really got a smile out of this. Such a good, simple example of what free software means.


You may want to tell the Marine Corps, even they are learning Chess now:

Given their future opponents, they may be better off learning “Go”.

I would argue that children generally do possess those virtues – how do you think they learned to walk, or talk? Try, fail, then try again, that’s what we all do regardless of age. :slight_smile:


i meant it as … you’re stuck in your ‘body’ while in the ‘matrix’ while you aren’t stuck in a game of chess … unless you really are … LOL

Sometimes it seems we spend the limited quantity of those for the basics and as we age, we have less and less of them to use for other activies - as proved by some adults - until our system is so slow that it only appears we’re being patient (but it’s just increased lag due to excess jumbled code and missing libraries :slight_smile: ).

The Matrix would have been an interesting movie about the imaginary chess of our minds - with Keanu as the rook who becomes a queen and changes the world (or just makes it checkers). Agent Smith can’t control the clock anymore. Previous versions of the matrix were likes of Throne chess or Rhombic chess (only seen as tie-in anime as the required CGI wasn’t advanced enough back then). And so on :sunglasses:

nah. it’s more like Keanu transforms into a super-sayan and kicks Freeza’s ass …

In chess terms, isn’t that pretty much the same? “I know move-fu” :wink:

1 Like

i can imagine a new Matrix like anime where the first thing they do to train Neo is to download a comprehensive Chess-master course … and the first thing Neo says after they jack-him-out is “i know Chess …” and Morpheus is like “show me !”

1 Like

This could only work with Battle Chess.

1 Like

I like the one in campy costumes from “The Prisoner” show in the 1960s. I think it was just one episode.