Files
  • main.py
  • wargame
  • VERSION
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# console-card-game-of-war by Alex Goretoy <[email protected]> http://alexgoretoy.com

import argparse
import logging
import names

from wargame.game import Game

# ***War Game***
# War is a card game designed for two players, utilizing a standard (French style) 52-card deck of playing-cards. The objective is to "capture" all the cards in the game before your opponent.
# *Gameplay*
# All cards are shuffled, and then divided equally to each player in face down stacks (one stack for each player). Each player reveals the top card of their deck simultaneously, with the player revealing the highest-ranking card winning that particular round and thusly "capturing" their opponent's card (in addition to retaining their card). Both cards are then returned to the round-winner's deck, placed face down at the bottom. Gameplay continues in the above fashion, with players playing out consecutive rounds, until one player runs out of cards and loses.
# *Rankings*
# Cards are ranked by face value, with Ace, King, Queen, and Jack each (in order) taking the highest ranking, followed by number cards in numerical order (10 being worth more than a 9, etc.). Output must show face value and suite of the card.
# *Ties*
# In the event of a tie in a round - two players playing the same ranked cards - both cards are left face up between the two players, and play proceeds to the next round. The winner of the next round takes all cards from the current as well as previous round.
# *Challenge*
# Your challenge is to write an application to simulate a game of War. Play out a game in full, and output the winner. Additionally, outputting the results of each round, including the card that each player played as well as the verdict of which player won. If no winner exists after 100 rounds, the game ends with a prompt to play chess instead.

parser = argparse.ArgumentParser()
parser.add_argument('-v', '--verbose', action='count', default=1)
args = parser.parse_args()

levels = [logging.WARNING, logging.INFO, logging.DEBUG]
level = levels[min(len(levels)-1, args.verbose)]

logging.basicConfig(level=level, format="%(message)s")


def run():
    Game(name=names.get_full_name()).join(
        names.get_full_name(), names.get_full_name()
    ).start()

if __name__ == '__main__':
    run()
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux