Example #1
0
def main():
    parser = argparse.ArgumentParser(description='Play a game of War.')
    parser.add_argument('--players',
                        type=int,
                        nargs='?',
                        required=True,
                        help='a count of players')
    parser.add_argument('--suits',
                        type=int,
                        nargs='?',
                        required=True,
                        help='a count of suits')
    parser.add_argument('--ranks',
                        type=int,
                        nargs='?',
                        required=True,
                        help='a count of ranks')
    parser.add_argument("--verbose",
                        help="show game in progress",
                        action="store_true")
    parser.add_argument("--slow",
                        help='wait for a second between turns',
                        action="store_true")
    args = parser.parse_args()

    w = War(count_of_players=args.players,
            count_of_suits=args.suits,
            count_of_ranks=args.ranks)
    winning_player = w.play(verbose=args.verbose, slow=args.slow)

    print "Winner: {0}".format(winning_player.name)
Example #2
0
 def test_hands(self):
     """ Check no cards are mixed or duplicate """
     self.game = War()
     self.game.start_game()
     while len(self.game.player_1.hand) > 0: # pylint:disable=len-as-condition
         test_card = self.game.player_1.show_card()
         self.assertNotIn(test_card, self.game.player_2.hand)
Example #3
0
def test_play_two_of_three():
    game = War(human=False)
    #There should be a dictionary that tracks win counts.
    n.assert_equal(max(game.win_counts.values()), 0)
    game.play_two_of_three()
    n.assert_equal(max(game.win_counts.values()), 2)
    #Make sure you don't get too many cards!
    n.assert_equal(len(game.player1) + len(game.player2) + len(game.pot), 52)
Example #4
0
def main():
    turt = turtle.Turtle()                  # turtle objects
    turt.hideturtle()
    o_turt = turtle.Turtle()
    o_turt.hideturtle()
    t_turt = turtle.Turtle()
    t_turt.hideturtle()
    u_turt = turtle.Turtle()
    u_turt.hideturtle()
    x_turt = turtle.Turtle()
    x_turt.hideturtle()
    p_turt = turtle.Turtle()
    p_turt.hideturtle()
    c_turt = turtle.Turtle()
    c_turt.hideturtle()
    c_turt.color('white')
    s_turt = turtle.Turtle()
    s_turt.color('white')
    s_turt.hideturtle()
    cs_turt = turtle.Turtle()
    cs_turt.color('white')
    cs_turt.hideturtle()
    turt.speed(0)
    wn = turtle.Screen()                    # makes screen
    wn.setup(width = 1200, height = 790, startx = None, starty = None)
    wn.bgcolor('turquoise')                 # sets color
    a = War()
    a.add_dealingpile()
    a.deal(wn, turt, u_turt, x_turt)         # deals cards
    play_game()
    while a.make_move(wn, turt) == True:                                        # continues running if there are cards in both hands
        a.remove_my_card()
        a.remove_other_card()
        a.display_card(wn, p_turt, c_turt)
        play_game()
        c = a.compare_cards()
        if c == 0:
            if a.compare_other(wn, u_turt, x_turt) == -1:
                a.remove_my_card()
                a.remove_other_card()
                a.display_card(wn, p_turt, c_turt)
                a.compare_cards()
                a.compare_other(wn, u_turt, x_turt)
            a.move_my_loot(wn, t_turt, turt)
            a.move_my_storage(wn, u_turt, o_turt, s_turt)
            a.move_other_storage(wn, x_turt, t_turt, cs_turt)
        elif c == 1:
            if a.compare_other(wn, u_turt, x_turt) == -1:
                a.remove_my_card()
                a.remove_other_card()
                a.display_card(wn, p_turt, c_turt)
                a.compare_cards()
                a.compare_other(wn, u_turt, x_turt)
            play_game()
            a.move_other_loot(wn, o_turt, turt)
            a.move_other_storage(wn, x_turt, o_turt, s_turt)
            a.move_my_storage(wn, u_turt, t_turt, cs_turt)
    wn.exitonclick()
