Ejemplo n.º 1
0
def test_never_require_pick_up_cards_from_face_down(
        game_three_players_one_card_each):
    '''P1 should not be able to pick up when they only have face down cards'''
    # P1 Card(1, 4), P2 Card(2, 3), P3 Card(3, 3)
    hand_cards = [cards.Card(1, 4), cards.Card(2, 3), cards.Card(3, 3)]

    g = game_three_players_one_card_each
    g.players[1].hand.append(hand_cards.pop())
    g.players[2].face_up.append(hand_cards.pop())
    g.state.number_of_players_requested = 3
    g.state.deal_done = True
    g.state.ready_to_play = [1, 2, 3]
    g.state.players_ready_to_start = [1, 2, 3]
    # create a played pile which P1 cannot beat
    g.cards.pile_played = [cards.Card(3, 9)]
    print(jsonpickle.encode(g, unpicklable=False))

    g.state.play_order = [1, 2, 3]
    g.state.this_player_id = 1
    play_result = g.play_pick_up()
    print(play_result)
    # expecting this to be accepted as P1 can always play (only has a hand card left)

    assert not play_result[
        'action_result'], f"play_pick_up succeeded even but should always play face down cards: {play_result['action_message']}"
Ejemplo n.º 2
0
def test_allow_pick_up_cards_when_can_beat_with_face_up(
        game_three_players_one_card_each):
    '''P2 should not be able to pick up because they can beat the pile card with a face up card'''
    # P1 Card(1, 4), P2 Card(2, 3), P3 Card(3, 3)
    hand_cards = [cards.Card(1, 4), cards.Card(2, 3), cards.Card(3, 3)]

    g = game_three_players_one_card_each
    g.players[1].hand.append(hand_cards.pop())
    g.players[2].face_up.append(hand_cards.pop())
    g.state.number_of_players_requested = 3
    g.state.deal_done = True
    g.state.ready_to_play = [1, 2, 3]
    g.state.players_ready_to_start = [1, 2, 3]
    # create a played pile which P3 can beat
    g.cards.pile_played = [cards.Card(3, 3)]
    print(jsonpickle.encode(g, unpicklable=False))

    g.state.play_order = [3, 1, 2]
    g = swap_to_player(g, 3)
    play_result = g.play_pick_up()
    print(play_result)
    # expecting this to be acepted as P3 can beat this card with their face up card

    assert not play_result[
        'action_result'], f"play_pick_up succeeded even though we can beat it: {play_result['action_message']}"
Ejemplo n.º 3
0
def test_add_card(test_player_one_card_each_deck):
    '''check that we can add cards to a player ok'''
    p = test_player_one_card_each_deck
    # https://stackoverflow.com/questions/40382487/copy-a-list-of-list-by-value-and-not-reference/40382592
    c_face_down = getattr(p,
                          p.Pile_Objects[p.Card_Pile_ID.PLAYER_FACE_DOWN])[:]
    c_face_up = getattr(p, p.Pile_Objects[p.Card_Pile_ID.PLAYER_FACE_UP])[:]
    c_hand = getattr(p, p.Pile_Objects[p.Card_Pile_ID.PLAYER_HAND])[:]

    c = [cards.Card(2, 4), cards.Card(4, 3), cards.Card(3, 4)]

    p.add_cards_to_player_cards(c, cards.Card_Types.CARD_FACE_DOWN)
    p.add_cards_to_player_cards(c, cards.Card_Types.CARD_FACE_UP)
    p.add_cards_to_player_cards(c, cards.Card_Types.CARD_HAND)

    errors = []

    if getattr(p, p.Pile_Objects[
            p.Card_Pile_ID.PLAYER_FACE_DOWN]) != c_face_down + c:
        errors.append(
            f"cards.Card_Types.CARD_FACE_DOWN != c_face_down + c - player: {getattr(p, p.Pile_Objects[p.Card_Pile_ID.PLAYER_FACE_DOWN])}, expected {c_face_down + c}"
        )
    if getattr(p,
               p.Pile_Objects[p.Card_Pile_ID.PLAYER_FACE_UP]) != c_face_up + c:
        errors.append(
            f"cards.Card_Types.PLAYER_FACE_UP != c_face_up + c - player: {getattr(p, p.Pile_Objects[p.Card_Pile_ID.PLAYER_FACE_UP])}, expected {c_face_up + c}"
        )
    if getattr(p, p.Pile_Objects[p.Card_Pile_ID.PLAYER_HAND]) != c_hand + c:
        errors.append(
            f"cards.Card_Types.PLAYER_HAND != c_hand + c - player: {getattr(p, p.Pile_Objects[p.Card_Pile_ID.PLAYER_HAND])}, expected {c_hand + c}"
        )
    assert not errors, "errors occured:\n{}".format("\n".join(errors))
