class TestDeckAPI(unittest.TestCase): # noinspection PyPep8Naming # This warning has been suppressed because naming convention of # methodName and runTest is required for unittest def __init__(self, methodName='runTest'): deck_location = 'D:\\code\\delirium\\tests\\test_data\\delirium.txt' self.deck = Deck() self.deck.load_text_list(deck_location) unittest.TestCase.__init__(self, methodName) def setUp(self): pass def tearDown(self): self.deck.shuffle_deck() def test_get_card(self): card = get_card('Noxious Gearhulk') self.assertEqual(card.name, 'Noxious Gearhulk') def test_load_text_list(self): card_list = [ 'Emrakul, the Promised End', 'Grim Flayer', 'Grim Flayer', 'Grim Flayer', 'Grim Flayer', 'Ishkanah, Grafwidow', 'Ishkanah, Grafwidow', 'Ishkanah, Grafwidow', 'Kalitas, Traitor of Ghet', 'Kalitas, Traitor of Ghet', 'Mindwrack Demon', 'Mindwrack Demon', 'Tireless Tracker', 'Liliana, the Last Hope', 'Liliana, the Last Hope', 'Liliana, the Last Hope', 'Liliana, the Last Hope', 'Dead Weight', 'Grapple with the Past', 'Grapple with the Past', 'Grasp of Darkness', 'Grasp of Darkness', 'Grasp of Darkness', 'Grasp of Darkness', 'Murder', 'Murder', 'Noxious Gearhulk', "Pilgrim's Eye", "Pilgrim's Eye", 'Ruinous Path', 'Traverse the Ulvenwald', 'Traverse the Ulvenwald', 'Traverse the Ulvenwald', 'Traverse the Ulvenwald', 'Vessel of Nascency', 'Vessel of Nascency', 'Vessel of Nascency', 'Blooming Marsh', 'Blooming Marsh', 'Blooming Marsh', 'Blooming Marsh', 'Evolving Wilds', 'Forest', 'Forest', 'Forest', 'Forest', 'Forest', 'Forest', 'Forest', 'Hissing Quagmire', 'Hissing Quagmire', 'Hissing Quagmire', 'Hissing Quagmire', 'Swamp', 'Swamp', 'Swamp', 'Swamp', 'Swamp', 'Swamp', 'Swamp', ] loaded_deck = [] for item in self.deck.cards: loaded_deck.append(item.name) self.maxDiff = None self.assertEqual(len(card_list), len(loaded_deck)) self.assertEqual(sorted(card_list), sorted(loaded_deck)) def test_draw(self): card = self.deck.draw() self.assertEqual(len(self.deck.cards), 59) self.deck.put_in_deck(card) def test_put_cards_in_graveyard(self): graveyard = [] self.deck.put_cards_in_graveyard(4, graveyard) self.assertEqual(56, self.deck.size()) self.assertEqual(4, len(graveyard)) for item in graveyard: self.deck.put_in_deck(item)
""" This script will determine the likely hood that you draw a specific card that you only have three copies of by a specific turn. Assumption is that you draw first. """ from lib.hand import Hand from lib.mtgsdk_wrapper import CardMock from lib.deck import Deck surgical = CardMock(name='Surgical Extraction') my_deck = Deck() my_deck.load_text_list('D:\\code\\delirium\\tests\\test_data\\draw_3_of.txt') turn = 3 # Change this variable to change the turn number to find the card by my_hand = Hand() deck_size = len(my_deck.cards) count = 0 draw_3_of = 0 while count < 10000: my_deck.shuffle_deck() my_hand.draw_starting_hand(my_deck) my_hand.draw(turn, my_deck) for card in my_hand.cards: if card.name == surgical.name: draw_3_of += 1
def test_load_deck_list(self): # John wants to calculate how often he will hit delirium off of a # turn 1 Vessel of Nascency in his GB Delirium deck. To do this # he needs to load his deck list. gb_delirium = Deck() gb_delirium.load_text_list('D:\\code\\delirium\\tests\\test_data\\' 'delirium.txt') # He knows the deck has sixty cards in it self.assertEqual(gb_delirium.size(), 60) # John then shuffles the deck gb_delirium.shuffle_deck() # John then draws 7 cards to his hand my_hand = Hand() my_hand.draw_starting_hand(gb_delirium) self.assertEqual(my_hand.size(), 7) # John realizes that he meant to get a a few specific cards in hand # first so he puts his hand back in the deck. count = 0 while (my_hand.size() > 0) and (count < 400): my_hand.put_in_deck(my_hand.cards[0], gb_delirium) count += 1 self.assertEqual(my_hand.size(), 0) # John gets a forest, swamp, and vessel in hand, # shuffles the deck, and then draws 4 more cards forest = CardMock(name='Forest', type='') swamp = CardMock(name='Swamp', type='') vessel = CardMock(name='Vessel of Nascency', type='') my_hand.get_card_from_deck(forest, gb_delirium) my_hand.get_card_from_deck(swamp, gb_delirium) my_hand.get_card_from_deck(vessel, gb_delirium) gb_delirium.shuffle_deck() my_hand.draw(4, gb_delirium) test_list = [] for item in my_hand.cards: test_list.append(item.name) self.assertEqual(my_hand.size(), 7) self.assertIn(forest.name, test_list) self.assertIn(swamp.name, test_list) self.assertIn(vessel.name, test_list) # John plays the forest and the vessel on turn 1 battlefield = [] my_hand.play(forest, battlefield) my_hand.play(vessel, battlefield) self.assertEqual(my_hand.size(), 5) # On his next turn John draws a card, plays a swamp, and cracks the # Vessel choosing to put all cards in graveyard my_hand.draw(1, gb_delirium) my_hand.play(swamp, battlefield) self.assertEqual(my_hand.size(), 5) my_graveyard = Graveyard() for item in battlefield: if item.name == vessel.name: battlefield.remove(item) my_graveyard.cards.append(item) break gb_delirium.put_cards_in_graveyard(4, my_graveyard.cards) self.assertEqual(5, len(my_graveyard.cards)) # check graveyard to see if delirium has been achieved my_graveyard.check_delirium() print(my_graveyard.delirium)
def test_gr_vengevine(self): # James wants to calculate how often he will get a playable hand # with the GR Vengevine deck. He defines a playable hand as two # castable creatures, a discard outlet, at least 2 lands, and # 2 vengevines by turn 3. He will start by loading his deck list. gr_vv = Deck() gr_vv.load_text_list('D:\\code\\delirium\\tests\\test_data\\' 'GR_vengevine.txt') # He knows the deck should have 60 cards in it. self.assertEquals(gr_vv.size(), 60) # James then shuffles the deck gr_vv.shuffle_deck() # Then he draws 7 cards to his hand my_hand = Hand() my_hand.draw_starting_hand(gr_vv) self.assertEqual(my_hand.size(), 7) self.assertEqual(gr_vv.size(), 53) # draw 3 more cards my_hand.draw(3, gr_vv) keep_hand = True creature_count = 0 land_count = 0 discard_count = 0 vengevine_count = 0 for card in my_hand.cards: types = get_types(card) # Check for 2 creatures that are castable in the first 3 turns. # Since the only creatures in the deck that are castable by # turn 3 are one drops we can just check converted mana cost. # Later we will have to make sure we have at least one red source. # This assumption does not count Hooting Mandrils since they usually # want a stocked graveyard. Hollow Ones count because with one # discard outlet there is a good chance to land one on turn 3. if 'Land' not in types: if card.cmc < 3 and 'Creature' in types: creature_count += 1 elif card.name == "Hollow One": creature_count += 1 # While we are checking creatures we should check for Vengevines elif card.name == "Vengevine": vengevine_count += 1 # Check for discard outlets if 'discard ' in card.text.lower(): discard_count += 1 # Since all the lands in the deck produce red mana and that is # all that is typically needed by turn 3 I am just checking to # to make sure that two lands have been drawn. else: land_count += 1 if creature_count < 2: keep_hand = False if land_count < 2: keep_hand = False if discard_count < 1: keep_hand = False if vengevine_count < 2: keep_hand = False count = 0 if keep_hand: count += 1 print(count)
class TestHand(unittest.TestCase): # noinspection PyPep8Naming # This warning has been suppressed because naming convention of # methodName and runTest is required for unittest def __init__(self, methodName='runTest'): self.island = CardMock(name='Island', type='') self.mountain = CardMock(name='Mountain', type='') self.tireless = CardMock(name='Tireless Tracker', type='') self.test_deck = Deck() self.my_hand = Hand() deck_location = 'D:\\code\\delirium\\tests\\test_data\\delirium.txt' self.gb_delirium = Deck() self.gb_delirium.load_text_list(deck_location) unittest.TestCase.__init__(self, methodName) def setUp(self): for _ in range(7): self.test_deck.cards.append(self.island) self.test_deck.cards.append(self.mountain) self.my_hand.cards = [] def tearDown(self): self.test_deck.cards = [] self.my_hand.cards = [] def test_draw_starting_hand(self): self.my_hand.draw_starting_hand(self.gb_delirium) self.assertEqual(len(self.my_hand.cards), 7) for item in self.my_hand.cards: self.my_hand.put_in_deck(item, self.gb_delirium) def test_put_in_deck(self): self.my_hand.draw_starting_hand(self.test_deck) self.my_hand.put_in_deck(self.mountain, self.test_deck) self.assertNotIn(self.mountain, self.my_hand.cards) self.assertIn(self.mountain, self.test_deck.cards) def test_get_card_from_deck(self): self.my_hand.get_card_from_deck(self.tireless, self.gb_delirium) test_list = [] for item in self.my_hand.cards: test_list.append(item.name) self.assertIn(self.tireless.name, test_list) test_list = [] for item in self.gb_delirium.cards: test_list.append(item.name) self.assertNotIn(self.tireless.name, test_list) for item in self.my_hand.cards: self.my_hand.put_in_deck(item, self.gb_delirium) def test_play(self): battlefield = [] self.my_hand.get_card_from_deck(self.tireless, self.gb_delirium) self.my_hand.play(self.tireless, battlefield) test_list = [] for item in battlefield: test_list.append(item.name) self.assertIn(self.tireless.name, test_list) test_list = [] for item in self.gb_delirium.cards: test_list.append(item.name) self.assertNotIn(self.tireless.name, test_list) for item in self.my_hand.cards: self.my_hand.put_in_deck(item, self.gb_delirium)
a forest, swamp, and vessel in you opening draw. """ import time from lib.graveyard import Graveyard from lib.hand import Hand from lib.mtgsdk_wrapper import CardMock from lib.deck import Deck # Start timer for profiling purposes start_time = time.time() # import the deck list gb_delirium = Deck() gb_delirium.load_text_list( 'D:\\code\\delirium\\tests\\test_data\\delirium.txt') # Initialize hand, battlefield, and graveyard my_hand = Hand() my_graveyard = Graveyard() battlefield = [] # Mock cards to be used in model forest = CardMock(name='Forest') swamp = CardMock(name='Swamp') vessel = CardMock(name='Vessel of Nascency') # Variables deck_size = len(gb_delirium.cards) # Initial size of imported deck count = 0 # Number of times model ran times_delirious = 0 # Number of times model found delirium was achieved
from lib.deck import Deck from lib.hand import Hand from lib.mtgsdk_wrapper import get_types # James wants to calculate how often he will get a playable hand # with the GR Vengevine deck. He defines a playable hand as two # castable creatures, a discard outlet, at least 2 lands, and # 2 vengevines by turn 3. He will start by loading his deck list. gr_vv = Deck() gr_vv.load_text_list('D:\\code\\delirium\\tests\\test_data\\' 'GR_vengevine.txt') deck_size = gr_vv.size() my_hand = Hand() count = 0 keep_count = 0 while count < 100000: gr_vv.shuffle_deck() my_hand.draw_starting_hand(gr_vv) # draw 3 more cards my_hand.draw(3, gr_vv) keep_hand = True creature_count = 0 land_count = 0 discard_count = 0