Пример #1
0
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
            break

    for card in my_hand.cards:
        my_deck.put_in_deck(card)
    my_hand.cards = []

    if len(my_deck.cards) != deck_size:
        print('Error resetting game state')
Пример #2
0
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)
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
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

# Run model 10000 times
while count < 10000:
    gb_delirium.shuffle_deck()

    # Get swamp, forest, and vessel in hand then draw 4 more cards
    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)

    # Turn 1
    my_hand.play(forest, battlefield)
    my_hand.play(vessel, battlefield)

    # Turn 2
    #  Assumption: You do not return a card from vessel
    my_hand.draw(1, gb_delirium)
Пример #6
0
# 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
    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.