Audamir

part 57

Statistics during a game: what the window counts and how luck is calculated

What the Statistics window counts during a game, and how the Luck column is made from attacks: wins minus the expected wins by the odds of each attack. One attack step by step, a real game by turns and 2,000 simulated games.

· 22 min read

In the article on the menu, the windows and the saved state, Statistics is a button in the menu and a window that can be pinned to the top left. What the window counts, and where the number in the Luck column comes from, is not there. This article fills that in. The article on the analysis measures luck and the decision after a game, in the chance to win the whole game; the Statistics window counts it during the game and in the wins of single attacks. It is the same idea under another name, and the luck table in the Analysis takes exactly the same counters from the game.

The state is Audamir 0.124.1 (7 November 2026), the Principalities mode. The numbers come from the code of the game, from its documentation and from runs of the tools of the game; the game was only read. The commands are in the sources at the end. What is an explanation and not a measurement is marked as such.

Three answers in advance:

  • Luck is the sum over the player's attacks: won attacks minus expected wins. Each attack has a chance p before the roll. If it succeeded, the player gets 1 − p; if not, −p.
  • On average it is zero. In 2,000 simulated games of four equal AIs the average luck was +0.005 wins per player (±0.024), and the spread of the numbers (2.15) matched the one predicted by the chances of the attacks themselves (2.12).
  • Zero on average does not mean zero in the game. A typical player ends a game with luck around ±2 wins, and the winner in these games had +0.77 on average, the others −0.25. The number does not say whether the move was good.

What the window shows

The window opens with the Statistics button in the menu ☰ or with the key S, and after the end of a game with the button on the end card. It has three tabs: Overview, Chart and Log.

Overview is a table with a row for each player in the order of places (the row of the human is highlighted, an eliminated player is faded) and eleven columns. The names come from the catalogue of the game; the explanations appear when the mouse is over the header:

ColumnWhat it countsWhere it comes from
Tilesnumber of tilescounted from the map at each drawing
Dicenumber of dice on the mapfrom the map
Areathe largest connected area, the basis of reinforcements per movefrom the map
Attacksnumber of attacks madecounter
Wonwon attacks and their share, for example “55 (95 %)”counter
Defencesuccessful defences / number of attacks on the player, for example “3/34”counters of the defender
Conqueredtiles conqueredcounter
Losttiles lostcounter
Destroyed 🎲the defender's dice that stood on the tile when a successful attack happenedcounter
Lost 🎲own dice lost in an attack that failedcounter
Luckwon attacks minus the expected number of winscounter of wins and sum of the odds

The three columns about the map are read from the state of the game, so they always match what is on the board. The others are counters that the game keeps in game.stats and adds to after every resolved attack: Engine.resolveAttack calls Stats.recordAttack right after the result of the roll is carried over to the map. An open window refreshes during the game at most every 350 ms. The counters are saved together with the game in progress, so after a continuation they do not start from zero. The game keeps two more that the window shows nowhere: the dice the player got from reinforcements, and the largest stack he attacked with.

This is how the window looks in a game under way (round 4, four players; the AI played the game also in the seat of the human; game 0.124.1, 7 Nov 2026). Green is at −2.4 in the picture, that is 2.4 wins worse than the odds promised (red number), Yellow at +1.3 (green number), and the note under the table says the same in words:

The Statistics window in a game of Principalities under way: the tabs Overview, Chart and Log, a table with a row for each player and the columns from Tiles to Luck
The tiles, dice, attacks and defence of every player are in the table, and the Luck column says by how many wins the attacks differed from their odds.

And this is the Overview at the end of one real game. It is a game of the Principalities for four players (game number CLS4, 12 rounds, 140 attacks), the same as in the articles on the piece of music from one game and on the picture of one game. In the seat of the player “You” a stand-in AI of level 3 played, not a human; the opponents are AI of level 2. The numbers are from the same counters that the window reads (Stats.rows):

