def testFourOfKindBoard(self): h = Hand.Hand() d = 0 c = Card.Card(51); h.accept(c) c = Card.Card(17); h.accept(c) c = Card.Card(13*1+d); h.accept(c) c = Card.Card(13*3+d); h.accept(c) c = Card.Card(13*0+d); h.accept(c) c = Card.Card(22); h.accept(c) c = Card.Card(13*2+d); h.accept(c) rank, hv = h.evaluate() face, count = hv[0] self.assertEqual(rank, h.VAL_FOUR_OF_A_KIND)
def create_deck(file_data): ''' Creates a deck by creating cards with clues and answers from supplied file data. ''' deck = [] for line in file_data: line = line.decode().strip() clue, answers = line.split(';') clue = clue.strip() answers = answers.strip().upper().split(',') answers = [answer.strip() for answer in answers] card = Card.Card(clue, answers) deck.append(card) return deck
def single_graph(length, population, pm, pi): sim = ea.Card(population, pm, pi) #these are each their own list for ease of graphing later minlist = [] q2list = [] medlist = [] q3list = [] maxlist = [] for step in range(length): sim.step() #create sorted list of fitness after each step fitlist = [] for individual in range(population): fitlist.append(sim.fitness(individual)) fitlist.sort() #I know this looks gory, sorry minlist.append(fitlist[0]) q2list.append(fitlist[int(0.25 * population)]) medlist.append(fitlist[int(0.50 * population)]) q3list.append(fitlist[int(0.75 * population)]) maxlist.append(fitlist[-1]) #plot everything plt.plot(minlist, color='#d2691e') plt.plot(q2list, '#b35919') plt.plot(medlist, '#864313') plt.plot(q3list, '#592d0d') plt.plot(maxlist, '#2d1606') plt.xlabel('Tournaments') plt.ylabel('Fitness') plt.ylim(0, 1) plt.title('Tournaments vs. Fitness') plt.show() #write output sim.output() return
def sort_hand(hand): h = [] i = 0 while i < len(hand): c = {'J': 11, 'Q': 12, 'K': 13, 'A': 14}.get(hand[i][1], 0) if c < 11: c = int(hand[i][1]) if c == 1: c = 10 h.append(Card.Card(hand[i][0], c)) i += 1 h = sorted(h, key=Card.Card.get_value, reverse=True) return h
def __init__(self) -> None: # Initialize cards self.__cards = [] for house in range(0, 4): for num in range(2, 15): houseName = "" if house == 0: houseName = "Hearts" elif house == 1: houseName = "Diamonds" elif house == 2: houseName = "Clubs" elif house == 3: houseName = "Spades" card = Card(houseName, num) self.__cards.append(card) self.shuffleDeck()
def testRoyalFlushFlop(self): h = Hand.Hand() c = Card.Card(13); h.accept(c) c = Card.Card(22); h.accept(c) c = Card.Card(23); h.accept(c) c = Card.Card(24); h.accept(c) c = Card.Card(25); h.accept(c) c = Card.Card(6); h.accept(c) c = Card.Card(7); h.accept(c) rank, hv = h.evaluate() self.assertEqual(len(hv), 4) suit, count = hv[0] self.assertEqual(suit, c.DIAMONDS) self.assertEqual(count, 5) self.assertEqual(rank, h.VAL_ROYAL_FLUSH)
def testFullHouseFlop(self): h = Hand.Hand() d = 0 e = 1 c = Card.Card(13*1+d); h.accept(c) c = Card.Card(13*3+d); h.accept(c) c = Card.Card(13*0+d); h.accept(c) c = Card.Card(13*1+e); h.accept(c) c = Card.Card(22); h.accept(c) c = Card.Card(13*2+e); h.accept(c) c = Card.Card(17); h.accept(c) rank, hv = h.evaluate() face, count = hv[0] self.assertEqual(rank, h.VAL_FULL_HOUSE)
def stringToHand(self, string): # trim whitespace string = string.strip() hand = [] # go through every third index for i in range(0, len(string), 3): # build card from string face = string[i] if (face == "X"): face = 10 if (face == "J"): face = 11 if (face == "Q"): face = 12 if (face == "K"): face = 13 suit = string[i + 1] hand.append(Card.Card(int(face), suit, False)) return hand
def init(): #delete cards = Card.getCards(session) for card in cards: Card.deleteCard(session, card.cardId) players = Player.getPlayers(session) for player in players: Player.deletePlayer(session, player.playerId) #add deck = Player.addPlayer(session, Player.Player(name="Deck", type=0)) mat = Player.addPlayer(session, Player.Player(name="Mat", type=1)) player1 = Player.addPlayer(session, Player.Player(name="Player1", type=2)) player2 = Player.addPlayer(session, Player.Player(name="Player2", type=3)) player3 = Player.addPlayer(session, Player.Player(name="Player3", type=4)) player4 = Player.addPlayer(session, Player.Player(name="Player4", type=5)) for i in range(2, 15): for j in range(0, 4): Card.addCard(session, Card.Card(type=j, number=i, playerId=deck.playerId))
def __init__(self): self.cardDict = [] self.chosenCards = [] self.deskCards = [] self.cardPool = [] self.deskCapacity = consts.DESK_CARDS_CAPACITY self.colorList = consts.COLOR_LIST self.fillList = consts.FILL_LIST self.shapeList = consts.SHAPE_LIST self.numList = consts.NUM_LIST index = 1 for color in self.colorList: for fill in self.fillList: for shape in self.shapeList: for number in self.numList: cardUrl = consts.IMAGE_PATH+color+" "+fill+" "+shape+str(index)+consts.IMAGE_FORMAT card = Card(index-1,color, fill, shape, number,cardUrl) self.cardDict.append(card) self.cardPool.append(card) index = index+1
def __init__(self, initial: list = None, _seed: int = None): colors: tuple = (0, 1, 2, 3, 4) numbers: tuple = (1, 1, 1, 2, 2, 3, 3, 4, 4, 5) starter: list = [Card(cardId=id) for id in range(50)] random.seed(_seed) if initial: self._cards = copy.deepcopy(initial) self._drew = [] # build removed cards list for cardInitial in initial: for cardStarter in starter: if cardInitial.toShort() == cardStarter.toShort(): self._drew.append(cardInitial) # self.remove(cardInitial) else: self._cards = starter self._drew = []
def move_freecell_to_foundation(self, n): ''' Move the card at index 'n' of the freecells to the foundation. If there is no card there, or if the card can't go to the foundation, raise an IllegalMove exception. ''' if type(n) != int or n > 3 or n < 0: raise IllegalMove('IllegalMove: Freecell number \ must be between 0 and 3') elif self.freecell[n] == None: raise IllegalMove('IllegalMove: No card in specified freecell') elif self.freecell[n].rank == 'A': self.foundation[self.freecell[n].suit] = 'A' self.freecell[n] = None elif self.freecell[n].suit not in self.foundation: raise IllegalMove('IllegalMove: Card cannot be placed in the foundation') elif self.freecell[n].goes_above(Card(self.foundation[self.freecell[n].suit], self.freecell[n].suit)): self.foundation[self.freecell[n].suit] = self.freecell[n].rank self.freecell[n] = None else: raise IllegalMove('IllegalMove: This card cannot be placed in the foundation')
def has_straight(self): self.cards.sort(key=lambda x: x.rank) count = 0 previous = Card(suit=self.cards[0].suit, rank=self.cards[0].rank - 1) for card in self.cards: if count == 5: return True if count == 4: if card.rank == previous.rank + 1 or card.rank == previous.rank - 12: return True else: count = 1 previous = card if count < 4: if card.rank == previous.rank + 1: count += 1 previous = card else: count = 1 previous = card return False
def testRoyalFlushRiver(self): h = Hand.Hand() d = 2 c = Card.Card(13*d+11); h.accept(c) c = Card.Card(13*d+0); h.accept(c) c = Card.Card(6); h.accept(c) c = Card.Card(13*d+12); h.accept(c) c = Card.Card(7); h.accept(c) c = Card.Card(13*d+10); h.accept(c) c = Card.Card(13*d+9); h.accept(c) rank, hv = h.evaluate() self.assertEqual(len(hv), 4) suit, count = hv[0] self.assertEqual(suit, d) self.assertEqual(count, 5) self.assertEqual(rank, h.VAL_ROYAL_FLUSH)
def move_cascade_to_foundation(self, n): ''' Move the bottom card of cascade 'n' to the foundation. If there is no card, or if the bottom card can't go to the foundation, raise an IllegalMove exception. ''' if type(n) != int or n > 7 or n < 0: raise IllegalMove('IllegalMove: Bad cascade number') elif len(self.cascade[n]) == 0: raise IllegalMove('IllegalMove: No card in specified cascade') elif self.cascade[n][-1].rank == 'A': self.foundation[self.cascade[n][-1].suit] = 'A' self.cascade[n].pop() elif self.cascade[n][-1].suit not in self.foundation: raise IllegalMove('IllegalMove: This card cannot be placed in the foundation') elif self.cascade[n][-1].goes_above(Card(self.foundation[self.freecell[n].suit], self.freecell[n].suit)): self.foundation[self.cascade[n][-1].suit] = self.cascade[n][-1].rank self.cascade[n].pop() else: raise IllegalMove('IllegalMove: This card cannot be placed in the foundation')
def compare_cards(population): c_mi = [] c_im = [] for pm_index in range(0, 101): pm = pm_index * 0.01 #edit this to ea.Cardmp if you want to switch the order of mutation and recombination emilie = ea.Card(population, pm, 0.5) for step in range(0, (population * 5)): emilie.step() fitlist = [] for individual in range(population): fitlist.append(emilie.fitness(individual)) fitlist.sort() c_im.append(fitlist[int(population / 2)]) brian = ea_mi.Card(population, pm, 0.5) for step in range(0, (population * 5)): brian.step() fitlist = [] for individual in range(population): fitlist.append(emilie.fitness(individual)) fitlist.sort() c_mi.append(fitlist[int(population / 2)]) plt.plot(c_mi) #plt.plot(c_im) plt.xlabel('Probability of Mutation') plt.ylabel('Median Fitness') plt.title('Population = %s, 5 generations' % population) plt.show()
def move_cascade_to_foundation(self, n): ''' Move the bottom card of cascade 'n' to the foundation. If there is no card, or if the bottom card can't go to the foundation, raise an IllegalMove exception. ''' # illegal move errors if n not in range(8) or type(n) != int: raise IllegalMove('argument must be an integer from 0 to 7') if self.cascade[n] == []: raise IllegalMove('attempted to remove card from an empty cascade') # card being moved from the cascade lowest_cascade_card = self.cascade[n][-1] suit = lowest_cascade_card.suit.upper() rank = lowest_cascade_card.rank if suit not in self.foundation: if rank == 'A': self.cascade[n].remove(lowest_cascade_card) self.foundation[suit] = rank else: raise IllegalMove('invalid move; the foundation bottom card' 'must be ace') else: foundation_top_card = Card(self.foundation[suit], suit) if lowest_cascade_card.goes_above(foundation_top_card) == True: self.cascade[n].remove(lowest_cascade_card) self.foundation[suit] = rank return else: raise IllegalMove( 'invalid move; the card moving from the ' 'cascade must be one higher in rank than the ' 'card at the top of the foundation and of ' 'same suit')
def makeAskForCardPrompt(self, askedPlayerName, buttons, label, text =""): """Prints out a prompt for the user to ask for a card. Args: askedPlayerName: The name of the player the user wants to ask for a card. buttons: buttons to be removed label: labels to be forgotten text: Optional text parameter to be deleted in button click. Raises: None. """ for player in self.game.player_list: if askedPlayerName == player.name: self.game.asked_player = player print(askedPlayerName + " " + player.name) label.place_forget() self.remove_buttons(buttons) self.delete(text) print("Player asked: ", self.game.asked_player.name) display_askOtherPlayerCard = self.create_text(575, 600, font = ("Purisa", 18), fill = "black", text= "Which card would you like to ask for?") button_indent = 0.04 existing_values = [] for card in self.game.current_player.player_hand.hand_cards: if card.card_value not in existing_values: existing_values.append(card.card_value) button_ref = [] for value in existing_values: button_indent += 0.040 askCardValue_button = tk.Button(self, text = value, font = ("Purisa", 12), bg="light cyan") #lambda:[self.game.checkRequest(self.game.current_player, askedPlayer, crd), self.remove_buttons(button_refs)] buttonValue = askCardValue_button['text'] crd = Card_library.Card(buttonValue, '♡') button_ref.append(askCardValue_button) askCardValue_button['command'] = partial(self.processCheckRequest, crd, askCardValue_button, button_ref, display_askOtherPlayerCard) askCardValue_button.place(relx = (0.25 + button_indent), rely = 0.8)
def dealCard(self): ''' This method will return a random card from the deck. This card will be removed from the deck and can not be drawn again. If the deck is empty it will shuffle up a new deck and draw from that ''' #check to see if the deck is empty if (len(self.deck) <= 0): #if empty create a new deck self.deck = [] for x in range(len(Card.suits)): for y in range(len(Card.ranks)): temp = Card.Card(y, x) self.deck.append(temp) rand = random.randint(0, len(self.deck) - 1) # this will get the random card card = self.deck[rand] #this will remove the card del self.deck[rand] #this will return the random card return card
def testStraightFlushSpades(self): h = Hand.Hand() d = 3 c = Card.Card(13*d+2); h.accept(c) c = Card.Card(15); h.accept(c) c = Card.Card(13*d+1); h.accept(c) c = Card.Card(13*d+4); h.accept(c) c = Card.Card(22); h.accept(c) c = Card.Card(13*d+0); h.accept(c) c = Card.Card(13*d+3); h.accept(c) rank, hv = h.evaluate() self.assertEqual(len(hv), 4) suit, count = hv[0] self.assertEqual(suit, d) self.assertEqual(count, 5) self.assertEqual(rank, h.VAL_STRAIGHT_FLUSH)
def move_freecell_to_foundation(self, n): ''' Move the card at index 'n' of the freecells to the foundation. If there is no card there, or if the card can't go to the foundation, raise an IllegalMove exception. ''' # illegal move errors if n not in range(4) or type(n) != int: raise IllegalMove('argument must be an integer from 0 to 4') if self.freecell[n] == None: raise IllegalMove('attempted to remove from freecell with no card') # card being moved from the cascade freecell_card = self.freecell[n] suit = freecell_card.suit.upper() rank = freecell_card.rank if suit not in self.foundation: if rank == 'A': self.freecell[n] = None self.foundation[suit] = rank else: raise IllegalMove('invalid move; the foundation bottom card' 'must be ace') else: foundation_top_card = Card(self.foundation[suit], suit) if freecell_card.goes_above(foundation_top_card) == True: self.freecell[n] = None self.foundation[suit] = rank return else: raise IllegalMove('invalid move; the card moving from the ' 'freecell must be one higher in rank than ' 'the card at the top of the foundation and ' 'of same suit')
def perform_player_recycling_move(board): move = input('Play your move: \n') moveInfo = move.split(' ') if len(moveInfo) is not 7: print('Invalid Input. Please enter valid input of recycling move') return perform_player_recycling_move(board) first_cell = board.get_cell_info(get_row_coordinate(moveInfo[1]), get_col_coordinate(moveInfo[0])) second_cell = board.get_cell_info(get_row_coordinate(moveInfo[3]), get_col_coordinate(moveInfo[2])) cells = [first_cell, second_cell] if is_valid_pick_card_input(cells) is False: print('Invalid Input Card. Please input a valid card to be moved') return perform_player_recycling_move(board) final_card = Card(ROTATIONS[int(moveInfo[4]) - 1], get_col_coordinate(moveInfo[5]), get_row_coordinate(moveInfo[6])) move_success = board.move_card(ROTATIONS[get_orientation(cells) - 1], first_cell, second_cell, final_card) if move_success is False: return perform_player_recycling_move(board) return True
def generate_states_from_position(parent_state_node, position_moves, recycler_parent_node=None, pick_card=None): current_state = parent_state_node.get_data( ) if recycler_parent_node is None else recycler_parent_node.get_data() move_state_nodes = [] for move in position_moves: x1 = move[0][0] y1 = move[0][1] x2 = move[1][0] for i in range(4): card = Card(ROTATIONS[(2 * i) if x1 == x2 else (2 * i + 1)], y1, x1) if pick_card is None or (pick_card is not None and is_valid_place_card_move( pick_card, card)): state = State(current_state, card, pick_card) state_node = StateNode(state) state_node.parent = parent_state_node if recycler_parent_node is None else recycler_parent_node move_state_nodes.append(state_node) return move_state_nodes
def mCard(self, n): newCard = Card(self.cardDeck[self.deckN]) self.deckN += 1 self.main.addCard(newCard) p = PhotoImage(file="GodoriCards/cardback.gif") self.LcardsMain.append(Label(self.window, bd=0, image=p)) self.LcardsMain[self.main.inHand() - 1].config( image=p) # 가지고있는 카드갯수 -1 인덱스는 0이 시작 self.LcardsMain[self.main.inHand() - 1].image = p self.LcardsMain[self.main.inHand() - 1].place(x=170 + n * 32, y=140) self.LcardsMPoint.append(newCard.getValue()) self.mPoint = list(map(int, self.LcardsMPoint)) self.LmPoint.append( Label(self.window, width=3, height=1, font=self.fontstyle2, bg="green", fg="white"))
def CreateCards(self): i = 1 n = 0 m = 0 numberSet = [] while i <= self.__m_cardCount: while n < self.__cardSize * self.__cardSize: try: numberSet.append(self.__numberSet.get(m)) except IndexError: m = 0 self.__numberSet.randomize() numberSet.append(self.__numberSet.get(m)) m += 1 n += 1 if self.__cardSize % 2 != 0: middle = ((self.__cardSize * self.__cardSize) // 2) numberSet[middle] = "FREE!" card = Card.Card(i, self.__cardSize, numberSet) self.__m_cards.append(card) n = 0 numberSet = [] i += 1
def read_input(self): player_health1, player_mana1, player_deck1, player_rune1, player_draw1 = [ int(j) for j in input().split() ] player_health2, player_mana2, player_deck2, player_rune2, player_draw2 = [ int(j) for j in input().split() ] opponent_hand, opponent_actions = [int(i) for i in input().split()] l_opponent_actions = [] for i in range(opponent_actions): card_number_and_action = input() l_opponent_actions.append(card_number_and_action) card_count = int(input()) l_cards = [] for i in range(card_count): card_number, instance_id, location, card_type, cost, attack, defense, abilities, my_health_change, opponent_health_change, card_draw, lane = input( ).split() one_card = cd.Card(int(card_number), int(instance_id), int(location), int(card_type), int(cost), int(attack), int(defense), abilities, (my_health_change), int(opponent_health_change), int(card_draw), int(lane)) l_cards.append(one_card) player1 = pl.Player(player_health1, player_mana1, player_deck1, player_rune1, player_draw1) player2 = pl.Player(player_health2, player_mana2, player_deck2, player_rune2, player_draw2) self.last_state = copy.copy(self.state) self.last_summon_strategy = self.summon_strategy self.last_attack_strategy = self.attack_strategy self.state = st.State(player1, player2, opponent_hand, l_opponent_actions, l_cards)
def covary_fixed_pi(pi, metapopulation, generations): fitness_array = np.zeros((11, 11)) for pop_index in range(0, 11): for pm_index in range(0, 11): pm = pm_index / 50 population = (pop_index + 1) * 5 emilie = [] fitlist = [] for trial in range(metapopulation): emilie.append(ea.Card(population, pm, pi)) for step in range(generations * population): emilie[trial].step() trial_fitlist = [] for individual in range(population): trial_fitlist.append(emilie[trial].fitness(individual)) trial_fitlist.sort() median = trial_fitlist[int(population / 2)] fitlist.append(median) fitness_array[pop_index][pm_index] = sum(fitlist) / len(fitlist) plt.imshow(fitness_array) plt.xlabel('Gene-wise Probability of Mutation') plt.ylabel('Population') plt.title( 'Probability of Recombination = %s, Generations = %s, Metapopulation = %s' % (pi, generations, metapopulation)) plt.show()
def __init__(self, a_deckNum, a_deck=None): """Deck class instantiation function. Deck class construction by member variable initialization according to the passed arguments. Args: a_deckNum: The number of decks to construct. a_deck: The list of cards in the deck to initialize as. Passes when loading a configuration file. Returns: NA Raises: NA """ # If config file is not passed, a new deck is created if a_deck is None: # Index of the "top card" self.__mTopCard = 0 # Initializing the final deck and its size self.__mDeck = [] self.__mDeckSize = int(a_deckNum) * self.DECKSIZE # Constructing a sorted deck for i in range(int(a_deckNum)): for j in range(self.DECKSIZE): self.__mDeck.append(Card.Card((j % 13) + 1, (j % 4) + 1)) random.shuffle(self.__mDeck) else: # Initialize top card, deck size and the deck: self.__mTopCard = 0 self.__mDeckSize = len(a_deck) self.__mDeck = a_deck
def on_click(): global counter global r_count #getCard card_input = card_img.get_final_value(stream_url) print(card_input) #card_input = int (card_input) #Algorithms - get running count and advantage percentage card = Card.Card(card_input) r_count = Algorithm.get_r_count(card, r_count) print(r_count) adv_percentage = Algorithm.get_adv_percentage(r_count) print(adv_percentage) #Update GUI based on refresh button ui.count_update(Dialog, r_count, counter) counter += 1 ui.percentage_update(Dialog, adv_percentage) ui.text_update(Dialog, adv_percentage)
def __init__(self,init_num): self.cardList = [] #element type: cards self.colorList = ['red','blue','green'] self.fillList = ['solid', 'shaded', 'clear'] self.shapeList = ['circle', 'triangle','square'] self.numList = ['1','2','3'] self.hint_num = 3 self.record = [] #passed formed set | element type: List of Card self.waitingList = [] #sets waiting for checking | element type: tuple value self.init_num = init_num self.score =0 #cards that are displayed for color in self.colorList: for fill in self.fillList: for shape in self.shapeList: for number in self.numList: #path yellow shaded triangle2 example image_path =resource_path(color+" "+fill+" "+shape+number+".gif") #image_path = "CardImages/"+color+" "+fill+" "+shape+number+".gif" self.cardList.append(Card(color, fill, shape, number,image_path)) self.display = [(count,elem) for count,elem in enumerate(self.cardList[0:init_num])] #tuple value self.hasSetInDisplay = False self.hasSetInCardList = False self.hint = []