Ejemplo n.º 4
0
    def __init__(self, name=''):
        # initialize name, score, and card lists
        self.name = name
        self.actions = 0
        self.gold = 0
        self.buys = 0
        self._deck = cards.Cards()
        self._hand = cards.Cards()
        self._discard_pile = cards.Cards()
        self._cards_in_play = cards.Cards()
        self._card_dict = {
            'hand': self._hand,
            'deck': self._deck,
            'discard': self._discard_pile,
            'in play': self._cards_in_play,
        }

        # a player starts with three Estates and seven Coppers in deck
        estates = [cards.Card('Estate', 'Victory', 2) for amount in range(3)]
        coppers = [cards.Card('Copper', 'Treasure', 0) for amount in range(7)]
        self.add_cards('deck', estates)
        self.add_cards('deck', coppers)

        # shuffle deck and draw five cards
        self.shuffle()
        self.draw_hand()
Ejemplo n.º 5
0
    def testWasteToTableauFaceUp(self):
        """
        waste_to_tableau(waste : list, tab_col : list, stock : Deck)
        Returns:
            None

        Good suit, good rank.
        """
        # test source tableau
        test_src_card = cards.Card(rank=1, suit=1)
        if not test_src_card.is_face_up():
            test_src_card.flip_card()
        test_src_waste = [test_src_card]
        # test destination foundation with an ace on top
        test_tab_col_dest = [cards.Card(rank=2, suit=2)]
        #
        try:
            proj10.waste_to_tableau(test_src_waste, test_tab_col_dest)
        except TypeError as e:
            proj10.waste_to_tableau(test_src_waste, test_tab_col_dest, [])

        self.assertTrue(
            test_tab_col_dest[-1] == test_src_card,
            msg="tab_to_fnd should succed if source card is face up and valid."
        )
Ejemplo n.º 6
0
    def load_deck(self, input_file='', file_type="txt"):
        ''' need cockatrice XML parse here as well'''

        self.deck_file = input_file
        df = open(input_file)
        regular = re.compile(r'(\d+)\s+(.+)$')
        sideRe = re.compile(r'side(?i)')
        side = False
        for line in df.readlines():
            #  pre filters
            if sideRe.search(line):
                side = True
                continue
            if line.isspace() or line.find('#') >= 0 or line.find('/') >= 0:
                # probably a comment line
                continue
            card_line = regular.match(line)
            if not card_line:
                print("Odd line in deck: %s" % (line))
                continue
            num = int(card_line.group(1))
            card_name = card_line.group(2).strip()
            try:
                template = self.db.by_card[card_name]
            except KeyError:
                print("Could not find %s in db" % (card_name))
                continue

            for n in range(num):
                if side:
                    self.side.append(cards.Card(card_data=template))
                else:
                    self.main.append(cards.Card(card_data=template))
        self.total_cards = len(self.main)
Ejemplo n.º 7
0
	def __init__(self, name, hp, gender, country, skill=["杀","火杀","雷杀"]):
		self.name = name		#名称
		self.hp = hp			#体力
		self.max_hp = hp		#体力上限
		self.drink = 0			#有没有使用酒
		self.use_kill = 0		#使用了多少杀
		self.has_card = []		#手牌
		self.gender = gender
		# 武器,防具,+1,-1,宝物
		self.equip=[cd.Card(0,0,0,1)]
		for i in range(0,4):
			self.equip.append(cd.Card(0,0,0,0))
		self.judge = []
		self.get_in = [1,1,1,1,1,1]
		self.pos = 0
		self.seat = 0
		self.country = country
		self.dead = 0
		self.skill = skill
		self.on_card = []  #武将牌上的牌
		self.flip = 0      #是否翻面
		self.connect = 0		#是否横置
		self.attack_dis = 0		#是否有距离-1特性
		self.defence_dis = 0	#是否有距离+1特性
		self.auto = 0  # 是否为电脑

		self.chosen = [0]*120		#手牌是否被选中
		self.pl_chosen = [0]*120	#武将是否被选中
		self.using_limit = 0		#出牌阶段是否可以打出
		for i in range(4):
			self.has_card.append(cd.get_new_card())
		self.skill_init()