PlayerTilesDiceAreaAttacksWonDefenceConqueredLostDestroyed 🎲Lost 🎲Luck
You32188325855 (95 %)3/34553114513+2.7
Blue0004541 (91 %)6/5541498513−0.3
Green0002220 (91 %)2/302028355+0.9
Yellow0001513 (87 %)0/211321174−0.8

You won by conquering the whole map (32 tiles); the others have zeros in the first three columns, because they were eliminated. The numbers can be checked against each other: the conquered tiles add up to 55 + 41 + 20 + 13 = 129 and the lost ones 31 + 49 + 28 + 21 = 129; the attacks received add up to 34 + 55 + 30 + 21 = 140, which is also the number of attacks; of them 129 succeeded and 11 were defended (3 + 6 + 2 + 0).

Chart is a line chart of one of three quantities, Tiles, Dice or Largest area, by rounds, with a line for each player (the lines can be switched off in the legend). The points are written at the end of each round (Stats.snapshot) and the last point is live. Luck is not in the chart: the history keeps only the tiles, the dice, the largest area and the reserve of reinforcements.

Log is a list of events, the newest first: the round, who attacked whom, the number of dice on both sides, the sums of the rolls, the result (“conquered” or “failed”), reinforcements and eliminations. It can be filtered to All and Only mine. The window shows the last 1,000 records; the game keeps at most 2,000.

Two kinds of window

Statistics is either a window that covers the game and always has all the columns, or a window pinned above the board (the cog in the header): it floats over the map, the game is played beside it, and it needs a screen at least 700 px wide. Only in the pinned window can the columns be chosen; the ready choices are All columns, Short overview (Tiles, Dice, Area) and Only luck (the only column Luck). The Statistics at the end of a game always have all the columns and have no cog (DESIGN §21.5 and §30.5). Under the table there is a note “Luck = won attacks − expected number of wins according to the odds of the single attacks” while the column is on. With the setting Fog of war, the player sees a question mark instead of the dice, area and luck of the opponents until the game ends.

How luck is calculated

The definition is in one sentence and also in the code: at every attack the game remembers what chance of winning the attack had before the roll, and adds the chances up. Luck is the difference between how many attacks succeeded and that sum.

expected wins = sum of the chances p of all the player's attacks
luck          = won attacks − expected wins
contribution of an attack = 1 − p if it succeeded;  −p if it did not

The entry is in Stats.recordAttack: A.expected += roll.p, and on a win A.wins++. The number roll.p is computed by rollAttack before the roll from the dice on both tiles. The window then shows wins − expected with one decimal and a sign; from +0.5 the number is green, from −0.5 red.

The chance of an attack

The attacker rolls as many dice as he has on the tile, the defender as many as he has on the attacked tile. The one with the higher sum wins. On a tie the setting Tie in the roll decides: by default Defender wins (the original rule), otherwise Attacker wins or Roll again. The defence bonus is added to the defender's sum if the setting or the fortress gives it (a fortress gives 3 points); the chances take it into account. The function winChance in rules.js builds the distribution of the sum over the dice (each further die moves every sum by 1 to 6, each with a sixth), and the chance of the attack is the sum over all sums s the attacker can roll: the chance that he rolls it, times the chance that the defender (with the bonus) rolls less.

Chance of an attack: 1 to 8 dice of the attacker against 1 to 8 dice of the defenderTable 8 × 8: in a row the number of dice of the attacker, in a column the number of dice of the defender, in a cell the chance of the attack in percent according to the function of the game (a tie goes to the defender, the defence has no bonus). Equal numbers of dice give a chance of 41.7%, 44.4%, 45.4%, 46.0%, 46.4%, 46.7%, 46.9%, 47.1% (1 to 8 dice). Three dice against two give 77.9%, four against one 99.7%, one against four 0.1%.defender's diceattacker11223344556677884291<1<1<1<1<184441541<1<1<19778451961<1<1>9994744622831>999991724624104>99>99988870472612>99>99999686694727>99>99>999995846747Chance that the attacker's dice sum is above the defender's;on a tie the defender wins. Shaded: the same number of dice.Frame: 3 dice against 2, the text example (77.9%).
The chance of an attack for 1 to 8 dice of the attacker against 1 to 8 dice of the defender from the function Rules.winChance of Audamir 0.124.1 (7 Nov 2026) with the default rules: a tie goes to the defender, the defence has no bonus. Each value was checked by a listing of all rolls (33 pairs, the difference only in rounding). Equal numbers of dice are shaded.

