The Statistics of War (the card game)

During Thanksgiving Break I played the card game War with my girlfriend and remembered how wonderfully mindless it is.  Because there’s no strategy or decision-making, it was feasible to write a program to play the game.  Once I could simulate one game, I could simulate several and collect some statistics.

Evidently the rules of War have some gaps, including what to do with the cards you win.  Do you place them on the bottom of your deck, in order, or do you shuffle and reuse them once your deck is empty?  Why not program both methods and compare?  Here is a plot of both approaches after 100,000 trials of each.  The x-axis is the number of turns required to complete the game, and the y-axis is the frequency of that outcome across 100,000 trials.

The data proved more interesting than I expected.

  • Shuffling the winnings led to much faster games — a mean of 262, a mode of 84, and a max of 2,702 turns.
  • When the winnings aren’t shuffled, the numbers are less clear.  Many games were seemingly infinite so I added a cap of 5,000 turns per game.  11,837 (11.8%) of the games hit this limit (and do not appear on the graph).  But plenty of games ended after 4,000+ turns, so we could expect many of these long games to be finite as well.  If we ignore the capped games, the mode is 104 turns.
  • Both plots show a binary distribution of the results, as you can see in the higher and lower groupings of dots.  It turns out that games are more likely to finish after an even number of turns.  Each player starts with 26 cards, so if there are no wars and one player wins every hand, the game will last 26 turns.  For every turn that player loses, they must win an additional hand to cancel the loss, so the game still requires an even number of turns. Only a war will break this trend because 4 cards change possession instead of 1.  A game with an odd number of wars will take an odd number of turns to complete (ignoring wars with fewer than 3 cards, when one player’s deck is low).

As for the program, here it is in JavaScript.  The highlighted lines show the changes made between the Shuffle and No-Shuffle versions.

To close, enjoy the amazing uniqueness of a well-shuffled deck.

2 thoughts on “The Statistics of War (the card game)

  1. Benjamin

    I know this is an older post but I just wanted to say thank you! I was assigned the task of creating a program that could simulate a game of war and I designed it to not shuffle. Seeing the statistics laid out like this made it much easier to determine if my game lengths were falling in line with what you may expect from a typical game. The frequency of an endless game being played threw me off and I honestly thought there was something wrong with my code until I took a look at your data. Is the act of shuffling a common rule? Where I live everyone I have ever played with typically adds their winnings to the bottom of their pile as we go along. Thanks again!

    Reply
    1. Drew Post author

      Thanks Benjamin! I’m glad this old post could help you.

      When I learned to play War, we shuffled. I think this adds excitement to the game. My fiancée learned to play without shuffling, and so perhaps it’s no coincidence that she considers War a waste of time. The Wikipedia article seems to confirm that the rules are hazy on this point.

      In any event, this simulation was eye-opening for me and I’d definitely recommend shuffling to anyone who wants a quicker game. But then again, I remember as a kid playing War with my brothers during neverending car trips. Stretching out every game by not shuffling might be a better way to pass the time.

      Reply

Leave a Reply

Your email address will not be published.