Ejemplo n.º 8
0
    def testWasteToTableauFaceUp(self):
        """
        tableau_to_tableau(tab1: list<Card>, tab2: list<Card>, n : int)
        Returns:
            None

        Good suit, good rank.
        """
        # test source tableau
        test_src_card = cards.Card(rank=1, suit=1)
        if not test_src_card.is_face_up():
            test_src_card.flip_card()
        test_tab_src = [test_src_card]
        n = 1
        # test destination foundation with an ace on top
        test_tab_col_dest = [cards.Card(rank=2, suit=2)]
        #
        try:
            proj10.tableau_to_tableau(test_tab_src, test_tab_col_dest)
        except TypeError as e:
            proj10.tableau_to_tableau(test_tab_src, test_tab_col_dest, n)

        self.assertTrue(
            test_tab_col_dest[-1] == test_src_card,
            msg="tab_to_tab should succeed if source card is face up and valid."
        )
Ejemplo n.º 9
0
    def __init__(self, situation=default_situation):
        """situation = (name, hp, gender, country)"""
        name, hp, gender, country = situation
        self.name = name  # 名称
        self.hp = hp  # 体力
        self.max_hp = hp  # 体力上限
        self.drink = 0  # 有没有使用酒
        self.use_kill = 0  # 使用了多少杀
        self.has_card = []  # 手牌
        self.gender = gender
        # 武器,防具,+1,-1,宝物
        self.equip = [cd.Card(0, 0, 0, 1)]
        for i in range(0, 4):
            self.equip.append(cd.Card(0, 0, 0, 0))
        self.judge = []
        self.get_in = [1, 1, 1, 1, 1, 1]
        self.pos = 0  #出牌顺序
        self.seat = 0  #显示的座次
        self.country = country
        self.dead = 0
        self.skill = ["杀", "火杀", "雷杀"]
        self.on_card = []  # 武将牌上的牌
        self.flip = 0  # 是否翻面
        self.connect = 0  #是否横置
        self.attack_dis = 0  # 是否有距离-1特性
        self.defence_dis = 0  # 是否有距离+1特性
        self.auto = 1  # 是否为电脑
        self.fire_col = 1000  #集火系数(死亡为0)

        for i in range(4):
            self.has_card.append(cd.get_new_card())