The table shows that the same number of dice is not enough: 1 against 1 wins 41.7 % of attacks and 8 against 8 only 47.1 %, because a tie goes to the defender. Double the dice is a decision in small columns (2 against 1: 83.8 %), a certainty in big ones (4 against 2: 93.9 %, 8 against 4: 99.0 %). One die more matters less and less as the column grows: 3 against 2 has 77.9 %, 5 against 4 71.8 % and 8 against 7 67.3 %. And an attack of four dice on one succeeds in 99.7 %, one die on four in 0.1 %.

One attack step by step

The example is from the real game CLS4: attack no. 30 of 140, in round 1 Yellow attacks with three dice a tile with two. What happens:

  1. The chance before the roll. The game calls winChance(3, 2, 0, 'defender') and gets 0.7785. The picture shows it step by step: the attacker can roll a sum from 3 to 18 and each sum has its chance (column); the dark part is where the two dice of the defender give less. Five dice can be rolled in 6⁵ = 7,776 ways and in 6,054 of them the attacker wins. 6,054 / 7,776 = 0.7785. The listing of all 7,776 rolls gave the same, not only the formula.
  2. The roll. The attacker rolled 8, the defender rolled 8.
  3. The result. The sums are equal, the tie goes to the defender, the attack failed. The player is credited 0 − 0.7785 = −0.7785.
  4. What would have happened had it succeeded. It would have been credited 1 − 0.7785 = +0.2215.
  5. The average. With probability 0.7785 comes +0.2215 and with 0.2215 comes −0.7785: 0.7785 · 0.2215 − 0.2215 · 0.7785 = 0. The attack therefore on average adds nothing and takes nothing away.
Attack of three dice against two: how the chance of 77.9% arisesBar chart of the sums of the three dice of the attacker (3 to 18). The height of a bar is the chance of the sum, its dark part the chance that the two dice of the defender give a smaller sum, so the attacker wins. The dark parts add up to 6054 of 7776 possible rolls of five dice, that is 77.9%. The sum 8 is marked: with it the attacker wins against 21 of the 36 rolls of the two dice of the defender, and if the defender also rolls 8, the defender wins.0%4%8%12%chance that the attacker rolls this sum3456789101112131415161718sum of the attacker's three dicedefender rolls less, attacker winsdefender rolls equal or more, defender winsAltogether 6 054 of 7 776 rolls of five dice = 77.9%.Frame: the sum 8 in the text; the defender must roll less, 21 of 36.
An attack of three dice on two (attack no. 30 of game CLS4, Yellow in round 1, game 0.124.1, 7 Nov 2026): the distribution of the sum of the attacker's three dice and the part of it in which the two dice of the defender give a smaller sum. In all 6,054 of 7,776 rolls, that is 77.85 %. Values from Rules.winChance and from the listing of all rolls. The sum 8 is the one that fell in the game.

This is how every line of the number arises. The whole number in the window for Yellow is his 15 attacks of the whole game: 13 succeeded, 2 did not. The table lists them with what the game saw (rounds 1 to 3, then Yellow was eliminated):

RoundDiceChanceSumsResultContributionSum
15 against 298.8 %19 : 5succeeded+0.012+0.012
14 against 199.7 %18 : 5succeeded+0.003+0.015
14 against 199.7 %23 : 2succeeded+0.003+0.017
14 against 293.9 %10 : 7succeeded+0.061+0.078
13 against 197.3 %10 : 2succeeded+0.027+0.105
13 against 197.3 %8 : 2succeeded+0.027+0.132
13 against 277.9 %8 : 8failed−0.779−0.646
24 against 199.7 %18 : 5succeeded+0.003−0.644
24 against 199.7 %9 : 5succeeded+0.003−0.641
23 against 197.3 %17 : 1succeeded+0.027−0.614
23 against 277.9 %9 : 8succeeded+0.221−0.392
23 against 277.9 %14 : 7succeeded+0.221−0.171
22 against 183.8 %7 : 6succeeded+0.162−0.009
34 against 199.7 %11 : 2succeeded+0.003−0.006
33 against 277.9 %10 : 10failed−0.779−0.785

