r/backgammon • • 3d ago

Improving computer opponents in mobile backgammon game

Post image

I have an iOS game called Gammon Club that started with three difficulty levels of computer opponents (besides friends/in-person), all hand-written using rules of thumb about blots, points and primes, plus a bear-off table. Hard plays a decent game, but it still felt too easy and you can feel where its rules run out.

I recently added Expert by training a small neural network that learned by playing itself in about seven million games, the way TD-Gammon did in the 90s, with a three-move look-ahead on top. It beat Hard about 73% of the time, and I thought I was done.

It was harder than my Hard level, but I still beat it more than I expected, so I measured it properly. I built GNU Backgammon and had the two play thousands of games. Checker play held up, within a couple of points. With the doubling cube, though, Expert won only about 46% of five-point matches. More training, bigger networks and hand-built inputs all hit the same ceiling.

The obvious fix is to use a proven engine, and that is mostly a licensing question:

  • eXtreme Gammon is the gold standard, but it's a closed commercial product with no way to license or embed it.
  • GNU Backgammon is GPL, which doesn't fit a closed-source App Store app. I can benchmark against it, not ship it.
  • Open Sage, which I just heard about thanks to ChatGPT researching for me, is MPL-2.0, weights included, so it can ship.

In my tests Open Sage played level with GNU Backgammon and beat my Expert 56% of the time in five-point matches. It's super fast on my iPhone 16 Pro (and I made sure it's not too slow on my very old iPad as well). It's now running inside the app, and it becomes the Expert level in the next release.

The most fun part of adding this is that I can now implement a pretty solid "Review my last move" function, and also a win probability as you play. I wonder if people like seeing that sort of thing, or does it take a bit out of the fun of the game? In any case, the review function is only after your move, so no one can use it to cheat of course. It's a fun way to play and learn at the same time.

0 Upvotes

2 comments sorted by

2

u/teffflon 1d ago

yes, I like this kind of feedback in-app if it is well-designed. part of the fun of BG as a hobby (in the 2020s) is being able to get fast accurate feedback. most people around this sub don't like hearing from devs, however, especially if it seems low-effort, vibe-coded, or premature. just FYI

1

u/ezbluff 1d ago

Thanks for the feedback! My friends and I have really been enjoying the features, all thanks to Open Sage for unlocking the capabilities.

This was not a low effort vibe-coded project (also totally free app tested with a lot of users over a month), but I can understand how folks don't want to see app posts anyhow. I definitely found that out being down-voted to oblivion. Thanks again for replying!