Example #1
0
    def test_round_score_val(self):
        p1 = Hand(["AS", "AD"])
        p2 = Hand(["KC", "AC"])
        community = Hand(["QC", "JC", "10C", "AH", "2S"])

        scores = RoundScore({1: p1, 2: p2}, community).compute_score()

        self.assertEqual(Decimal("4.141211"), scores[1])
        self.assertEqual(Decimal("9.14"), scores[2])
Example #2
0
    def test_init_p1_override(self):
        round = SimpleRound(num_players=4, p1_override=Hand(["AS", "AD"]))

        self.assertEqual(4, len(round.player_hands.keys()))
        for ph in round.player_hands.values():
            self.assertEqual(2, len(ph.cards))

        self.assertEqual(5, len(round.community_cards.cards))
        self.assertEqual(round.player_hands[0].cards, Hand(["AS", "AD"]).cards)
Example #3
0
    def test_simple_round_outcome_tie(self):
        p1 = Hand(["AS", "2D"])
        p2 = Hand(["AC", "2H"])
        community = Hand(["QC", "JC", "10C", "5H", "2S"])

        sr = SimpleRound(num_players=2)
        sr.player_hands = {1: p1, 2: p2}
        sr.community_cards = community

        self.assertEqual(SimpleRound.Outcome.TIE, sr.determine_outcome(1))
        self.assertEqual(SimpleRound.Outcome.TIE, sr.determine_outcome(2))
Example #4
0
    def __init__(self, num_players: int = 4, p1_override: Hand = None):
        if num_players < 1:
            raise Exception("Can't play a round with less than 1 player")

        self.deck = Deck(omit_cards=p1_override).shuffle()
        self.player_hands = {}
        for i in range(0, num_players):
            if p1_override and i == 0:
                self.player_hands[i] = p1_override
                continue
            self.player_hands[i] = Hand(self.deck.deal_cards(2))
        self.community_cards = Hand(self.deck.deal_cards(5))
Example #5
0
    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)
Example #6
0
    def generate_possible_hands(player_hand: Hand,
                                community_cards: Hand) -> List[Hand]:
        possible_hands = [Hand(community_cards.cards.copy())]
        for i in range(0, 5):
            clone1 = community_cards.cards.copy()
            clone2 = clone1.copy()
            clone1[i] = player_hand.cards[0]
            clone2[i] = player_hand.cards[1]

            possible_hands += [Hand(clone1), Hand(clone2)]

        for i in range(0, 5):
            for j in range(0, 5):
                if i != j and i > j:
                    clone = community_cards.cards.copy()
                    clone[i] = player_hand.cards[0]
                    clone[j] = player_hand.cards[1]
                    possible_hands.append(Hand(clone))

        return possible_hands
Example #7
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)
Example #8
0
def simulate_round(num_players: int, p1_override: List[Tuple[str, str]]) -> SimpleRound.Outcome:
    sr = SimpleRound(num_players=num_players, p1_override=Hand(p1_override))
    return sr.determine_outcome(1)
Example #9
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)
Example #10
0
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)
Example #11
0
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

# Run model 10000 times
while count < 10000:
Example #12
0
    def test_collision_detected(self):
        self.ar.channels = {
            'ems1': {'min_max': [0, 80], 'type': 'digipot', 'prefix': 1000, 'last_value': 0, 'ems_on_off': False}, 
            'ems2': {'min_max': [0, 80], 'type': 'digipot', 'prefix': 2000, 'last_value': 0, 'ems_on_off': False}
        }
        hand = Hand(self.df, self.db, self.ar)
        hand.collision_detected("hand", "envelope_1", 1.0)
        self.assertFalse(self.ar.send_value.called)
        hand.collision_detected("hand", "envelope_1", 0.5)
        self.ar.send_ems_strength.assert_called_with({"ems1": 0.54, "ems2": 0.09})
        hand.collision_detected("hand", "envelope_1", 0.2)
        self.ar.send_ems_strength.assert_called_with({"ems1": 0.2, "ems2": 0.04})
        
        self.ar.reset_mock()
        
        
        multiplied_list_ems1 = self.multiply_lists(self.gesture_allpoints['ems1'],self.envelope_allpoints)
        multiplied_list_ems2 = self.multiply_lists(self.gesture_allpoints['ems2'],self.envelope_allpoints)
        assertions = []
        for each in range(50):
            dist = 1 - (each/50)
            hand.collision_detected("hand", "envelope_1", dist)
            if dist < 0.8:             
                index = int(Hand.my_round( 14 * (dist/0.8) ) )
                val_ems1 =  multiplied_list_ems1[index]
                val_ems2 =  multiplied_list_ems2[index]
                assertions.append(call.send_ems_strength({"ems1": val_ems1, "ems2": val_ems2}))
                
        self.ar.assert_has_calls(assertions)
        
        
        hand.gesture_list['test_gesture']['allpoints'] = {
            "ems1": [3,2,99],
            "ems2": [1,1,1]
        }        
        hand.envelope_list['envelope_1']['allpoints'] = [9,5,13]
        

        hand.collision_detected("hand", "envelope_1", 0.4)
        self.ar.send_ems_strength.assert_called_with({"ems1": 0.1, "ems2": 0.05})
        
        
        hand.collision_detected("hand", "no_target", 999999)
        self.ar.send_ems_strength.assert_called_with({"ems1": 0, "ems2": 0}, True)
Example #13
0
 def test_reload_db(self):  
     hand = Hand(self.df, self.db, self.ar)
     self.assertEqual(hand.envelopes, self.fake_mongo_envelope_reply({}))
     self.envelope_allpoints = [1,5,4]
     hand.reload_db()
     self.assertEqual(hand.envelopes, self.fake_mongo_envelope_reply({}))
Example #14
0
    def test_round_score_generate_possible_hands(self):
        score = RoundScore.generate_possible_hands(
            Hand(["2S", "3D"]), Hand(["4S", "5D", "6C", "7D", "8H"]))

        self.assertEqual(21, len(score))
        self.assertEqual(21, len(set(score)))
Example #15
0
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
            break
Example #16
0
def simulate_round_with_override(
        num_players: int,
        p1_override: List[Tuple[str, str]] = None) -> SimpleRound.Outcome:
    sr = SimpleRound(num_players=num_players, p1_override=Hand(p1_override))
    return sr.player_result(1)
Example #17
0
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