The sum is computed from unrounded values, so it need not equal exactly the sum of the rounded contributions. Thirteen wins gave +0.772 together and two losses −1.557; altogether −0.785, in the window −0.8, in red. Expected wins were 13.785 and 13 came. What is interesting is what this number is paid for: both losses are ties (8 : 8 and 10 : 10), which go to the defender under the default rule. And this is not an exception of this game: of the 11 failed attacks of the whole game, 6 were ties.

Why this is a fair measure

Luck is measured against the chance of the same attack. An attack with a chance of 26 % is +0.74 when it wins and −0.26 when it loses; an attack with a chance of 97 % is +0.03 when it wins and −0.97 when it loses. A player who takes risks is therefore neither penalised nor rewarded: each of these attacks has zero on average, so the sum has it too. The number thus measures neither courage nor strength, only by how much the dice added to or took away from what the odds promised.

Checked in the game

Chances: the function against the listing of rolls

For every pair of 1 to 6 dice against 1 to 6 dice whose total number of dice does not exceed ten (33 pairs, at most 6¹⁰ = 60 million rolls per pair), all the rolls were listed and counted in how many the attacker wins. The result differs from the function of the game by at most 3 · 10⁻¹⁶, that is by rounding. The table for 1 to 8 dice is from the function of the game; all 140 attacks of the game CLS4 have at most 8 dice on each side, so their chances are from the table; they agree with those the game wrote down at the attacks, to four decimal places.

Simulation: 2,000 games of four equal AIs

The average luck can be measured only over many games. The game has a tool that plays a whole game without waiting (Engine.playGame); the same tool is used by the measurement of the fairness of the order of turns. Here 2,000 games were played on the middle map (four players, seeds STAT0 to STAT1999), all four are AI of the same level 2. As in the fairness tool, the game does not end with the elimination of the player in the seat of the human, but only when a single living player is left, so that all the seats are on the same footing. After each game, Stats.rows(game)[i].luck is read for each player, that is the number the window would show. The only thing the script added is a copy of the write of the attack, which also adds p · (1 − p) for each attack to a sum: that is the variance the numbers should have if the model in the article holds.

Luck of a player at the end of the game in 2 000 games of four equal AIsColumn chart of the luck of 8 000 players in 2 000 games, one win wide per column. The columns form a hump around zero: the mean +0.005 wins, the standard deviation 2.15 (the chances of the attacks alone predict 2.12). The highest column is 0 to +1 (20.6% of the players). More than ±2 wins beyond expectation had 32% of the players, more than ±4 6.9%.0%5%10%15%20%25%share of the players in the games−8−6−4−20+2+4+6+8luck at the end of the game (one column = one win)plus and minus 2.1: the spread they predictthe attacks' chances alone (standard deviation)Dashed line: zero. Mean of all 8 000 numbers: +0.005.
Luck of the player at the end of the game in 2,000 games of four equal AIs of level 2 (8,000 numbers; middle map, four players, seeds STAT0 to STAT1999; the game goes on until one living player is left). Game 0.124.1, 7 Nov 2026, the command in the sources. The band is plus and minus 2.12: the variance that the chances of the attacks predict by themselves.
MeasurementValue
Games, players in the games2,000, 8,000
Average luck+0.005 (±0.024)
By place at the table (1st to 4th)−0.034, +0.009, +0.089, −0.043 (each ±0.04 to 0.05)
Standard deviation, measured2.15
Standard deviation predicted by the odds2.12
Attacks per player in a game, average chance of an attack64.6; 91.3 %
Wins in total and expected in total471,982; 471,941.4 of 516,807 attacks
Player in a game outside ±2 wins32.3 %, outside ±4: 6.9 %
Worst, best luck−11.4; +10.2