Ejemplo n.º 10
0
    def setUp(self):
        """
        Initialize a game.
        """
        # re-route cards to cards1

        # grab a few cards
        self._heart_two_card = cards.Card(rank=2, suit=3)
        self._heart_three_card = cards.Card(rank=3, suit=3)
        self._club_two_card = cards.Card(rank=2, suit=1)
        self._club_three_card = cards.Card(rank=3, suit=1)
        # face down card
        self._face_down_card = cards.Card(rank=1, suit=3)
        if self._face_down_card.is_face_up():
            self._face_down_card.flip_card()

        # with open('enbody_game_elements.pckl', 'wb') as outfile:
        # (fnd, tab, stock, waste) = proj10.setup_game()
        # enbody_game_elements = {'tab': tab, 'fnd':fnd, 'stock': stock, 'waste': waste}
        # pickle.dump(enbody_game_elements, outfile)

        self._enbody_game_elements_dict = {}  # temp
        try:
            with open('./enbody_game_elements.pckl', 'rb') as infile:
                enbody_game_elements_dict = pickle.load(infile)
                self._fnd = enbody_game_elements_dict['fnd']
                self._tab = enbody_game_elements_dict['tab']
                self._waste = enbody_game_elements_dict['waste']
                self._stock = enbody_game_elements_dict['stock']
        except FileNotFoundError:
            raise FileNotFoundError(
                'enbody_game_elements.pckl is required for this test.')
 def test_fullHouse(self):
     hand = game.Hand()
     hand.addCard(cards.Card(11, 'S'))
     hand.addCard(cards.Card(11, 'D'))
     hand.addCard(cards.Card(11, 'H'))
     hand.addCard(cards.Card(5, 'C'))
     hand.addCard(cards.Card(5, 'S'))
     self.assertEqual(evaluateHand(hand), {7: [11, 5]})
 def test_pair(self):
     hand = game.Hand()
     hand.addCard(cards.Card(10, 'S'))
     hand.addCard(cards.Card(9, 'H'))
     hand.addCard(cards.Card(7, 'S'))
     hand.addCard(cards.Card(4, 'C'))
     hand.addCard(cards.Card(4, 'S'))
     self.assertEqual(evaluateHand(hand), {2: [4, 10, 9, 7]})
 def test_twoPairs(self):
     hand = game.Hand()
     hand.addCard(cards.Card(10, 'S'))
     hand.addCard(cards.Card(9, 'H'))
     hand.addCard(cards.Card(9, 'S'))
     hand.addCard(cards.Card(8, 'C'))
     hand.addCard(cards.Card(8, 'S'))
     self.assertEqual(evaluateHand(hand), {3: [9, 8, 10]})
 def test_threeOfAKind(self):
     hand = game.Hand()
     hand.addCard(cards.Card(14, 'S'))
     hand.addCard(cards.Card(5, 'H'))
     hand.addCard(cards.Card(5, 'S'))
     hand.addCard(cards.Card(5, 'C'))
     hand.addCard(cards.Card(2, 'S'))
     self.assertEqual(evaluateHand(hand), {4: [5, 14, 2]})
 def test_straight(self):
     hand = game.Hand()
     hand.addCard(cards.Card(14, 'S'))
     hand.addCard(cards.Card(5, 'S'))
     hand.addCard(cards.Card(4, 'S'))
     hand.addCard(cards.Card(3, 'C'))
     hand.addCard(cards.Card(2, 'S'))
     self.assertEqual(evaluateHand(hand), {5: [5]})
 def test_fourOfAKind(self):
     hand = game.Hand()
     hand.addCard(cards.Card(12, 'S'))
     hand.addCard(cards.Card(12, 'D'))
     hand.addCard(cards.Card(12, 'H'))
     hand.addCard(cards.Card(12, 'C'))
     hand.addCard(cards.Card(9, 'S'))
     self.assertEqual(evaluateHand(hand), {8: [12, 9]})
 def test_straightFlush(self):
     hand = game.Hand()
     hand.addCard(cards.Card(13, 'S'))
     hand.addCard(cards.Card(12, 'S'))
     hand.addCard(cards.Card(11, 'S'))
     hand.addCard(cards.Card(10, 'S'))
     hand.addCard(cards.Card(9, 'S'))
     self.assertEqual(evaluateHand(hand), {9: [13]})
 def test_highCard(self):
     hand = game.Hand()
     hand.addCard(cards.Card(12, 'S'))
     hand.addCard(cards.Card(9, 'H'))
     hand.addCard(cards.Card(7, 'S'))
     hand.addCard(cards.Card(5, 'C'))
     hand.addCard(cards.Card(4, 'S'))
     self.assertEqual(evaluateHand(hand), {1: [12, 9, 7, 5, 4]})
 def test_royalFlush(self):
     hand = game.Hand()
     hand.addCard(cards.Card(14, 'S'))
     hand.addCard(cards.Card(13, 'S'))
     hand.addCard(cards.Card(12, 'S'))
     hand.addCard(cards.Card(11, 'S'))
     hand.addCard(cards.Card(10, 'S'))
     self.assertEqual(evaluateHand(hand), {10: []})
 def test_flush(self):
     hand = game.Hand()
     hand.addCard(cards.Card(13, 'S'))
     hand.addCard(cards.Card(11, 'S'))
     hand.addCard(cards.Card(10, 'S'))
     hand.addCard(cards.Card(7, 'S'))
     hand.addCard(cards.Card(4, 'S'))
     self.assertEqual(evaluateHand(hand), {6: [13, 11, 10, 7, 4]})
Ejemplo n.º 21
0
def some_cards():
    """List of different Card objects"""
    return [
        cards.Card("write book", "Brian", "done"),
        cards.Card("edit book", "Katie", "done"),
        cards.Card("write 2nd edition", "Brian", "todo"),
        cards.Card("edit 2nd edition", "Katie", "todo"),
    ]
