← Back to Royal Game of Ur

About the Royal Game of Ur

The Royal Game of Ur is about 4,500 years old, and one of the oldest board games in the world.

How to Play

The goal. The first to get all seven pieces along the path and off the board wins.

5
6
7
8
9
10
11
12
4
3
2
1
start
home
14
13
Your path, in order. The bottom row is yours and the top row is your opponent's; their path is the mirror image of yours, and the two of you share the middle row.

The path. Your pieces start off the board. They come on in your own row and run left (squares 1 to 4), then right along the whole middle row (5 to 12), then back into your own row (13 and 14), and off into home. Your opponent's pieces do the same on their side. The squares in your own row are yours alone; the middle row is where the fighting happens.

The dice. You throw four four-sided dice, each shaped like a little pyramid. Two of each die's four corners are marked, so each die lands with a marked tip on top half the time. That kind of makes it more like flipping a coin instead of rolling dice, but whatever. The number of marked tips showing is how far you move. That makes 2 the most common roll and 0 and 4 the rarest:

0 1 2 3 4
  • Roll 0 1 in 16 6.25%
  • Roll 1 4 in 16 25%
  • Roll 2 6 in 16 37.5%
  • Roll 3 4 in 16 25%
  • Roll 4 1 in 16 6.25%

Moving. On your turn, move one piece exactly the number you rolled. Bringing a new piece on is a move too: a roll of 1 puts it on square 1, a roll of 4 on square 4. You can't land on one of your own pieces, and a piece only goes home with the exact roll: from square 13 you need a 2, and from 14 a 1. If you can move, you must, even when every move is bad for you. If you roll a 0, or no piece can move that far, your turn passes.

Capturing. Land on one of your opponent's pieces in the middle row and it goes back off the board, to start over. Nobody can be captured in their own row, since the other player can't get there.

Rosettes. The five flower squares are rosettes. Land on one and you roll again. The one in the middle of the shared row (your square 8) is also safe: a piece standing there can't be captured, which also means nobody else can land on it until it leaves. Whoever holds it is a real nuisance to the other player.

Nobody knows the original rules for certain (see History, below), so there are several modern rule sets. These are the RoyalUr.net "Finkel" rules, named after the man who worked them out.

History

In the 1920s the archaeologist Leonard Woolley excavated the Royal Cemetery at Ur, a Sumerian city in what is now southern Iraq. Among the treasures in the tombs were several game boards from around 2600 to 2400 BC, inlaid with shell, red limestone and lapis lazuli, all with the same odd shape of twenty squares. One of them is now in the British Museum, and the place it was found gave the game its name.

The game wasn't just for royalty. Boards with the same twenty squares turn up all over the ancient Middle East and beyond, over a span of thousands of years. Tutankhamun was buried with a game box that has senet on one side and twenty squares on the other. Someone, perhaps a bored guard, scratched a board into one of the enormous winged bulls guarding the palace of the Assyrian king Sargon II at Khorsabad, and you can still see it in the British Museum.