What follows from this:

  • The average is zero within the error, also for each place separately (each is at most 1.9 errors from zero). There were 41 wins more than expected out of 516,807 attacks, that is by eight hundred-thousandths.
  • The measured deviation agrees with the predicted one (2.15 against 2.12). That is firmer proof than the average: it means that the numbers the window counts behave exactly as the model describes them, even though the AI chooses attacks by the state of the game.
  • Luck around ±2 wins is common per game. Outside ±2 almost a third of the players ended. The window colours the number green from +0.5 and red from −0.5: in these games the green number was at 40.0 % of players, the red at 39.5 % and without colour at 20.5 %. The voice of the Avatar (described in article 053) speaks about the luck of the player in the seat of the human from ±1.6 after at least six attacks; a value of ±1.6 or more was at the end of the game at 41.6 % of players.
  • The AI level changes the spread, not the average. AI of level 3 (1,000 games, the same seeds as the first thousand) attacks less, on average 42.8 times per game against 64.6, and the spread is smaller: +0.042 (±0.027), measured deviation 1.73 and predicted 1.75. The average chance of an attack is 90.3 %.

Of the 2,000 games, 1,993 ended with the conquest of the whole map and seven got stuck in a stalemate and ended on points; the games had 14.8 rounds on average, the longest 42.

One real game by rounds

The simulation talks about the average, a game is played once. The picture shows the luck of the four players of the game CLS4 after every round, read from the counters of the game after every attack. The line of You (red, thick) rises to +2.1 by round 3, then wavers between +1.5 and +3.1 and falls by 0.5 in the last round: an attack of five dice on three with a chance of 91 % failed on a tie, 12 : 12. Yellow (eliminated in round 4) and Green (in round 5) do not attack from round 4 on, so their lines are flat. Blue drops from +0.6 to −1.0 in rounds 7 and 8: in each of these rounds one of its attacks failed, with a chance of 88 % and 94 %. Then the line rises a little again.

Luck of four players round by round in one gameLine chart of the cumulative luck (won attacks minus the expected wins) of the four players of the game CLS4, round 0 to 12. At the end of the game: You +2.7, Blue −0.3, Green +0.9, Yellow −0.8. The zero line is the luck as expected. A player who lost the last tile is no longer drawn: Yellow was eliminated in round 4, Green in round 5 and Blue in round 12.−10+1+2+3luck: won attacks minus expected wins024681012round of the game (state at the end of the round)× player out of tiles (Yellow round 4, Green round 5, Blue round 12)You +2.7Green +0.9Blue −0.3Yellow −0.8
Luck of four players of one game by rounds (Principalities, four players, game number CLS4, 12 rounds, 140 attacks; in the seat of the player “You” a stand-in AI of level 3 played, not a human; the opponents are AI of level 2). The values are the sum (win − odds) over the attacks so far, read from the counters of the game (Stats.rows) after every attack, not from the text of the window. Game 0.124.1, 7 Nov 2026.

The final numbers are those of the Overview table above. The game analysis (article 050) shows for the same game a table of Attacks, Wins, Expected and Luck with the same counters, only to two decimal places: You 58, 55, 52.33, +2.67; Blue 45, 41, 41.34, −0.34; Green 22, 20, 19.05, +0.95; Yellow 15, 13, 13.78, −0.78 (the analysis run over the record of that game, 4 s).

To read the number it has to be compared with its deviation. From the odds of the 58 attacks of You the predicted deviation is worked out as 2.12, so +2.7 is 1.3 deviations: better than the average, but common. In the simulation +2.7 or more was reached by 9.8 % of players (every tenth). Yellow has a predicted deviation of 0.99 from his 15 attacks, and −0.8 is 0.8 deviations; such or worse luck was had by 34.3 % of players.

What the number does not say

It does not say whether the move was good. An attack with a chance of 26 % may succeed and an attack with a chance of 97 % may fail. Luck is credited to how the rolls fell, not to whether the attack paid off. Whether it paid off is distinguished by the analysis of the game: its turning points are split into luck and decision in the chance of winning the whole game. The window speaks here only about the rolls.

