War Card Game Python

First the cards from the first player, then the one from the second player (for a 'war', all the cards from the first player then all the cards from the second player). For example, if the card distribution is the following: Player 1: 10D 9S 8D KH 7D 5H 6S Player 2: 10H 7H 5C QC 2C 4H 6D Then after one game turn, it. Python War card game For Beginners. Started by Durakken February 16, 2009 12:30 AM. 1 comment, last by Hollower 12 years, 2 months ago.

  1. War Card Game Python
  2. War Card Game Python Source Code
  3. War Python Code
  4. War Card Game Python

War is a classic kids card game. I spent many an hour wiling away the time playing war growing up. Enough so that I actually developed a strategy for the game. A strategy for the game of war? That's crazy talk.

War Card Game Python

For those who've never encounter the game of war here are the rules. A standard deck of 52 cards is shuffled and split between two equal stacks which are then given to the two players. The players then turn over the top card of their stacks and the player with the higher rank card 'wins' and gets to take the two cards and place them at the bottom of their stack. If the cards end up being the same rank, then a 'war' occurs. The players each deal two cards face down (it doesn't really matter that they are face down. Variants of the game include dealing one card face down instead of two.) They then each deal a face up card and the player with the higher rank of these cards wins. If the ranks are the same, then another war ensues. If at any time during a war, a player runs out of cards, then the last card they can play is used as the face up card for the war (this could even be the card which started the war.) The goal, of course, is to be the person who ends up with all the cards (this is war, after all.)

War card friv

So how in the world could there be a strategy for war? Well it all comes from the fact that when you win, you get to place cards at the bottom of the deck in an order which you get to choose. Of course if both players randomly place the winning bounty of cards onto the bottom of their deck, the game is symmetric and no one has an advantage. But what if you are playing against someone who randomly places cards at the bottom of the deck. Is there then a strategy which can give you an advantage?

When I was a kid I came up with just such a simple strategy for winning the game of war. My idea was that wars were very important in the game of war (whoda thunk?) and in particular it was important to try to setup your cards in such a was as to win as many wars as possible. The strategy thus worked by attempting to make the cards as close as possible to the template high, low, low, high, low, low, high, etc. One can do this by keeping track of where you are in such a template and then everytime you win ordering your cards so as to best match this template. There is some arbitrariness in this idea: for example if you win and get two cards which should be low, low in the sequence, which one do you put first? One could arbitrarily break ties for this problem or one could use a fixed strategy there as well. Yeah, all good and such, but does this strategy really provide any advantage?

Well, the question is, does my childhood strategy actually provide any advantage against a player that is randomizing the cards they put at the bottom of their deck? Today after many years of procrastination I cranked out a little python code to test this. The code implemented the strategy in a manner such that for any given sequence of high/lows that it was trying to match, the cards were sorted in such a way that the high's were sorted in descending order and the lows in descending order. Thus if you win the cards 1,5,10,7,8,9,6,12 and were trying to match high, low, low, high, low, low, high, low the order would be 12,1,5,10,6,7,9,8.

Python

And what are the results? Well it turns out that indeed this strategy does give you an advantage. After one million games of war, the player implementing this strategy won 548330 times. Okay, not a huge advantage, but not insignificant either.

But this got me thinking, what about other simple strategies? Suppose you follow a repeated template of high,low, for example? Or high,high,low? Note that because of the way I coded up the program there is sorting going on. Thus a high, high, template causes you to order your cards in increasing order and a low, low template causes you to order your cards in decreasing order. Here are the results of simulations of 100000 games:


TemplateWinsNotes
[high]51336 decreasing sort
[low]40632increasing sort
[high,low]42102
[hi,lo,lo]54854
[high,high,low]58190
[low,low,low,high]40653
[low,low,high,high]46947
[low,high,high,high]50196
Wins for the player using the strategy given in the template.

An interesting high performing strategy on this list is the high,high,low strategy. It's not obvious to me why this strategy performs so well, but it gives you a pretty significant edge against a random ordering player.

So that's my basic strategy for winning the card game of war. So go out and defeat the average uninformed war player! Fame and fortune will certainly surely then be yours.

David Lightman: What is the primary goal?
Joshua: You should know, Professor. You programmed me.
David Lightman: C'mon. What is the primary goal?
Joshua: To win the game.

  • Log in to post comments
Latest versionCard

Released:

A simple python module that implements a few classes need to construct a card game

Project description

Python-Card-Game

A simple python module that implements a few classes need to contruct a card game

Card game using pygame. Uses a custom card engine to help with GUI

War Card Game Python Source Code

  • Free software: ISC license
  • Documentation: https://Python-Card-Game.readthedocs.org.

Setup

use the requirements document in CardEngine and run the following

$ pip install cat pycardgame.req

let me know if you have issues getting your python configuredMine is: Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32 We don’t want python-3000

Credits

War Card Game Python

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

For Fun

Checkout markdown developed by daringfireball.

Project details


Release historyRelease notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Python-Card-Game, version 0.1.0
Filename, sizeFile typePython versionUpload dateHashes
Filename, size Python-Card-Game-0.1.0.tar.gz (12.2 kB) File type Source Python version None Upload dateHashes

War Python Code

Close

Hashes for Python-Card-Game-0.1.0.tar.gz

War Card Game Python

Hashes for Python-Card-Game-0.1.0.tar.gz
AlgorithmHash digest
SHA25654dfac9eebf16073efc0fe8d82d8810bc88b40df9c8a626d0fa2167617ff5f38
MD5aaed899649056a910367d0218fb57e13
BLAKE2-2568db28210c419531715ded5ba2468fde3d984cbcd92713bc8840adaad5d98c2a2