def make_deck(self):
     cards = []
     for suit_name in self.suits:
         suit = Suit(suit_name)
         suit_cards = suit.make_cards_for_suit()
         cards += suit_cards
     return cards
示例#2
0
 def initialize_deck(self):
     cards = []
     for value in range(1, 14):
         cards.extend(BlackJackCard(value, Suit(st))
                      for st in Suit.get_all_suit_types())
     deck = Deck()
     deck.set_cards(cards)
     deck.reset()
     self._deck = deck
示例#3
0
def generateDispensableCard(seed=None):
    if seed is not None:
        random.seed(seed)
    card = Card()
    card.setSuit(Suit(random.randint(1, 5)))
    card.setValue(random.randint(1, 4))  # 5s are indispensable
    graveyard = [random.randint(0, 3) if i % 5 == 0 else (random.randint(0, 1) if i % 5 == 4 else random.randint(0, 2)) for i in range(25)]
    #            0-3 discarded if a 1                          0-1 discarded if a 5                 else 0-2 discarded
    graveyard[int(card) - 1] = 0 if card.getValue() > 1 else random.randint(0, 1)

    graveyard.append(Suit.toInt(card.getSuit()))
    graveyard.append(card.getValue())
    return graveyard
示例#4
0
def generateGoodCombo(seed=None):
    """ Generates two cards which can be played on top of each other in the hanabi game
    """
    random.seed(seed)
    fireWork = Card()
    card = Card()
    while not (fireWork.getSuit() == card.getSuit()
               and fireWork.getValue() == card.getValue() - 1):
        fireWork.setSuit(Suit(random.randint(1, 5)))
        fireWork.setValue(random.randint(1, 5))
        card.setSuit(Suit(random.randint(1, 5)))
        card.setValue(random.randint(1, 5))
    return (Suit.toInt(fireWork.getSuit()), fireWork.getValue(),
            Suit.toInt(card.getSuit()), card.getValue())
示例#5
0
def generateUnplayableCard(seed=None):
    random.seed(seed)
    fireWorks = []
    for i in range(5):
        fireWorks.append(
            random.randint(0, 5)
        )  # creating random firework values (intentionally normally distributed)
    card = Card()
    card.setSuit(Suit(random.randint(1, 5)))
    forbiddenValue = fireWorks[Suit.toInt(card.getSuit()) - 1] + 1
    card.setValue(random.randint(1, 5))
    while card.getValue() == forbiddenValue:
        card.setValue(random.randint(1, 5))
    fireWorks.append(Suit.toInt(card.getSuit()))
    fireWorks.append(card.getValue())
    return fireWorks
示例#6
0
def generatePlayableCard(seed=None):
    random.seed(seed)
    fireWorks = []
    for i in range(5):
        fireWorks.append(
            random.randint(0, 5)
        )  # creating random firework values (intentionally normally distributed)
    card = Card()
    card.setSuit(Suit(random.randint(1, 5)))
    card.setValue(fireWorks[Suit.toInt(card.getSuit()) - 1] + 1)
    if card.getValue() == 6:
        fireWorks[Suit.toInt(card.getSuit()) - 1] = random.randint(1, 4)
        card.setValue(fireWorks[Suit.toInt(card.getSuit()) - 1] + 1)
    fireWorks.append(Suit.toInt(card.getSuit()))
    fireWorks.append(card.getValue())
    return fireWorks
示例#7
0
def generateIndispensableCard(seed=None):
    if seed is not None:
        random.seed(seed)
    card = Card()
    card.setSuit(Suit(random.randint(1, 5)))
    card.setValue(random.randint(1, 5))
    graveyard = [random.randint(0, 3) if i % 5 == 0 else (random.randint(0, 1) if i % 5 == 4 else random.randint(0, 2)) for i in range(25)]
    #            0-3 discarded if a 1                          0-1 discarded if a 5                 else 0-2 discarded

    graveyard[(Suit.toInt(card.getSuit()) - 1) * 5] = random.randint(0, 2)
    for i in range((Suit.toInt(card.getSuit()) - 1) * 5 + 1, int(card) - 1):
        graveyard[i] = random.randint(0, 1)
    graveyard[int(card) - 1] = 0 if card.getValue() == 5 else 2 if card.getValue() == 1 else 1
    #                            5 can't be discarded            must be the last 1         must be the last of its kind
    graveyard.append(Suit.toInt(card.getSuit()))
    graveyard.append(card.getValue())
    return graveyard
示例#8
0
 def appStarted(app):
     app.splashScreen = SplashScreen()
     app.suit = Suit()
     app.informationScreen = InformationScreen()
     app.draft = DraftMode()
     app.teamPage = TeamPage()
     app.simulateGame = SimulateGame()
     app.gameOverScreen = GameOverScreen()
     app.setActiveMode(app.splashScreen)