Ejemplo n.º 22
0
def test_list(mock_cardsdb):
    some_cards = [
        cards.Card("some task", id=1),
        cards.Card("another", id=2),
    ]
    mock_cardsdb.list_cards.return_value = some_cards
    output = cards_cli("list")
    assert output.strip() == expected_output.strip()
Ejemplo n.º 23
0
 def __init__(self, win):
     self.counts = [-1, -1, -1, -1]
     self.demo_card = cards.Card('blank', 'start', 'images/back.png')
     self.draw_card = cards.Card('blank', 'start', 'images/back.png')
     self.cards = []
     self.top_card = cards.Card('blank', 'start', 'images/back.png')
     self.back_ground = pygame.image.load('images/back_ground.png')
     self.win = win
Ejemplo n.º 24
0
    def test_draw(self):
        deck = cards.Deck(
            "Test Deck",
            [cards.Card("A", "B"),
             cards.Card("C", "D"),
             cards.Card("E", "F")])

        self.assertRaises(IndexError, deck.draw_random, 4)
        self.assertEqual(set(deck.draw_random(3)), set(deck.cards))
        self.assertEqual(len(set(deck.draw_random(2))), 2)
Ejemplo n.º 25
0
def test_is_card_useful_killed_by_discard(killed_value):
    """
    A card should be not useful if any of the numbers lower than it have
    been entirely discarded, thus killing the color.
    """
    game = Game([])
    for _ in range(cards.Deck.CARD_COUNT_MAP[killed_value]):
        game.discards.append(cards.Card(cards.Colors.BLUE, killed_value))

    assert not game.is_card_useful(cards.Card(cards.Colors.BLUE, 5))
Ejemplo n.º 26
0
    def do(self):
        if cards.current_card is not None: cards.current_card.close(self.start_index - 1)

        if ("t" in self.args or "f" in self.args):
            front = "**True or False?**\n" + self.body
            answer = "**" + str("t" in self.args) + "**\n" # True for t arg and f if f arg
            cards.current_card = cards.Card(front=front, back=str(answer), add_reversed="q" in self.args, start_index=self.start_index)
        else:
            cards.current_card = cards.Card(front=self.body, add_reversed=("q" in self.args), start_index=self.start_index)

        super().do()
Ejemplo n.º 27
0
 def __init__(self):
     self._cards = []
     for rank in RANKS:
         for suit in SUITS:
             self._cards.append(cards.Card((rank, suit)))
     for rank in RANKS:
         for suit in SUITS:
             self._cards.append(cards.Card((rank, suit)))
     for x in range(0, 4):
         self._cards.append(cards.Card('X'))
     random.shuffle(self._cards)
Ejemplo n.º 28
0
	def died(self):
		print("%s猛然向后一倒,口吐鲜血,已是武功俱废"%(self.name))
		self.dead = 1
		self.equip = []
		self.equip = [cd.Card(0, 0, 0, 1)]
		for i in range(0, 4):
			self.equip.append(cd.Card(0, 0, 0, 0))
		self.judge = []
		self.has_card = []
		self.drink = 0
		self.connect = 0
		self.flip = 0
Ejemplo n.º 29
0
    def test_eq(self):
        card = cards.Card('A♡')
        rankmatches = cards.Card('A♣')
        suitmatches = cards.Card('7♡')
        neithermatch = cards.Card('7♣')
        bothmatch = cards.Card('A♡')

        self.assertEqual(card, card)
        self.assertNotEqual(card, rankmatches)
        self.assertNotEqual(card, suitmatches)
        self.assertNotEqual(card, neithermatch)
        self.assertEqual(card, bothmatch)
Ejemplo n.º 30
0
    def test_setitem(self):
        hand = cards.Hand('6♡Q♣4♡5♢7♣2♢')

        hand[0] = cards.Card('K♠')
        self.assertEqual(repr(hand), 'K♠Q♣4♡5♢7♣2♢')

        hand[-1] = cards.Card('6♡')
        self.assertEqual(repr(hand), 'K♠Q♣4♡5♢7♣6♡')

        cardlist = cards.Hand('T♠J♡8♠A♢')[:]
        hand[1:3] = cardlist
        self.assertEqual(repr(hand), 'K♠T♠J♡8♠A♢5♢7♣6♡')