Shuffling Strategies in War

Monte-Carlo simulation for exploring how shuffling strategies affect outcomes in the game of War

TL;DR: Bury your Aces Counterintuitively, in War you don’t want your hand to be packed with strong cards.

Simulation code available here.

Introduction

The card game War is, at its core, a game of dumb luck. Whoever gets the better draw usually walks away with the win. But there’s at least one way to get an edge.

Here’s the version I grew up playing:

  • Cards you win go into a discard pile.
  • When your hand runs out, you fold the discard pile back in.
  • When you recombine you may shuffle.
  • If your opponent recombines, you can combine and shuffle too.

That single choice of when to shuffle cracks open a surprising little window of strategy in an otherwise mindless game.

With these rules there’s four approaches:

  1. Always shuffle: Ruthlessly neutral approach, full reset.
  2. Never shuffle: Stay with what you’re dealt all the way
  3. Shuffle on strength: Combine and shuffle when you’ve got a strong hand
  4. Shuffle on weakness: Reset when you don’t have ‘good’ cards

Assume you’re a perfect cryptographic level RNG with this shuffling.

There are a few basic ways to define strong or weak hand?

  • Average Value: (Difficult in a real game)
    • Strong if mean(hand) > mean(pile)
    • Weak if mean(hand) < mean(pile)
  • Ace Density: The higher ace to card ratio, the stronger the hand. Trivial to do.
  • Face Card Density (J, Q, K, A): Superset of Ace Density.

My idea was that I can keep track of the face cards in my hand and in my discard pile to maximize their time in play. The key metric is number of face cards per card. If there’s a higher density in the pile than I will shuffle to get them back in circulation.

So I’ll consider these strategies and refer to them by number:

  1. Always shuffle when out of cards
  2. Always shuffle whenever given the chance
  3. Never shuffle
  4. Shuffle when mean(hand) > mean(pile)
  5. Shuffle when mean(hand) < mean(pile)
  6. Shuffle when Ace density in hand > Ace density in pile
  7. Shuffle when Ace density in hand < Ace density in pile
  8. Shuffle when face card density in hand > face card density in pile
  9. Shuffle when face card density in hand < face card density in pile

Rules

There are a couple edge gases to consider:

  • Last card War: If your final card triggers a war, you automatically lose.

  • Shuffling discarded sets: Any set of discarded cards is shuffled before returning to the pile. This avoids infinite loops that can occur when no shuffling is done and better reflects real-world play.

Interestingly there’s an advantage to be had in the order a player puts the cards back into their pile. If the high value then low value is added to the bottom of the deck there’s about a 10% advantage over the opposite. Stacking the cards exactly the same way each time also lead to infinite games so I chose to shuffle all the cards being added to the pile simulating the cards getting mixed up when playing.

Monte Carlo Simulation

To explore which strategy performs the best we first simulate all strategy pairs, two runs per permutation. Limiting the number of games initially keeps runtimes reasonable. Once the weaker strategies are identified, we discard them and rerun the remaining pairs with a larger number of games to improve statistical resolution.

The simulation is implemented in C++, using the std::shuffle function from to handle the shuffling operations.

Results

./War-simulator 100000 0 1 2 3 4 5 6 7 8

Sorted win/loss ratio of all strategies showing some strategies are better than others.

Win/Loss matrix of all strategies with the turn loss average residual. Note that the turn card value is inversely correlated with the win probability.