示例#9
0
def generateIndispensableCard(seed=None):
    if seed is not None:
        random.seed(seed)
    card = Card()
    card.setSuit(Suit(random.randint(1, 5)))
    card.setValue(random.randint(1, 5))
    graveyard = [random.randint(0, 1) for i in range(25)
                 ]  # 0 if some corresponding cards are left else 1

    for i in range(
        (Suit.toInt(card.getSuit()) - 1) * 5,
            int(card) - 1
    ):  # none of the cards with same suit and lower value as the current card should have all of their identical cards discarded
        graveyard[i] = 0
    graveyard[
        int(card) -
        1] = 1  # This one means that all the cards identical to the current card have been discarded but not the current card, which is necessary but not in keeping with the other slots
    graveyard += card.toBinary()
    return graveyard
示例#10
0
文件: deal.py 项目: abortz/saycbridge
 def old_identifier(self):
     # We're constructing a 52 digit number in base 4,
     # converted to base-10, its our identifier.
     identifier = 0
     for position, hand in enumerate(self.hands):
         for suit_index, cards in enumerate(hand.cards_by_suit_index):
             for card in cards:
                 suit = Suit.from_index(suit_index)
                 card_identifier = Card.identifier_for_card(suit, card)
                 identifier += position * pow(4, card_identifier)
     return str(identifier)
示例#11
0
def generateDispensableCard(seed=None):
    if seed is not None:
        random.seed(seed)
    card = Card()
    card.setSuit(Suit(random.randint(1, 5)))
    card.setValue(random.randint(1, 4))  # 5s are indispensable
    graveyard = [random.randint(0, 1) for i in range(25)
                 ]  # 0 if some corresponding cards are left else 1
    graveyard[int(card) - 1] = 0
    graveyard += card.toBinary()
    return graveyard
示例#12
0
def train(self, player, table):
    for card in player.hand:
        inputs = []
        for suit, value in table.field.items():
            inputs.append(value)
        inputs.append(Suit.toInt(card.getSuit()))
        inputs.append(card.getValue())
        self.compute(inputs)
        expectedValue = 0
        if table.cardPlayable(card):
            expectedValue = 1
        self.backprop([expectedValue])
示例#13
0
def testOnGame(self, player, table):
    for card in player.hand:
        inputs = []
        for suit, value in table.field.items():
            inputs.append(value)
        inputs.append(Suit.toInt(card.getSuit()))
        inputs.append(card.getValue())
        self.compute(inputs)
        expectedValue = 0
        if table.cardPlayable(card):
            expectedValue = 1
        output = self.getOutput()[0]
        if output > 0.5:
            output = 1
        else:
            output = 0
        self.learnError.append(abs(expectedValue - output))
示例#14
0
文件: deal.py 项目: abortz/saycbridge
    def identifier(self):
        position_for_card = [None for _ in range(52)]
        for position_index, hand in enumerate(self.hands):
            for suit_index, cards in enumerate(hand.cards_by_suit_index):
                for card in cards:
                    suit = Suit.from_index(suit_index)
                    card_identifier = Card.identifier_for_card(suit, card)
                    position_for_card[card_identifier] = position_index

        # position_for_card represents a 52-digit number in base 4
        # We're going to split it into 4-digit hunks and convert to base 16.
        identifier = ""
        hex_chars = '0123456789abcdef'
        for offset in range(26):
            # A single hex digit encodes 4 bits where as our previous encoding was 2.
            hex_index = position_for_card[offset * 2 + 0] * 4 + position_for_card[offset * 2 + 1]
            identifier += hex_chars[hex_index]
        return identifier
示例#15
0
def generateGoodSample():
    inputs = []
    inputs.append(Suit.randomColor())
    inputs.append("")
    inputs.append("cardcol")
    inputs.append("cardvalue")
    inputs[0] = Suit.randomColor()
    inputs[1] = random.randint(1, 5)
    c = Card(suit=Suit.randomColor(), value=random.randint(1, 5))
    inputs[2] = Suit.toInt(c.getSuit())
    inputs[3] = c.getValue()
    while not ((inputs[0] == c.getSuit()) and
               (inputs[1] == (c.getValue() - 1))):
        inputs[0] = Suit.randomColor()
        inputs[1] = random.randint(1, 5)
        c = Card(suit=Suit.randomColor(), value=random.randint(1, 5))
        inputs[2] = Suit.toInt(c.getSuit())
        inputs[3] = c.getValue()
    # print("good: ", inputs, "card: ", c.getSuit(), c .getValue())
    return [Suit.toInt(inputs[0]), inputs[1], inputs[2], inputs[3]]
示例#16
0
def create_card(cardstring):
    rank = Rank(cardstring[0])
    suit = Suit(cardstring[1])
    card = Card(rank, suit)
    return card
示例#17
0
文件: card.py 项目: ygkn/ros2-porker
 def __init__(self, suit_number, rank_number):
     self.suit = Suit(suit_number)
     self.rank = Rank(rank_number)
示例#18
0
def suit():
    '''Creates new instance of suit class.'''
    return Suit()
示例#19
0
 def make_deck(self):
     for rank in self.card_ranks:
         for suit in self.card_suits:
             yield Card(Rank(rank), Suit(suit))