It is credited only to the attacker. A defence that holds against an attack with a 91 % chance appears in the table only as a minus of the attacker; the defender gets nothing. The sum of luck of the four players therefore is not zero in the game: in the simulation it came out at +0.02 on average, but with a deviation of 4.26. The bad luck of an opponent appears nowhere in your number.

The average zero holds for all players together, not for the winner. The winner had luck on average +0.77 (±0.06) in the 2,000 games, the others −0.25 (±0.03). The luckiest of the four players won 45.0 % of games and the least lucky 17.8 %, while 25 % would be won by any of the four equally strong players if luck meant nothing.

How often the luckiest and the least lucky player wonTwo horizontal bars from 2 000 games of four equal AIs. The luckiest player of the game won 45.0% of the games, the least lucky 17.8%. The dashed line is 25%: that is what any of the four equally strong players would win if luck meant nothing.The luckiest of the players won45.0%The least lucky of the players won17.8%Dashed line: 25%, if luck meant nothing.2 000 games, four equal players, 2 000 games with a winner.
How often the luckiest and the least lucky of four equal AIs of level 2 won in the same 2,000 games. Game 0.124.1, 7 Nov 2026.

The measurement cannot say what is the cause and what the effect. An explanation (not a measurement): a player whose two attacks with a high chance fail loses columns of dice, and with them further attacks and tiles, and so loses more often; on the other hand a player who wins attacks for longer, and his luck lines get longer. Summed over all players the average stays zero, but the winner and the loser fall into different halves.

It does not count reinforcements or bonuses. Reinforcements are distributed at random or placed by the player himself, but they do not enter luck (the counter gained stays out of the sum). Attacks on neutral tiles are counted like the others.

The reroll bonus shifts the number (from reading the code, not measured). Engine.resolveAttack gets only the last roll of an attack and writes its chance; a failed roll that was repeated is not written at all. For an attack with chance p and one repeat, the chance of winning is p + (1 − p) · p, which is more than the written p, so in games with this bonus (according to DESIGN it is the campaign) luck has an expectation above zero. In the standard games and in the simulation there is no bonus.

What I take from it

  • Luck is the difference between the attacks won and the sum of the chances of those same attacks. Each attack adds 1 − p or −p and on average zero; the number measures rolls, not moves.
  • The number can be checked. The chances agree with the listing of all rolls, and the measured deviation 2.15 agrees with the prediction 2.12, so the window counts what it says.
  • Typical luck per game is around ±2 wins. Almost a third of the players are outside ±2, and +2.7 after 58 attacks is 1.3 deviations, nothing exceptional.
  • The winner tends to be luckier, but that is no proof that luck decides. The luckiest of the four won 45 % of games, the least lucky 17.8 %; cause and effect cannot be told apart from this.
  • Decisions are judged by something else. The window measures the rolls in attacks; where the game was decided is told by the analysis in article 050.

Sources and notes

  • State and method: Audamir 0.124.1 (7 Nov 2026), the Principalities mode. The game was only read; the tools ran over a copy of the tree (git archive) under ulimit -v (6 GB).
  • Picture of the window: scene stats in tools/video-teaser/shots.js (--lang sk,en), headless Firefox; a game differs in every run, so the numbers in the picture are not those of game CLS4.
  • Game CLS4: audamir-056-game.js (game principalities4, seed CLS4; the record was replayed by Replay.run and after every attack Stats.rows was read), table of the Analysis audamir-056-analysis-luck.js.
  • Chances and simulation: audamir-056-odds.js (Rules.winChance, listing of all rolls), audamir-056-sim.js (2,000 games of level 2, 1,000 of level 3), processing audamir-056-build-data.js → tools/charts-data/statistiky.json.
  • Code: js/ui/panels.js, js/realms/kastgard/games/stacks/core/stats.js, rules.js; docs/DESIGN.md §21.5, §30.5, §121.
  • Not measured: luck in games with campaign bonuses, in team games, with fog of war and with other tie rules; how the window looks on a phone.