def test_playable_cards_on_draw_four(self): p = Player(self.game, "Player 0") self.game.last_card = c.Card(c.RED, None, c.DRAW_FOUR) self.game.draw_counter = 4 p.cards = [c.Card(c.RED, c.DRAW_TWO), c.Card(c.RED, '5'), c.Card(c.BLUE, '0'), c.Card(c.GREEN, '5'), c.Card(c.GREEN, c.DRAW_TWO), c.Card(None, None, c.DRAW_FOUR), c.Card(None, None, c.CHOOSE)] expected = list() self.assertListEqual(p.playable_cards(), expected)
def reset(self): self.cards.clear() for i in range(75): if i < 20: self.cards.append(card.Card( 25, '25', './images/low.png', )) # '25 dollar')) elif i < 40: self.cards.append(card.Card( 50, '50', './images/med.png', )) # '50 dollar')) elif i < 50: self.cards.append(card.Card( 100, '100', './images/high.png', )) # '100 dollar')) elif i < 55: self.cards.append(card.Card( 0, 'Skip', './images/skip.png', )) # 'Skips the other players turn')) elif i < 60: self.cards.append( card.Card( 0, 'Steal Money', './images/stealm.png', )) # 'Steals money from the other player')) elif i < 65: self.cards.append( card.Card( 0, 'Steal Card', './images/stealc.png', )) # 'Steals a card from the other player')) elif i < 70: self.cards.append(card.Card(0, 'Trade', './images/trade.png') ) #, 'Trade 2 cards with the other player')) else: self.cards.append(card.Card( 0, 'Draw 2', './images/draw.png')) #, 'Draw 2 cards from the deck'))
def createPlayerDeck(self, numEpidemic, numPlayer): deck = [] for c in util.yellowCities: deck.append(card.Card(2, c, "Yellow")) for c in util.blackCities: deck.append(card.Card(2, c, "Black")) for c in util.redCities: deck.append(card.Card(2, c, "Red")) for c in util.blueCities: deck.append(card.Card(2, c, "Blue")) shuffle(deck) # We take out 2 cards for each players as starting cards for y in range(2): for i in range(numPlayer): self.players[i].hand.append(deck[-1]) deck.pop() # Adding infection cards to the deck baseRange = math.floor(len(deck) / numEpidemic) nbLongerRanges = len(deck) % numEpidemic index = 0 for i in range(numEpidemic): if nbLongerRanges > 0: usedRange = baseRange + 1 nbLongerRanges -= 1 else: usedRange = baseRange randomPosition = randrange(0, usedRange) deck.insert(index + randomPosition, card.Card(3)) index = index + usedRange + 1 return deck
def noMine(self): self.timer1.start(15, self) self.myCard.append( card.Card(self, self.getRandomCard(), 150 + 25 * len(self.myCard), 510, True)) self.playButton.setDisabled(True) self.noButton.setDisabled(True) self.playButton.setStyleSheet( "QPushButton{background-image: url(empty.png)} QPushButton{border: none}" ) self.noButton.setStyleSheet( "QPushButton{background-image: url(empty.png)} QPushButton{border: none}" ) self.step = 0
def add_player(self, name: str, player_type: str): """ Метод, который добавляет игрока к игре с именем указанным в качестве входного параметра :param name: имя игрока player_type: тип игрока """ c_player = pl.Player(name) c_player.clean_card() c_player.type = player_type for i in range(self._i_card_number): c_card = cd.Card() c_card.set_card() c_player.add_card(c_card) self._l_players.append(c_player)
def run(self): print "" self.output.info('Starting disclosures module...') try: resp = self.request.send(url=self.url, method="GET", payload=None, headers=None, cookies=self.cookie) ip.IP(resp.content) email.Email(resp.content) card.Card(resp.content) except Exception, e: pass
def parsestringtocard(line): """ Split string into card object attributes. This splits a string into a card object. When the split array length is 1, the returned card object has only a name attribute. When the split array length is larger than 1, the returned card object got all attributes. :param line: String from file input :type line: str :return: Card object from parsed string :rtype: card """ assert line is not None split = line.split('|') if len(split) == 1: c = card.Card(split[0].rstrip('\n')) else: c = card.Card(split[0], split[1], split[2], split[3], split[4].rstrip('\n')) assert c is not None return c
def generate_pair_hands(rank, dead_cards=None): """Generates all possible pair hands for the given rank.""" if rank not in card.RANKS: raise ValueError('Invalid rank: %s' % rank) cards = [card.Card(s, rank) for s in card.SUITS] filtered_cards = cards if dead_cards: filtered_cards = [c for c in cards if c not in dead_cards] return [ poker_hand.HoldemHand(cards=c) for c in itertools.combinations(filtered_cards, 2) ]
async def show_creator(request): if "filename" in request.args: initialcard = card.from_file( str(request.args["filename"][0]) + ".yaml") else: initialcard = card.Card() initialcard.filename = card.get_vacant_filename() #initialcard.power = "" #initialcard.cp = "" #initialcard.steps = "" #initialcard.effects = "" #initialcard.flags = "" return {"card": initialcard}
def test_all_played(self): o_card1 = cd.Card() o_card1.set_card() o_card2 = cd.Card() o_card2.set_card() self.player.add_card(o_card1) self.player.add_card(o_card2) self.player.check_number(8) self.player.check_number(11) self.player.check_number(12) self.player.check_number(22) self.player.check_number(47) self.player.check_number(5) self.player.check_number(21) self.player.check_number(56) self.player.check_number(75) self.player.check_number(88) self.player.check_number(4) self.player.check_number(35) self.player.check_number(60) self.player.check_number(23) self.player.check_number(30) self.player.check_number(31) self.player.check_number(72) self.player.check_number(24) self.player.check_number(66) self.player.check_number(87) self.player.check_number(46) self.player.check_number(58) self.player.all_played() self.assertNotEqual("Win", self.player.state) self.player.check_number(76) self.player.all_played() self.assertEqual("Win", self.player.state)
def test_dealerScore(): """ Tests the dealerScore method for Blackjack objects """ deck = [card.Card(0, 12), card.Card(1, 10), card.Card(2, 9)] game = lab09.Blackjack(deck) cornell.assert_equals(9, game.dealerScore()) game.dealerHand = [card.Card(2, 2), card.Card(3, 1)] game.playerHand = [card.Card(1, 13), card.Card(0, 3)] cornell.assert_equals(13, game.dealerScore()) print('The dealerScore tests passed')
def test_playerScore(): """ Tests the playerScore method for Blackjack objects """ deck = [card.Card(0, 12), card.Card(1, 10), card.Card(2, 9)] game = bjack.Blackjack(deck) introcs.assert_equals(20, game.playerScore()) game.playerHand = [card.Card(2, 2), card.Card(3, 1)] game.dealerHand = [card.Card(1, 13), card.Card(0, 3)] introcs.assert_equals(13, game.playerScore()) print('The playerScore tests passed')
def test_playable_cards_simple(self): p = Player(self.game, "Player 0") self.game.last_card = c.Card(c.RED, '5') p.cards = [ c.Card(c.RED, '0'), c.Card(c.RED, '5'), c.Card(c.BLUE, '0'), c.Card(c.GREEN, '5'), c.Card(c.GREEN, '8') ] expected = [ c.Card(c.RED, '0'), c.Card(c.RED, '5'), c.Card(c.GREEN, '5') ] self.assertListEqual(p.playable_cards(), expected)
def deal_deck(self): """ Shuffle the deck and deal 13 cards to each player. Note that for Blind Nill purposes, the handing out of cards happens during the bidding phase. """ deck = [] for suit_id in range(4): for number_id in range(13): deck.append(card.Card(suit_id, number_id)) random.shuffle(deck) for i in range(4): hand = deck[13 * i: 13 * (i + 1)] self.hands[i] = hand self.dealer = (self.dealer + 1) % 4
def _process_text(self, text): "Assign values from text" # 1. Get the numbers to be called self.numbers = [int(x) for x in text[0].split(',')] # 2. Loop for the cards for index in range(1, len(text), 5): # 3. Build a card lines = text[index:index + 5] new_card = card.Card(text=lines) # 4. Add the card self.cards.append(new_card)
def test_playable_cards_on_draw_two(self): p = Player(self.game, "Player 0") self.game.last_card = c.Card(c.RED, c.DRAW_TWO) self.game.draw_counter = 2 p.cards = [ c.Card(c.RED, c.DRAW_TWO), c.Card(c.RED, '5'), c.Card(c.BLUE, '0'), c.Card(c.GREEN, '5'), c.Card(c.GREEN, c.DRAW_TWO) ] expected = [c.Card(c.RED, c.DRAW_TWO), c.Card(c.GREEN, c.DRAW_TWO)] self.assertListEqual(p.playable_cards(), expected)
def test_card_can_accept_barrel(self): test_card = card.Card() test_barrels = [] for line in range(3): for pos in test_card.lines[line]: if isinstance(pos, int): ans = test_card.can_accept_barrel(int(pos)) self.assertTrue(ans) test_barrels.append(int(pos)) for i in range(1, 91): if not (i in test_barrels): ans = test_card.can_accept_barrel(i) self.assertFalse(ans)
def main(): card_list = {} list1 = [] for i in range(0, 5): rand_card = card.Card() random_value = rand_card.selectAtRandom() card_list[rand_card.getRank()] = rand_card.getSuit() # print card_list # card_list=sorted(card_list.items(),key=lambda item:item[0]) print card_list for value in card_list: print value list1.append(int(value)) print list1 sort_list(list1)
def MakeDeck(self,num_of_decks): values = "A,2,3,4,5,6,7,8,9,10,J,Q,K".split(",") suits = "Hearts Clubs Spades Diamonds".split() DeckToReturn = [] for suit in suits: for value in values: DeckToReturn.append(card.Card(suit=suit,value=value)) # self.Cards = DeckToReturn if num_of_decks == 1 else ",".join([",".join(DeckToReturn) for _ in range(num_of_decks)]).split(",") if num_of_decks == 1: self.Cards = DeckToReturn else: for decks in range(num_of_decks): self.Cards.extend(DeckToReturn)
def newDeck(self): self.cards = [] faces = [ "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" ] suits = ["Clubs", "Spades", "Hearts", "Diamonds"] for suit in suits: for face in faces: c = card.Card(face, suit) self.cards.append(c)
def __init__(self): """ create a deck of 52 cards as a list """ self.__deck = [] suits = ['C', 'D', 'H', 'S'] rank = [ str(i) for i in range(SMALLEST_CARD_NUMBER, BIGGEST_CARD_NUMBER + 1) ] rank.extend(['J', 'Q', 'K', 'Ace']) for suit in suits: for j in range(len(rank)): my_card = card.Card(rank[j], suit, j + 2) self.__deck.append(my_card)
def GetMoves(self): """ Get all possible moves from this state. """ if self.game.current_player.cards: playable = self.game.current_player.playable_cards() playable_converted = list() for card in playable: if not card.color: for color in c.COLORS: playable_converted.append( c.Card(color, None, card.special)) else: playable_converted.append(card) # playable_converted.append('draw') return playable_converted or ['draw'] else: return list()
def create_card(suit, ordinal): """ * Creates a card given a suite and ordinal value. Creates the proper name * for the given ordinal. Does not error check for invalid ordinals :param suit: Suit of card to create :param ordinal: 2-14 numerical value for this card :return: Generated card given suit and ordinal data """ name = ordinal if ordinal == 11: name = "Jack" if ordinal == 12: name = "Queen" if ordinal == 13: name = "King" if ordinal == 14: name = "Ace" return card.Card(name, suit, ordinal)
def test_player_two_diamond_cards(self): player_1 = player.Player("Yildiz") player_1.add_card(card.Card(1, 0, yildor.onyx, 2, 2, 1, 0, 0)) player_1.add_card(card.Card(1, 0, yildor.diamond, 2, 2, 1, 0, 0)) player_1.add_card(card.Card(1, 0, yildor.diamond, 2, 2, 1, 0, 0)) player_1.add_card(card.Card(1, 0, yildor.ruby, 2, 2, 1, 0, 0)) player_1.add_card(card.Card(1, 0, yildor.emerald, 2, 2, 1, 0, 0)) player_1.add_card(card.Card(1, 0, yildor.sapphire, 2, 2, 1, 0, 0)) self.assertTrue(player_1.diamond_cards_currently() == 2) self.assertTrue(player_1.sapphire_cards_currently() == 1) self.assertTrue(player_1.emerald_cards_currently() == 1) self.assertTrue(player_1.ruby_cards_currently() == 1) self.assertTrue(player_1.onyx_cards_currently() == 1)
def handle_cards(filename): # Read cards im, contours = card.get_im_contours(filename) contours = card.filter_cards_contours(contours) trained = card.load_trained() cards = [] for contour in contours: my_card = card.Card(im, contour) my_card.predict(trained) cards.append(my_card) print(my_card) # Compute sets my_set = set.Set(im, contours, cards) # Show sets # my_set.show_sets() # Write sets prefix = os.path.basename(args.filename).split(".")[0] filenames = my_set.save_sets("save", prefix) return filenames
def test_print_player(self, print): self.game._i_card_number = 1 self.game.add_player("Comp1", "Computer") with self.assertRaises(ValueError): self.game._l_players[0]._l_card = [] self.game.print_player(self.game._l_players[0]) o_in = cd.Card() o_in.set_card() self.game._l_players[0].add_card(o_in) self.game.print_player(self.game._l_players[0]) self.assertEqual(l_print_output[0], "------ Карточки игрока Comp1 ------") self.assertEqual(l_print_output[1], "------------------------------------") self.assertEqual(l_print_output[2], " 4 23 30 31 72 ") self.assertEqual(l_print_output[3], " 24 47 66 72 87 ") self.assertEqual(l_print_output[4], " 21 46 47 58 76 ") self.assertEqual(l_print_output[5], "------------------------------------")
def getDesk(self): i = 0 cards = [] for lt in self.leftTop: i += 1 box = (lt[0], lt[1], lt[0] + self.width, lt[1] + self.height) region = self.im.crop(box) region_rank = region.crop(self.box_rank) card_rank = ic.compareRank(img2gray(region_rank)) region_suit = region.crop(self.box_suit) card_suit = ic.compareSuit(img2gray(region_suit)) #print card_rank,'_',card_suit if card_suit != "unknown" and card_rank != "unknown": cards.append(card.Card(card_suit, card_rank)) #cards.append(card_suit+"_"+str(card_rank)) else: return cards return cards
def card_input(c): if len(c) == 2 or len(c) == 3 and c[-1] in card.SUIT_INDICES: suit = card.SUIT_INDICES.find(c[-1]) if c[:-1] == "j": c = 11 elif c[:-1] == "q": c = 12 elif c[:-1] == "k": c = 13 elif c[:-1] == "a": c = 14 else: try: c = int(c[:-1]) except ValueError: c = -1 if 0 <= suit and suit < len( card.SUIT_INDICES ) and card.MIN_CARD <= c and c <= card.MAX_CARD: return card.Card(suit, c)
def start_game(path='words.txt'): import card # Preparing cards = [] line = '' with open(path, mode='r') as f: for line in f: words = line.split('_') cards.append(card.Card(words[0], words[1])) from random import random points = 0 chances = 3 length = len(cards) while True: # Starting word = cards[int(random() * length)] while True: print(word.get_word1()) inp = input('Is: ') if word.equals(inp + '\n') == True: #if (inp+'\n') == word.get_word2(): points += 1 chances = 3 if (points % 100) == 0: print('!!!Fine, you\'ve earned ' + str(points) + ' points!!!') elif (points % 10) == 0: print('!!!Fine, you\'ve earned ' + str(points) + '!!!') else: print('+1 points All: ' + str(points)) break elif inp is 'X': sys.exit() else: if chances > 0: points -= 1 chances -= 1 print('You are lose 1 point.') else: points -= 1 chances = 3 print('True variant: ' + word.get_word2()) break
def test_rate_card(self): t = time.time() c = card.Card('d', 'r') c.rate_card(0) self.assertAlmostEqual(c.easiness_factor, 2.5 - 0.8) self.assertAlmostEqual(c.iteration_length, 0) self.assertAlmostEqual(t, c.unix_time_to_review, 3) self.assertEqual(c.iteration_number, 0) self.assertTrue(c.is_reviewable()) t = time.time() c.rate_card(2) self.assertAlmostEqual(c.easiness_factor, 2.5 - 0.8) self.assertAlmostEqual(c.iteration_length, card.ONE_DAY) self.assertAlmostEqual(c.unix_time_to_review, t + card.ONE_DAY, 3) self.assertEqual(c.iteration_number, 1) self.assertFalse(c.is_reviewable()) t = time.time() c.rate_card(3) self.assertAlmostEqual(c.easiness_factor, 2.5 - 0.8 + 0.1) self.assertAlmostEqual(c.iteration_length, 6 * card.ONE_DAY) self.assertAlmostEqual(c.unix_time_to_review, t + 6 * card.ONE_DAY, 3) self.assertFalse(c.is_reviewable()) t = time.time() c.rate_card(2) self.assertAlmostEqual(c.easiness_factor, 2.5 - 0.8 + 0.1) self.assertAlmostEqual(c.iteration_length, 6 * card.ONE_DAY * (2.5 - 0.8 + 0.1)) self.assertAlmostEqual(c.unix_time_to_review, t + 6 * card.ONE_DAY * (2.5 - 0.8 + 0.1), 3) self.assertFalse(c.is_reviewable()) t = time.time() c.rate_card(1) self.assertAlmostEqual(c.easiness_factor, 2.5 - 0.8 + 0.1 - 0.3) self.assertAlmostEqual(c.iteration_length, 0) self.assertAlmostEqual(c.unix_time_to_review, t, 3) self.assertTrue(c.is_reviewable())