← Back to Arpeggios

About Arpeggios

As with so many other games on this website, Arpeggios comes from Math with Bad Drawings. You can read the original rules in this PDF.

How to Play

Arpeggios is a dice game for two players. One player is the Ascending player, and the other is the Descending player. Each player is building a list of ten two-digit numbers: the Ascending player's list must go up, and the Descending player's list must go down.

On your turn, roll both dice. The two dice can be combined in either order to make a two-digit number -- so a roll of 2 and 6 can be either 26 or 62. You may take one of those two numbers and append it to your list, or you may pass the dice. If you pass, your opponent may use those same dice as their turn, or roll fresh dice for themselves.

If you roll doubles, you get an extra option: you may reroll one of the dice, leaving the other as is. If the rerolled die repeats itself, you're stuck with it.

Once per game -- and only once -- you may break your ascending or descending pattern, as a kind of reset button. In this game, that reset is marked with a thick line in your column.

The winner is the first player to list ten numbers.

The "Keep" button automatically keeps the better of the two options for dice order. For example, if you're ascending and it's your first move and you roll a 12, then obviously keeping a 12 is strictly better than keeping 21. So the button will always do that.

About the AI

I've solved Arpeggios. The AI plays perfectly. It knows the exact probability of winning from every game state, and it always chooses the move that maximizes its chances.

Here's the method. Every game state has some probability of winning. Each action available in a state brings you to another game state, with its own probability of winning, so the best move is simply the action that leads to the state with the highest chance of winning. Some actions, like rolling the dice, don't lead to just one state -- they can land in a bunch of possible next states, and the chances of going to the next game states don't have to be the same. For example, rolling 11 (or any doubles) has a probability of 1/36, while rolling a 24 (or any non-doubles) has a probability of 1/18. The value of rolling is the expected value over all of those outcomes.

Put that all together and you have an enormous system of equations: every game state is an unknown variable representing the probability of winning, defined in terms of the values of the states that can follow it. All together, there are 116,616,896 possible game states, so it's like solving a system of equations with that many unknowns. End game states have a known value: 1 if the computer wins and 0 if the computer loses. To solve the massive system of equations, I used an iterative technique. Every state starts with an arbitrary initial guess, and then each iteration updates every state's value using the current values of its possible next states. Repeat until the values converge and stop moving, and you're left with the true win probability -- and therefore the optimal action -- for every state in the game.

The last step was loading the solution into the WASM binary that runs in your browser, and doing it as efficiently as possible. For the optimal action, I needed 3 bits. Since there are 5 possible actions, 2 bits aren't enough. For the probabilities, I ended up using 6 bits. There's a tradeoff between accuracy and binary size. With 6 bits, the probability is accurate to within 1%.

Best First Moves

Here's the best action for the first player for every possible first roll, along with the probability of winning after taking it. I find it interesting that 36 is not monotonic compared to the rest of the actions. Apparently, giving the descending player a 63 is worse for you than keeping a 36. I also find it interesting that even though it's only the first move, the difference between the best first roll and the worst first roll is so large. With a best first roll of 11 or 12 (66.7%) vs the worst (33.3%), that's a shockingly big difference to me! Given that there's so much game remaining to be played, I would've thought the first roll wouldn't matter as much.

RollBest ActionProbability of Winning
11Keep66.7%
12Keep66.7%
13Keep65.1%
14Keep61.9%
15Keep60.3%
16Keep58.7%
22Keep57.1%
23Keep55.6%
24Keep54.0%
25Keep52.4%
26Keep50.8%
33Reroll One50.8%
34Pass47.6%
35Pass46.0%
36Keep39.7%
44Reroll One49.2%
45Pass44.4%
46Pass34.9%
55Reroll One46.0%
56Pass33.3%
66Reroll One41.3%