How to play it was forgotten, until Irving Finkel, a curator at the British Museum, worked it out from a clay tablet in the museum's collection. It was written in Babylon in 177 BC by a scribe named Itti-Marduk-balāṭu, who copied it from an older tablet, and it explains how the game is played and even tells your fortune for landing on certain squares. The tablet doesn't settle everything, though (it doesn't say which way the pieces go round, for one), and it was written two thousand years after the boards at Ur were made, so the rules everyone plays today are Finkel's best reconstruction rather than the original game.

Remarkably, it never quite died out. The Jewish community of Kochi, in southern India, kept playing a version of it they called asha until the 1950s, when most of the community emigrated to Israel. These days it's having a revival, helped along by a British Museum video of Finkel playing the YouTuber Tom Scott, and by RoyalUr.net, where people play it online. Wikipedia has much more.

About the AI

First, I solved the game

Under these rules, the Royal Game of Ur has 137,913,936 possible positions. That sounds like a lot, but it's few enough to work out the exact chance that the player to move wins from every single one of them, assuming both sides play perfectly. That's called a strong solution of the game. (The RoyalUr.net folks solved it first; mine agrees with theirs.)

Captures make this harder than solving something like tic-tac-toe, where you can just work backwards from the end of the game. A capture sends a piece back to the start, so positions can lead round in circles. What saves it is that a piece that has made it home never comes back. So I grouped the positions by how many pieces have made it home, and solved the groups from the end of the game backwards: first the positions with twelve pieces home between the two players, then eleven, and so on down to the opening. Inside each group, the circles are still there, so the solver sweeps over the group again and again, updating every position's value from the positions it leads to, until nothing changes any more.

It takes about two minutes on my computer, and the answer for the opening is that the first player wins 51.54% of the time. That matches the published value to within a millionth, and since the opening is the last position solved, a mistake in any rule or anywhere in those 138 million positions would have thrown it off.

Then I taught a neural network to imitate it

The trouble is that the solved table is 263 MB, which is far too much to make you download to play a game. So instead I trained a small neural network to predict the table's answer for any position. It's four layers of 512 neurons, about 800,000 numbers in all, which is a 1.6 MB download: about 1/160th the size of the table.

To train it, I had the table play 400,000 games against itself, with mistakes deliberately mixed in so the network would also see the messy positions that real players get into, and added positions picked completely at random. Every position came with its exact value from the table, and the network learned to match them. Training took about six minutes on a graphics card.

Learning from exact answers is a big advantage. The AI for Boop, on this site, learned by playing itself and seeing who won, like DeepMind's AlphaZero. That works well for a game of pure skill, but in Ur the dice decide a lot of games, so "who won" is a very noisy lesson. Here the network never has to guess what a position was worth: the table tells it.

How it picks a move

On its turn, the computer looks at every legal move for its roll and asks the network how good the resulting position is for it. It can also look ahead: looking two rolls ahead, it considers every roll that could come next and the best move with each before asking the network, and looking three ahead it goes one roll further still. Expert plays the best move it finds looking three rolls ahead. All of this happens in your browser, in WebAssembly, and takes well under a millisecond.

Why it's so good, but not perfect

Because I have the exact table, I don't have to guess how strong the network is: I can check every move it makes against the perfect one. Over 10,000 games against perfect play, it played the very best move 98.3% of the time looking one roll ahead, and 99.1% looking two ahead. Adding up what its mistakes cost, it gives away 0.094 percentage points of winning chances per game looking one roll ahead, and 0.035 points looking two ahead. In other words, against a perfect player it wins about 49.97% of its games where perfection would win 50%. You'd need millions of games to notice the difference by counting wins. I haven't measured three rolls ahead yet.

It isn't perfect because a 1.6 MB network can't memorize 138 million exact values. Its estimates are off by about 0.07 percentage points on a typical position, and occasionally by as much as 0.8. Most of the time that doesn't matter, but when two moves are nearly tied, a small error can put them in the wrong order. Looking ahead helps because the computer then bases its decision on many positions instead of one, and their errors tend to cancel out. Even its worst mistakes are tiny: in all those games, no single move cost it more than 0.8 percentage points.

None of this means it wins every game. Perfect play only changes the odds, and the dice still decide plenty. Two perfect players would split their games almost evenly.

The strength settings

The weaker settings don't always play the best move. The computer rates every legal move, then picks one at random, favoring the better ones: strongly on Hard, less so on Medium, and only a little on Easy. Moves in Ur are often close in value, so a computer that's slightly careless with its choices is still a decent player. Here's how often each setting beats the best move looking two rolls ahead, over 2,000 games each:

SettingWins against the best
Easy3%
Medium19%
Hard42%
Expertabout 50%

For comparison, a player who picks every move completely at random didn't win a single one of 2,000 games.

The computer's chance of winning on the game screen is the network's estimate, looking two rolls ahead, of the computer's chance of winning from the current position if both of you play your best from here. On the easier settings the computer doesn't play its best, so its real chances are lower than it says. The hints use the same estimate: your chance of winning after each move you could make.

A few things the table taught me

Going first is worth a little. The first player wins 51.54% of the time with perfect play. The best opening roll is a 4 (55.87%), because it brings a piece straight onto a rosette and rolls again. The worst is a 0 (48.46%), which just hands the move to the other player.

Sometimes you'd rather not move at all. Say both players are down to their last piece, each sitting safely on square 3 of their own row. The two sides are in exactly the same situation, except for whose turn it is, and the player whose turn it is wins only 48.71%. The must-move rule forces them to walk their piece out of safety towards the shared row, where it can be captured. Rolling a 0 is better for them than a 1, 2 or 3.

The final race is 4 to 3. If both players have one piece left, each on square 14 needing an exact 1, the player to move wins exactly 4/7 of the time: a 1 comes up 4 times in 16, and any other roll hands the same situation to the opponent.