Example #5
0
def test_play_game():
    game = War(human=False)
    game.play_game()
    n.assert_equal(len(game.player1) + len(game.player2) + len(game.pot), 52)
    n.assert_is_not_none(game.winner)
    if game.player1.name == game.winner:
        n.assert_equal(len(game.player2), 0)
    else:
        n.assert_equal(len(game.player1), 0)
Example #6
0
 def test_calculate_winner_when_evens_win(self):
     # given
     odds_points = {'positive': 15, 'negative': 5}
     evens_points = {'positive': 20, 'negative': 10}
     war = War()
     # when
     result = war.calculate_winner(odds_points, evens_points)
     # then
     self.assertEqual(result, 'tie')
Example #7
0
 def test_binary_conversion(self):
     #given
     int_data = [-100, 5, 100, -8]
     war = War()
     #when
     result = war.convert_to_binary(int_data)
     #then
     expected = ['-1100100', '101', '1100100', '-1000']
     self.assertEqual(result, expected)
Example #8
0
 def test_count_battle_points_for_evens(self):
     # given
     binary_data = ['-1100100', '101', '1100100', '-1000']
     war = War()
     # when
     result = war.count_battle_points(binary_data, '0')
     # then
     expected = {'positive': 7, 'negative': 5}
     self.assertEqual(result, expected)
Example #9
0
class CheckCards(unittest.TestCase):
    """Tests for the card class"""

    game = War()
    deck = Deck()
    card = Card(0, "hearts")


    def test_suit_number(self):
        """ Test if a setup card returns class variables """
        self.card = Card(6, "clubs")
        # __repr__ returns face_value, wich is value + 1 and suit
        self.assertEqual(str(self.card), "7 of clubs")


    def test_card_draw(self):
        """ Make sure drawn card is not in deck (list) """
        self.deck = Deck()
        drawn = self.deck.draw()
        self.assertNotIn(drawn, self.deck.cards)


    # def test_for_jokers(self):
    #     """ Are there any jokers in the deck? """
    #     self.deck = Deck()
    #     self.deck.add_jokers(2)
    #     self.assertIn("joker of spades", str(self.deck.cards))

    def test_deck_shuffle(self):
        """ See if shuffling works """
        self.deck = Deck()
        stacked = self.deck.cards
        self.deck.shuffle()
        shuffled = self.deck
        self.assertNotEqual(stacked, shuffled)

    def test_deck_stacked(self):
        """ Check if stacking works - sanity check """
        self.deck = Deck()
        stacked = self.deck.cards
        self.assertEqual(stacked, self.deck.cards)

    def test_hands(self):
        """ Check no cards are mixed or duplicate """
        self.game = War()
        self.game.start_game()
        while len(self.game.player_1.hand) > 0: # pylint:disable=len-as-condition
            test_card = self.game.player_1.show_card()
            self.assertNotIn(test_card, self.game.player_2.hand)

    def test_count_hands(self):
        """ Are players hands equally big? """
        self.game = War()
        self.game.start_game()
        self.assertEqual(len(self.game.player_1.hand),
                         len(self.game.player_2.hand))
Example #10
0
def game_driver(iterations=1):
    completed_iterations = 0
    w = War()
    while completed_iterations < iterations:
        game_in_session = True
        w.reset_game()
        while game_in_session:
            print('CURRENT DECK')
            print('PLAYER 1 DECK: \n{}, \n# CARDS: {}'.format(
                w.player_1.deck, len(w.player_1.deck)))
            print('PLAYER 2 DECK: \n{}, \n# CARDS: {}'.format(
                w.player_2.deck, len(w.player_2.deck)))
            # _ = input('CLICK FOR TURN NUMBER {}'.format(turns))
            print('PLAYING TURN # {}'.format(w.turns_of_play))
            w.take_turn()
            game_in_session = w.winner == None
        print("TOTAL TURNS FOR THIS GAME: {}\n" \
            "TOTAL WAR HANDS FOR THIS GAME: {}\n" \
            "WINNER: {}".format(w.turns_of_play, w.war_hands, w.winner.name))
        log_results(w.turns_of_play, w.war_hands, w.winner.name)
        completed_iterations += 1
