After playing the card game War recently, I wonder about the probability of winning, and on average, how many “battles” were fought and how many wars waged in a single game? Intuitively, I figured the odds of winning were 50-50 because there really is no strategy to the game; it’s all chance.
To explore my intuition, I wrote a War card game simulator in a Jupyter Notebook. Interestingly, I found the odds usually came out to be about 40-60 in favor of player 2 winning, with an average of about 188 battles and 13 wars per game (sample size = 1,000 games).
War card game is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page. The face up card determines who wins the war and gets all 10 cards that are on the table at this point. If the face up card is again the same rank, then the war goes on, three more face down, one face up etc. First player to finish all their cards loses the game. If a player finishes their cards during a war without having enough cards to.
Python Is This Your Card
The results did not change significantly with a sample size of 10,000. Is there a bug in the code, or is it really advantageous to always be player 2?
The chart exposes some interesting insights, most notably, once a player starts winning, they continue to win. But on a smaller scale, say 10 games, there is more variability.
War Card Game Python
Here are the rules I used in the simulation:
Number of players: 2
Objective: Collect all of the cards in a standard deck of playing cards (excluding Jokers).
- The entire deck of cards is dealt in an alternating fashion to each player (each player receives 26 cards).
- Player 1 lays a card from the top of their deck face up on the table. Player 2 does the same.
- The card with the highest value wins the “battle”. The winning player collects all of the cards and sets them aside, face down. (Cards are valued 2 – A with 2 the lowest card and Ace the highest.)
- This process continues until each player lays down a card of equal value. This is a war!
- Procedures for a war:
- a. Each player lays down three cards face down.
- b. The fourth card is dealt face up. The card with the highest value (same as rule #3) wins the war and collects all of the cards.
- c. It is possible that the “war” cards could be of the same value, which incites an additional war. In this case the process repeats (steps a and b). The winner takes all of the cards.
- d. If a player does not have enough cards to complete the war (4 cards), they lose and the other player wins by default.
- When a player exhausts their deck of cards, their discard deck is played (without shuffling).
Mostly this was an excuse to have some fun programming in Jupyter Notebooks and using MatPlotLib. Any insight or comments would be appreciated. The Jupyter Notebook is here.