S1S2P1 WinsP2 WinsTieP1 Turn Loss AverageP2 Turn Loss AverageHandsGames
30517804822007.9027.96629931220100000
70515154848507.9327.96829788863100000
50513944860607.9777.9929760910100000
20503044969608.0058.00928338017100000
00498675013308.0018.028444920100000
10496905031008.0038.028374050100000
60485485145208.0488.03626564007100000
80483085169208.0928.05226637305100000
40480675193308.1178.05526640254100000
31518084819207.9047.9729934310100000
71516634833707.9267.97529850829100000
51514734852707.9747.98929716184100000
21501184988208.08.00328366913100000
01500824991808.0068.00528306387100000
11499845001608.0028.00428498197100000
61483915160908.0388.02726679552100000
81483125168808.0898.03926819193100000
41480595194108.118.04626830364100000
32518704813007.8997.96429935030100000
72514534854707.9297.97229888962100000
52513494865107.9787.98529764117100000
22500824991808.0078.00528382332100000
12499635003708.08.028321730100000
02499625003808.0018.00528390324100000
62485185148208.0478.03326588704100000
42480415195908.1158.05926600390100000
82479305207008.0918.05326600826100000
33499575004307.8647.86831761935100000
73496865031407.897.86631826111100000
53493465065407.9367.88631594946100000
03484205158007.9667.90629919192100000
23482435175707.9597.930169512100000
13476935230707.9667.89929849804100000
63466375336308.0037.92527948796100000
43465565344408.0777.94928042695100000
83465085349208.0557.94527945946100000
34537424625807.9538.07627842569100000
54536214637908.0268.10127588998100000
74536084639207.9768.08727878300100000
04520874791308.0568.10826620616100000
24518704813008.0578.11526584317100000
14517974820308.0438.10626840138100000
84500384996208.1398.15125171604100000
44499615003908.168.15925229869100000
64499375006308.0898.13825171799100000
35503614963907.8867.93731445577100000
75502544974607.9147.94431540836100000
55499985000207.9577.96231394865100000
25486135138707.9877.97129795102100000
05483725162807.9857.97629728723100000
15483185168207.9867.97229378570100000
65469985300208.0287.99727559215100000
85467395326108.088.01727710291100000
45463935360708.0998.02727622187100000
36533984660207.938.00727831833100000
56533334666707.9998.02727577342100000
76530424695807.9548.01527971068100000
16519354806508.0258.03726767821100000
26516294837108.0288.04526511521100000
06514214857908.0328.04426520568100000
66500304997008.0678.06925206137100000
86497915020908.1218.08125294126100000
46495505045008.148.08825154688100000
77502494975107.8957.89431691953100000
37499745002607.8677.89131701461100000
57497315026907.9437.90931454296100000
07483095169107.9767.93129756751100000
27482235177707.9727.92329910449100000
17481415185907.9767.92929739674100000
67467265327408.0167.95327884862100000
87465095349108.0647.96627804877100000
47463185368208.0887.97927910007100000
78536574634307.978.06327734990100000
38535704643007.9468.05728045224100000
58534344656608.0188.0827544830100000
28521964780408.0518.09426572758100000
08520524794808.058.09426663275100000
18520444795608.0428.09126761540100000
68499875001308.0818.11425188068100000
88499525004808.1328.13525319738100000
48497865021408.158.13825139605100000

Repeatably 4, 6, & 8 are the lowest performing strategies.

  1. Shuffle when mean(hand) < mean(pile)
  2. Shuffle when Ace density in hand < Ace density in pile
  3. Shuffle when face card density in hand < face card density in pile

The method of keeping a string hand is actually counterproductive. Instead, the winning move is to shuffle when your hand is strong, avoiding the risk of losing high-value cards in wars.

I added a metric, turn loss average, to test this. It tracks the value of face-down cards lost in war events. Since aces are 14 and the distribution is 2–14, the unbiased average should be 8. Strong hands show higher losses, explaining their worse performance.

I expect that strong hands have a higher risk of losing high value cards in a War event and this is a risk that isn’t offset by the higher utilization rate of the higher value cards.

Strong hands offer a better chance to win a war but increase the risk of losing high-value cards.

Deeper Simulation

After removing the underperforming strategy, I reran with 1M games:

./War-simulator 1000000 2 3 5 7 && ./War-simulator 1000000 0 1 2
S1S2P1P2TieP1 Turn Loss AverageP2 Turn Loss AverageHandsGames
2050050949949108.0038.0032832710571000000
0049963550036508.0058.0042834189231000000
1049928350071708.0038.0042837543091000000
2149985650014408.0038.0022838525231000000
0149948550051508.0048.0052843145021000000
1149918050082008.0038.0042840091741000000
2250005249994808.0058.0032833655711000000
1249994750005308.0038.0042835691651000000
0249949150050908.0048.0022836630591000000
3251774848225207.9017.962995812511000000
7251653348346707.9287.972992114701000000
5251365248634807.9737.9862976495741000000
2249983850016208.0038.0022834840071000000
3349995250004807.8627.8623183568971000000
7349893750106307.897.8723174981491000000
5349481050519007.9377.8843155822981000000
2348317451682607.9627.92995872741000000
7550387649612407.9127.9433144677361000000
3550371849628207.8847.9363159026111000000
5549925650074407.9627.963146368691000000
2548632951367107.9857.9752977814681000000
3750105449894607.8727.8883177386231000000
7750032049968007.8967.8973164271481000000
5749570650429407.9457.9113150057571000000
2748396051604007.9717.9262991125111000000

Strategy 3 (shuffle when mean(hand) > mean(pile)) gives the largest edge. Tracking face and even just tracking aces are close competitors.

Card counting also increases game length:

  • ~284 hands for simple strategies
  • ~300 for one card-counting strategy
  • ~315 for two card-counting strategies

Excess wins comparison shows that strategy 3 is the best but is closely followed by the other two card counting methods.

Conclusion

Count cards but shuffle, and protect your aces.

The top strategies are:

  1. Shuffle when mean(hand) > mean(pile)
  2. Shuffle when face card density in hand > face card density in pile
  3. Shuffle when Ace density in hand > Ace density in pile

Most of the benefit comes from tracking aces alone. The sweet spot: track aces, and shuffle when you hold many, to avoid losing them in war.