Example #11
0
import tweepy
import os
import sys
from war import War

PATH = os.path.dirname(os.path.abspath(__file__))
IMG_PATH = PATH + '/output.jpg'
CSV_PATH = PATH + '/data/war_data.csv'
ROWS = 6

war = War(CSV_PATH)
message = war.attack()
if message is None:
    sys.exit()
war.save_state()
war.image(IMG_PATH, ROWS)

# Authenticate to Twitter
auth = tweepy.OAuthHandler("API key", "API secret key")
auth.set_access_token("Access token", "Access token secret")

# Create API object
api = tweepy.API(auth)
# Create a tweet
api.update_with_media(IMG_PATH, status=message)
Example #12
0
def test_play_round():
    game = War(human=False)
    game.play_round()
    n.assert_equal(len(game.player1) + len(game.player2), 52)
Example #13
0
def test_war_deal():
    game = War(human=False)
    n.assert_equal(len(game.player1), 26)
    n.assert_equal(len(game.player2), 26)
Example #14
0
def main():
    war = War()
    war.add_dealingPile()
    war.deal()
    war.make_move()
Example #15
0
 def setUp(self):
     """ Create object for all tests """
     self.war = War()
Example #16
0
from war import War

# play out one thousand games of war.
results = [War().play() for _ in range(1000)]

# and then report on how they went.
print(
    "After one thousand games of war, the shortest game had {} battles, the longest had {} battles, and the average was {}"
    .format(min(results), max(results),
            sum(results) / len(results)))
Example #17
0
 def setUp(self):
     self.game = War()
Example #18
0
from war import War
from TicTacToe import TicTacToe

War = War()
TTT = TicTacToe()

print("Your game options are: ")

print("\t(1) War")
print(
    "\t\tA Two player game of flipping and collecting cards until one person holds all of the cards,"
)
print("\t\tbut watch out, there's a twist if you flip over the sae card!")

print("\t(2) Tic Tac Toe")
print(
    "\t\tA one or two player game where people take turns placing an X or an O attemping to get three in a row"
)

while True:
    try:
        game = int(
            input(
                "\nPlease input the number of the game you would like to play: "
            ))
        break
    except ValueError:
        print("That was not a game number!")

if game == 1:
    War.game()
Example #19
0
def test_war_size():
    game = War(war_size=5, human=False)
    game.play_round()  #Play first to shuffle hand
    game.war()
    n.assert_equal(len(game.pot), 10)
Example #20
0
 def setUp(self):
     """ Create object for all tests """
     self.testgame = War()
Example #21
0
 def test_count_hands(self):
     """ Are players hands equally big? """
     self.game = War()
     self.game.start_game()
     self.assertEqual(len(self.game.player_1.hand),
                      len(self.game.player_2.hand))
Example #22
0
from Deck import Deck
from Player import Player
from war import War

if __name__ == "__main__":
    deck = Deck()
    Jon = Player("Jon Snow")
    Dave = Player("David Spade")
    war = War(Jon, Dave)
    deck.build_deck()
    deck.shuffle()
    war.deal(deck)

    # print(Dave)
    # # Dave.print_hand()
    # print(Jon)
    # Jon.print_hand()
    war.play_game()
    deck.shuffle()
Example #23
0
def run_game():
    war_game = War()
    war_game.play()
Example #24
0
#!/usr/bin/env python3
"""
Main file for War game
"""

from war import War

war_game = War(2)

war_game.new_game()

war_game.start_game()