Shuffling Strategies in War
Categories:
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:
- Always shuffle: Ruthlessly neutral approach, full reset.
- Never shuffle: Stay with what you’re dealt all the way
- Shuffle on strength: Combine and shuffle when you’ve got a strong hand
- 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)
- Strong if
- 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:
- Always shuffle when out of cards
- Always shuffle whenever given the chance
- Never shuffle
- Shuffle when mean(hand) > mean(pile)
- Shuffle when mean(hand) < mean(pile)
- Shuffle when Ace density in hand > Ace density in pile
- Shuffle when Ace density in hand < Ace density in pile
- Shuffle when face card density in hand > face card density in pile
- 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
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.
| S1 | S2 | P1 Wins | P2 Wins | Tie | P1 Turn Loss Average | P2 Turn Loss Average | Hands | Games |
|---|---|---|---|---|---|---|---|---|
| 3 | 0 | 51780 | 48220 | 0 | 7.902 | 7.966 | 29931220 | 100000 |
| 7 | 0 | 51515 | 48485 | 0 | 7.932 | 7.968 | 29788863 | 100000 |
| 5 | 0 | 51394 | 48606 | 0 | 7.977 | 7.99 | 29760910 | 100000 |
| 2 | 0 | 50304 | 49696 | 0 | 8.005 | 8.009 | 28338017 | 100000 |
| 0 | 0 | 49867 | 50133 | 0 | 8.001 | 8.0 | 28444920 | 100000 |
| 1 | 0 | 49690 | 50310 | 0 | 8.003 | 8.0 | 28374050 | 100000 |
| 6 | 0 | 48548 | 51452 | 0 | 8.048 | 8.036 | 26564007 | 100000 |
| 8 | 0 | 48308 | 51692 | 0 | 8.092 | 8.052 | 26637305 | 100000 |
| 4 | 0 | 48067 | 51933 | 0 | 8.117 | 8.055 | 26640254 | 100000 |
| 3 | 1 | 51808 | 48192 | 0 | 7.904 | 7.97 | 29934310 | 100000 |
| 7 | 1 | 51663 | 48337 | 0 | 7.926 | 7.975 | 29850829 | 100000 |
| 5 | 1 | 51473 | 48527 | 0 | 7.974 | 7.989 | 29716184 | 100000 |
| 2 | 1 | 50118 | 49882 | 0 | 8.0 | 8.003 | 28366913 | 100000 |
| 0 | 1 | 50082 | 49918 | 0 | 8.006 | 8.005 | 28306387 | 100000 |
| 1 | 1 | 49984 | 50016 | 0 | 8.002 | 8.004 | 28498197 | 100000 |
| 6 | 1 | 48391 | 51609 | 0 | 8.038 | 8.027 | 26679552 | 100000 |
| 8 | 1 | 48312 | 51688 | 0 | 8.089 | 8.039 | 26819193 | 100000 |
| 4 | 1 | 48059 | 51941 | 0 | 8.11 | 8.046 | 26830364 | 100000 |
| 3 | 2 | 51870 | 48130 | 0 | 7.899 | 7.964 | 29935030 | 100000 |
| 7 | 2 | 51453 | 48547 | 0 | 7.929 | 7.972 | 29888962 | 100000 |
| 5 | 2 | 51349 | 48651 | 0 | 7.978 | 7.985 | 29764117 | 100000 |
| 2 | 2 | 50082 | 49918 | 0 | 8.007 | 8.005 | 28382332 | 100000 |
| 1 | 2 | 49963 | 50037 | 0 | 8.0 | 8.0 | 28321730 | 100000 |
| 0 | 2 | 49962 | 50038 | 0 | 8.001 | 8.005 | 28390324 | 100000 |
| 6 | 2 | 48518 | 51482 | 0 | 8.047 | 8.033 | 26588704 | 100000 |
| 4 | 2 | 48041 | 51959 | 0 | 8.115 | 8.059 | 26600390 | 100000 |
| 8 | 2 | 47930 | 52070 | 0 | 8.091 | 8.053 | 26600826 | 100000 |
| 3 | 3 | 49957 | 50043 | 0 | 7.864 | 7.868 | 31761935 | 100000 |
| 7 | 3 | 49686 | 50314 | 0 | 7.89 | 7.866 | 31826111 | 100000 |
| 5 | 3 | 49346 | 50654 | 0 | 7.936 | 7.886 | 31594946 | 100000 |
| 0 | 3 | 48420 | 51580 | 0 | 7.966 | 7.906 | 29919192 | 100000 |
| 2 | 3 | 48243 | 51757 | 0 | 7.959 | 7.9 | 30169512 | 100000 |
| 1 | 3 | 47693 | 52307 | 0 | 7.966 | 7.899 | 29849804 | 100000 |
| 6 | 3 | 46637 | 53363 | 0 | 8.003 | 7.925 | 27948796 | 100000 |
| 4 | 3 | 46556 | 53444 | 0 | 8.077 | 7.949 | 28042695 | 100000 |
| 8 | 3 | 46508 | 53492 | 0 | 8.055 | 7.945 | 27945946 | 100000 |
| 3 | 4 | 53742 | 46258 | 0 | 7.953 | 8.076 | 27842569 | 100000 |
| 5 | 4 | 53621 | 46379 | 0 | 8.026 | 8.101 | 27588998 | 100000 |
| 7 | 4 | 53608 | 46392 | 0 | 7.976 | 8.087 | 27878300 | 100000 |
| 0 | 4 | 52087 | 47913 | 0 | 8.056 | 8.108 | 26620616 | 100000 |
| 2 | 4 | 51870 | 48130 | 0 | 8.057 | 8.115 | 26584317 | 100000 |
| 1 | 4 | 51797 | 48203 | 0 | 8.043 | 8.106 | 26840138 | 100000 |
| 8 | 4 | 50038 | 49962 | 0 | 8.139 | 8.151 | 25171604 | 100000 |
| 4 | 4 | 49961 | 50039 | 0 | 8.16 | 8.159 | 25229869 | 100000 |
| 6 | 4 | 49937 | 50063 | 0 | 8.089 | 8.138 | 25171799 | 100000 |
| 3 | 5 | 50361 | 49639 | 0 | 7.886 | 7.937 | 31445577 | 100000 |
| 7 | 5 | 50254 | 49746 | 0 | 7.914 | 7.944 | 31540836 | 100000 |
| 5 | 5 | 49998 | 50002 | 0 | 7.957 | 7.962 | 31394865 | 100000 |
| 2 | 5 | 48613 | 51387 | 0 | 7.987 | 7.971 | 29795102 | 100000 |
| 0 | 5 | 48372 | 51628 | 0 | 7.985 | 7.976 | 29728723 | 100000 |
| 1 | 5 | 48318 | 51682 | 0 | 7.986 | 7.972 | 29378570 | 100000 |
| 6 | 5 | 46998 | 53002 | 0 | 8.028 | 7.997 | 27559215 | 100000 |
| 8 | 5 | 46739 | 53261 | 0 | 8.08 | 8.017 | 27710291 | 100000 |
| 4 | 5 | 46393 | 53607 | 0 | 8.099 | 8.027 | 27622187 | 100000 |
| 3 | 6 | 53398 | 46602 | 0 | 7.93 | 8.007 | 27831833 | 100000 |
| 5 | 6 | 53333 | 46667 | 0 | 7.999 | 8.027 | 27577342 | 100000 |
| 7 | 6 | 53042 | 46958 | 0 | 7.954 | 8.015 | 27971068 | 100000 |
| 1 | 6 | 51935 | 48065 | 0 | 8.025 | 8.037 | 26767821 | 100000 |
| 2 | 6 | 51629 | 48371 | 0 | 8.028 | 8.045 | 26511521 | 100000 |
| 0 | 6 | 51421 | 48579 | 0 | 8.032 | 8.044 | 26520568 | 100000 |
| 6 | 6 | 50030 | 49970 | 0 | 8.067 | 8.069 | 25206137 | 100000 |
| 8 | 6 | 49791 | 50209 | 0 | 8.121 | 8.081 | 25294126 | 100000 |
| 4 | 6 | 49550 | 50450 | 0 | 8.14 | 8.088 | 25154688 | 100000 |
| 7 | 7 | 50249 | 49751 | 0 | 7.895 | 7.894 | 31691953 | 100000 |
| 3 | 7 | 49974 | 50026 | 0 | 7.867 | 7.891 | 31701461 | 100000 |
| 5 | 7 | 49731 | 50269 | 0 | 7.943 | 7.909 | 31454296 | 100000 |
| 0 | 7 | 48309 | 51691 | 0 | 7.976 | 7.931 | 29756751 | 100000 |
| 2 | 7 | 48223 | 51777 | 0 | 7.972 | 7.923 | 29910449 | 100000 |
| 1 | 7 | 48141 | 51859 | 0 | 7.976 | 7.929 | 29739674 | 100000 |
| 6 | 7 | 46726 | 53274 | 0 | 8.016 | 7.953 | 27884862 | 100000 |
| 8 | 7 | 46509 | 53491 | 0 | 8.064 | 7.966 | 27804877 | 100000 |
| 4 | 7 | 46318 | 53682 | 0 | 8.088 | 7.979 | 27910007 | 100000 |
| 7 | 8 | 53657 | 46343 | 0 | 7.97 | 8.063 | 27734990 | 100000 |
| 3 | 8 | 53570 | 46430 | 0 | 7.946 | 8.057 | 28045224 | 100000 |
| 5 | 8 | 53434 | 46566 | 0 | 8.018 | 8.08 | 27544830 | 100000 |
| 2 | 8 | 52196 | 47804 | 0 | 8.051 | 8.094 | 26572758 | 100000 |
| 0 | 8 | 52052 | 47948 | 0 | 8.05 | 8.094 | 26663275 | 100000 |
| 1 | 8 | 52044 | 47956 | 0 | 8.042 | 8.091 | 26761540 | 100000 |
| 6 | 8 | 49987 | 50013 | 0 | 8.081 | 8.114 | 25188068 | 100000 |
| 8 | 8 | 49952 | 50048 | 0 | 8.132 | 8.135 | 25319738 | 100000 |
| 4 | 8 | 49786 | 50214 | 0 | 8.15 | 8.138 | 25139605 | 100000 |
Repeatably 4, 6, & 8 are the lowest performing strategies.
- Always shuffle when out of cards
- Always shuffle whenever given the chance
- Never shuffle
- Shuffle when mean(hand) > mean(pile)
Shuffle when mean(hand) < mean(pile)- Shuffle when Ace density in hand > Ace density in pile
Shuffle when Ace density in hand < Ace density in pile- Shuffle when face card density in hand > face card density in pile
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
| S1 | S2 | P1 | P2 | Tie | P1 Turn Loss Average | P2 Turn Loss Average | Hands | Games |
|---|---|---|---|---|---|---|---|---|
| 2 | 0 | 500509 | 499491 | 0 | 8.003 | 8.003 | 283271057 | 1000000 |
| 0 | 0 | 499635 | 500365 | 0 | 8.005 | 8.004 | 283418923 | 1000000 |
| 1 | 0 | 499283 | 500717 | 0 | 8.003 | 8.004 | 283754309 | 1000000 |
| 2 | 1 | 499856 | 500144 | 0 | 8.003 | 8.002 | 283852523 | 1000000 |
| 0 | 1 | 499485 | 500515 | 0 | 8.004 | 8.005 | 284314502 | 1000000 |
| 1 | 1 | 499180 | 500820 | 0 | 8.003 | 8.004 | 284009174 | 1000000 |
| 2 | 2 | 500052 | 499948 | 0 | 8.005 | 8.003 | 283365571 | 1000000 |
| 1 | 2 | 499947 | 500053 | 0 | 8.003 | 8.004 | 283569165 | 1000000 |
| 0 | 2 | 499491 | 500509 | 0 | 8.004 | 8.002 | 283663059 | 1000000 |
| 3 | 2 | 517748 | 482252 | 0 | 7.901 | 7.96 | 299581251 | 1000000 |
| 7 | 2 | 516533 | 483467 | 0 | 7.928 | 7.97 | 299211470 | 1000000 |
| 5 | 2 | 513652 | 486348 | 0 | 7.973 | 7.986 | 297649574 | 1000000 |
| 2 | 2 | 499838 | 500162 | 0 | 8.003 | 8.002 | 283484007 | 1000000 |
| 3 | 3 | 499952 | 500048 | 0 | 7.862 | 7.862 | 318356897 | 1000000 |
| 7 | 3 | 498937 | 501063 | 0 | 7.89 | 7.872 | 317498149 | 1000000 |
| 5 | 3 | 494810 | 505190 | 0 | 7.937 | 7.884 | 315582298 | 1000000 |
| 2 | 3 | 483174 | 516826 | 0 | 7.962 | 7.9 | 299587274 | 1000000 |
| 7 | 5 | 503876 | 496124 | 0 | 7.912 | 7.943 | 314467736 | 1000000 |
| 3 | 5 | 503718 | 496282 | 0 | 7.884 | 7.936 | 315902611 | 1000000 |
| 5 | 5 | 499256 | 500744 | 0 | 7.962 | 7.96 | 314636869 | 1000000 |
| 2 | 5 | 486329 | 513671 | 0 | 7.985 | 7.975 | 297781468 | 1000000 |
| 3 | 7 | 501054 | 498946 | 0 | 7.872 | 7.888 | 317738623 | 1000000 |
| 7 | 7 | 500320 | 499680 | 0 | 7.896 | 7.897 | 316427148 | 1000000 |
| 5 | 7 | 495706 | 504294 | 0 | 7.945 | 7.911 | 315005757 | 1000000 |
| 2 | 7 | 483960 | 516040 | 0 | 7.971 | 7.926 | 299112511 | 1000000 |
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:
- Shuffle when mean(hand) > mean(pile)
- Shuffle when face card density in hand > face card density in pile
- 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.