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 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)
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)
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)
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)
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)
def declare_war(self, aggressor, defender, status): if aggressor.player == defender.player: return 'hidden' if set(aggressor.wars).intersection(defender.wars): return 'disabled' if status == 'execute': War.new(aggressor, defender) return 'done' return self.end_order(status)
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')
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))
class TestWar(unittest.TestCase): def setUp(self): self.game = War() def test_play(self): self.assertIsInstance(self.game.play(), int) def test_game_is_over(self): self.assertFalse(self.game.game_is_over()) self.game.play() self.assertTrue(self.game.game_is_over())
class TestWar(unittest.TestCase): """ Submodule for unittests, derives from unittest.TestCase """ def setUp(self): """ Create object for all tests """ self.testgame = War() def tearDown(self): """ Remove dependencies after test """ self.testgame = None def test_conv_str(self): """ Test staticmethod. conv_str. Should return integer""" self.assertIsInstance(self.testgame.conv_str('knight'), int) def test_if_card_in_hand(self): """ Test method. card in hand. Should return bool val false """ self.testgame.player1.cards = [] self.testgame.player2.cards = [] self.assertFalse(self.testgame.if_card_in_hand())
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
class TestWar(unittest.TestCase): """ Submodule for unittests, derives from unittest.TestCase """ def setUp(self): """ Create object for all tests """ self.war = War() def tearDown(self): """ Remove dependencies after test """ self.war = None def test_generate_players(self): """Test if function generate players work""" self.assertEqual(len(self.war.players), 2) def test_draw_cards(self): """Test if function draw cards works""" self.war.draw_cards() self.assertEqual(len(self.war.players[0].cards), 25) def test_append_cards(self): """Test function append cards""" self.war.draw_cards() self.war.append_cards(0) self.assertEqual(len(self.war.players[0].cards), 27)
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)))
def __init__(self, reset=False, preset=False): self.model = { 'army': Army, 'battle': Battle, 'culture': Culture, 'land': Land, 'person': Person, 'player': Player, 'province': Province, 'title': Title, 'war': War, } connect('histemul') self.orders = {} if reset: client = MongoClient() db = client.histemul Player.drop_collection() Person.drop_collection() Army.drop_collection() Battle.drop_collection() War.drop_collection() Province.drop_collection() #collection = db.province_vo db.command('aggregate', 'province_vo', pipeline=[{'$match':{}}, {'$out': "province"}], allowDiskUse=True, cursor={}) if preset: Matthieu = self.new_player('Matthieu', division='fess', tinctures=['green', 'orange']) Pierre = self.new_player('Pierre', division='pale', tinctures=['blue', 'red']) Robert = self.new_person('Robert', True, datetime.date(975, 1, 1), Matthieu, 1) Jean = self.new_person('Jean', True, datetime.date(981, 1, 1), Pierre, 14) Philippe = self.new_person('Philippe', True, datetime.date(965, 1, 1), Pierre, 39) Matthieu.leader = Robert Matthieu.save() Pierre.leader = Jean Pierre.save() Berquinais = Title.objects.get(pk='Berquinais') Berquinais.holder = Robert Berquinais.name_number = {'Robert': 1} Berquinais.save() Orvence = Title.objects.get(pk='Orvence') Orvence.holder = Jean Orvence.name_number = {'Jean': 1} Orvence.save() Bourquige = Title.objects.get(pk='Bourquige') Bourquige.holder = Philippe Bourquige.name_number = {'Philippe': 1} Bourquige.save() Berquinais_province = Province.objects.get(name='Berquinais') Berquinais_province.controller = Robert Berquinais_province.save() Orvence_province = Province.objects.get(name='Orvence') Orvence_province.controller = Jean Orvence_province.save() Bourquige_province = Province.objects.get(name='Bourquige') Bourquige_province.controller = Philippe Bourquige_province.save() Army_Orvence = self.rally_troops(Pierre, Orvence_province, 'execute')
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))
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()
def on_enter_War(self, event): war = War() while war.state != 'End': war.step()
def test_war_deal(): game = War(human=False) n.assert_equal(len(game.player1), 26) n.assert_equal(len(game.player2), 26)
def run_game(): war_game = War() war_game.play()
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)
def setUp(self): self.game = War()
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()
#!/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()
def setUp(self): """ Create object for all tests """ self.war = War()
def main(): war = War() war.add_dealingPile() war.deal() war.make_move()
def test_play_round(): game = War(human=False) game.play_round() n.assert_equal(len(game.player1) + len(game.player2), 52)
def setUp(self): """ Create object for all tests """ self.testgame = War()
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)
def wars(self): from war import War return War.objects(Q(aggressors=self) | Q(defenders=self))
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()