Exemplo n.º 1
0
class Dealer:

    def __init__(self):
        self.hello = ""
        self.hand = Hand()

    def show_first_card(self):
        print("")
        print("Dealers' first card:")
        print(self.hand.cards[0])
        print("")

    def draw_remaining_cards(self, deck):
        while self.hand.score < 17:
            self.hand.draw_card(deck)

    def deal_card(self, player, deck):
        player.hand.draw_card(deck)

    def show_hand(self):
        print("")
        print('DEALER has cards:')
        for card in self.hand.cards:
            print(card)
        print("")

    def is_bust(self):
        return self.hand.is_bust()
Exemplo n.º 2
0
def getBest5CardsAsHand(hand):
    '''
    Get best hand from hand of 7 card objects return hand object
    '''
    bestCards = getBest5CardHand(hand)
    bestHand = Hand()
    bestHand.setHandFromEvalList(bestCards)
    return bestHand
Exemplo n.º 3
0
def buildHand(howMany):
    deck = Deck()
    deck.shuffle()
    hand = Hand()
    for _ in range (0, howMany):
        hand.cards.append(deck.deal())
    return hand
Exemplo n.º 4
0
    def test_best_of_seven_straight(self):
        #         pass
        hand = Hand()
        card = Card('14', 'H')
        hand.cards.append(card)
        card = Card('13', 'H')
        hand.cards.append(card)
        card = Card('12', 'H')
        hand.cards.append(card)
        card = Card('11', 'S')
        hand.cards.append(card)
        card = Card('10', 'H')
        hand.cards.append(card)
        card = Card('5', 'S')
        hand.cards.append(card)
        card = Card('2', 'D')
        hand.cards.append(card)

        wins = evaluation.processor.getBest5CardHand(hand)
        self.assertEqual(len(wins), 5)
        self.assertTrue('14H' in wins)
        self.assertTrue('13H' in wins)
        self.assertTrue('12H' in wins)
        self.assertTrue('10H' in wins)
        self.assertTrue('11S' in wins)
Exemplo n.º 5
0
 def shape(self):
     ''' Minimizes Hand.strain to return the easiest shape of this chord'''
     from player import Hand  # Circular dependency
     best = None
     for shape in self.shapes:
         h = Hand(shape)
         try:
             if h.strain < best.strain:
                 best = h
         except AttributeError:
             best = h
     return best.shape
Exemplo n.º 6
0
    def test_best_of_seven_two_of_a_kind(self):
        #         pass
        #Four of Diamonds, Ace of Spades, Six of Clubs, Two of Spades, Ace of Diamonds, Six of Diamonds, King of Diamonds
        # This test failed with the initial evaluator
        hand = Hand()
        card = Card('4', 'D')
        hand.cards.append(card)
        card = Card('14', 'S')
        hand.cards.append(card)
        card = Card('6', 'C')
        hand.cards.append(card)
        card = Card('2', 'S')
        hand.cards.append(card)
        card = Card('14', 'D')
        hand.cards.append(card)
        card = Card('6', 'D')
        hand.cards.append(card)
        card = Card('13', 'D')
        hand.cards.append(card)

        print(hand.toEvalList())
        lst = evaluation.processor.get5CardCombosFrom7CardsForEval(hand)
        print("there were " + str(len(lst)) + " variations found")
        lst.sort()
        print(lst)

        for cardList in lst:
            self.assertEqual(len(cardList), 5)

        print(lst)
        print(lst)
        wins = evaluation.processor.getBest5CardHand(hand)
        self.assertEqual(len(wins), 5)
        self.assertTrue('14S' in wins)
        self.assertTrue('14D' in wins)
        self.assertTrue('6C' in wins)
        self.assertTrue('6D' in wins)
        self.assertTrue('13D' in wins)
Exemplo n.º 7
0
    def test_getPlayer(self):
        playerRandomName = "Test Player " + random_string(5)
        player = datalayer.getOrCreateSavedPlayer('notAPlayerId',
                                                  playerRandomName)
        print(player)

        playerII = datalayer.getOrCreateSavedPlayer(player.playerId)
        print(playerII)

        self.assertEqual(player.playerId, playerII.playerId)
        self.assertEqual(player.name, playerII.name)
        self.assertEqual(player.chips, playerII.chips)
        self.assertEqual(player.currentBet, playerII.currentBet)
        self.assertEqual(player.folded, playerII.folded)
        self.assertEqual(player.currentAction, playerII.currentAction)

        playerII.chips = 1000
        playerII.name = "Some Test This is"
        playerII.folded = True
        hand = Hand()
        deck = Deck()
        deck.shuffle()
        hand.cards.append(deck.deal())
        hand.cards.append(deck.deal())
        playerII.hand = hand
        playerII.currentBet = 5

        datalayer.updatePlayer(playerII)
        playerIII = datalayer.getOrCreateSavedPlayer(player.playerId)

        self.assertEqual(playerII.playerId, playerIII.playerId)
        self.assertEqual(playerII.name, playerIII.name)
        self.assertEqual(playerII.chips, playerIII.chips)
        self.assertEqual(playerII.currentBet, playerIII.currentBet)
        self.assertEqual(playerII.folded, playerIII.folded)
        self.assertEqual(playerII.currentAction, playerIII.currentAction)
        self.assertEqual(playerII.hand.cards[0], playerIII.hand.cards[0])

        datalayer.deletePlayer(player)
Exemplo n.º 8
0
 def test_best_of_seven_3_of_a_kind(self):
     #         pass
     hand = Hand()
     card = Card('4', 'D')
     hand.cards.append(card)
     card = Card('A', 'C')
     hand.cards.append(card)
     card = Card('A', 'D')
     hand.cards.append(card)
     card = Card('J', 'S')
     hand.cards.append(card)
     card = Card('10', 'H')
     hand.cards.append(card)
     card = Card('A', 'S')
     hand.cards.append(card)
     card = Card('5', 'D')
     hand.cards.append(card)
     wins = evaluation.processor.getBest5CardHand(hand)
     self.assertTrue('AC' in wins)
     self.assertTrue('AD' in wins)
     self.assertTrue('AS' in wins)
     self.assertTrue('JS' in wins)
     self.assertTrue('10H' in wins)
def player_win():
    print("You win!!!")
    playerchip.win_bet()


def player_lose():
    print("You lose!!!")
    playerchip.lose_bet()


playerchip = Chips()

while playagain:
    deck = Deck()
    deck.suffer()
    playerhand = Hand()
    dealerhand = Hand()
    playerchip.take_bet()

    hit(playerhand, deck)
    hit(playerhand, deck)

    hit(dealerhand, deck)
    hit(dealerhand, deck)

    display(playerhand, dealerhand, playerchip, False)

    #while playing:
    print("Your turn")
    playing = True
    while (not bust(playerhand) and playing):
Exemplo n.º 10
0
 def __init__(self):
     self.hello = ""
     self.hand = Hand()