예제 #1
0
import hand
import cv2
import gesture
import roi
#import Lights

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
hand = hand.Hand()
roi = roi.roi()
command = 0
fingerCount = 0
lastCount =0
crop=0

while True:
    t, image = cap.read()

    if t :

        try:

            cv2.setMouseCallback('Hands', roi.getroi)
            image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB)
            image = roi.drawSquare(image)
            crop = image

            if roi.isItCropped:

                image = roi.cropimage(image)
예제 #2
0
파일: player.py 프로젝트: ntout/blackjack
 def __init__(self, money=100):
     self.hand = hand.Hand()
     self.split = hand.Hand()
     self.wallet = money
예제 #3
0
def push(dealer, player):
    print("Its tie . ")


# now its time to  play the black jack game :)
if __name__ == '__main__':

    chips = amount_to_chips()
    while True:
        # Print an opening statement
        print('Welcome to BlackJack! Get as close to 21 as you can without going over!\n\
            Dealer hits until she reaches 17. Aces count as 1 or 11.')
        deck1 = deck.Deck()
        deck1.card_shuffle()
        # create player hand object
        player = hand.Hand()
        # create dealer hand object
        dealer = hand.Hand()
        # take bet from player
        take_bet(chips)
        # distribute equal cards and hide the dealer's second card
        for x in range(2):
            player.add_card(deck1.deal())
            player.adjust_for_ace()
            dealer.add_card(deck1.deal())
            dealer.adjust_for_ace()
        # display cards excluding dealer card
        display_some_cards(dealer, player)
        # ask for hit or stay
        playing = True
        while playing:
예제 #4
0
def learning_by_hands(intelligent=True, alternate=True):
    #Function initializations: setup players, deck, turncard, local variables, determine dealer
    p1 = players.Computer(difficulty="medium")
    p2 = players.Computer(difficulty="medium")
    d = deck.Deck()
    d.shuffle()
    crib = []
    turncard = d.deal_one()
    if alternate:
        is_dealer_p1 = True
    else:
        is_dealer_p1 = False

    #Allows learning Function to focus either on random configurations or heuristically influenced configurations
    if not intelligent:
        for i in range(4):
            p1.cards.append(d.deal_one())
            p2.cards.append(d.deal_one())
            crib.append(d.deal_one())
            p1_discards = crib[0:2]
            p2_discards = crib[2:4]
    else:
        p1_dealt_hand = []
        p2_dealt_hand = []
        for i in range(6):
            p1_dealt_hand.append(d.deal_one())
            p2_dealt_hand.append(d.deal_one())
        h1 = hand.Hand(p1_dealt_hand)
        h2 = hand.Hand(p2_dealt_hand)
        #For heuristically influenced hand selection
        h1_selects = h1.optimize_by_points(2)
        h2_selects = h2.optimize_by_points(2)
        p1.cards = list(h1_selects)
        p2.cards = list(h2_selects)
        p1_discards = []
        p2_discards = []

        for cp1, cp2 in zip(p1_dealt_hand, p2_dealt_hand):
            if cp1 not in h1_selects:
                p1_discards.append(cp1)
            if cp2 not in h2_selects:
                p2_discards.append(cp2)

        crib.extend(p1_discards)
        crib.extend(p2_discards)
        """
        h1_combos = combinations(p1_dealt_hand, 4)
        h2_combos = combinations(p2_dealt_hand, 4)
        for h1h, h2h in zip(h1_combos, h2_combos):
            if len(h1h) == 4 and len(h2h) == 4:
                p1.cards = h1h
                p2.cards = h2h
                h1_disc = []
                h2_disc = []
                for card in p1_dealt_hand:
                    if card not in p1.cards:
                        h1_disc.append(card)
                for card in p2_dealt_hand:
                    if card not in p2.cards:
                        h2_disc.append(card)
                crib.extend(h1_disc)
                crib.extend(h2_disc)
                is_dealer_p1 = True
                peg_sequence(is_dealer_p1, turncard, p1, p2)
                p1_peg = p1.score
                p2_peg = p2.score
                show_sequence(turncard, p1, p2)
                crib_pts = crib_sequence(turncard, crib)
                if len(p1.cards) == 4 and len(p2.cards) == 4:
                    memorize_results(p1, p2, p1_peg, p2_peg, is_dealer_p1)
                if len(h1_disc) == 2 and len (h2_disc) == 2:
                    memorize_discards(h1_disc, h2_disc, crib_pts, is_dealer_p1)
                p1.score = 0
                p2.score = 0
                is_dealer_p1 = False
                peg_sequence(is_dealer_p1, turncard, p1, p2)
                p1_peg = p1.score
                p2_peg = p2.score
                show_sequence(turncard, p1, p2)
                crib_pts = crib_sequence(turncard, crib)
                if len(p1.cards) == 4 and len(p2.cards) == 4:
                    memorize_results(p1, p2, p1_peg, p2_peg, is_dealer_p1)
                if len(h1_disc) == 2 and len (h2_disc) == 2:
                    memorize_discards(h1_disc, h2_disc, crib_pts, is_dealer_p1)
                """

        #Main driver block: peg sequence updates player scores; scores stored before updated again in show_sequence
    peg_sequence(is_dealer_p1, turncard, p1, p2)
    p1_peg = p1.score
    p2_peg = p2.score
    show_sequence(turncard, p1, p2)
    crib_pts = crib_sequence(turncard, crib)
    if is_dealer_p1:
        p1.score += crib_pts
    else:
        p2.score += crib_pts
    #Memorize the results, check for occasionally memory corruption
    #if len(p1.cards) == 4 and len(p2.cards) == 4:
    #memorize_results(p1, p2, p1_peg, p2_peg, is_dealer_p1)
    #memorize_discards(p1_discards, p2_discards, crib_pts, is_dealer_p1)
    return [p1.score, p2.score]
예제 #5
0
 def setUp(self):
     # player needs values: [player name, player type, player color]
     player = ['Red', 0, 'r']
     # hand needs values: start position, player
     self.hand = hand.Hand((0, 0), player)
예제 #6
0
def show_sequence(turncard, p1, p2):
    h1 = hand.Hand(p1.cards, turncard=turncard)
    h2 = hand.Hand(p2.cards, turncard=turncard)
    p1.score += h1.compute_score()
    p2.score += h2.compute_score()
예제 #7
0
def crib_sequence(turncard, crib_hand):
    c = hand.Hand(crib_hand, is_crib=True, turncard=turncard)
    return c.compute_score()
예제 #8
0
    def endHand(self):

        theWinner = None

        maxWin = {}
        for p in self.players:
            maxWin[p.id] = p.pot

        if self.numInHand == 1:
            for p in self.players:
                if p.isInHand:
                    winningIDs = [p.id]

        elif self.numInHand > 1:

            #NEED TO ADD REVEAL CODE HERE

            assert len(self.communityCards) == 5

            hands = []
            for p in self.players:
                if p.isInHand:
                    hands.append(
                        hand.Hand(p.pocket + self.communityCards, ID=p.id))

            winningIDs = hand.winner(hands)

        else:
            assert False

        displayText = ""
        handName = ""
        for ID in winningIDs:
            p = self.getPlayerByID(ID)
            if len(displayText) == 0:
                displayText += p.name
                #If the winner revealed their hand include some text to show who won
                if p.hasRevealed:
                    handName = " with " + hand.Hand(
                        p.pocket + self.communityCards).handName()
                else:
                    handName = "."
                token = " has won"
            else:
                displayText += ", " + p.name
                token = " have tied"
        displayText += token + " this hand" + handName

        splitPots = []
        while len(winningIDs) > 0:

            #First, we need to create split pots for winners who only partially contributed
            lowestPotContribution = -10
            for p in self.players:
                if (p.id in winningIDs) and (p.pot < lowestPotContribution
                                             or lowestPotContribution == -10):
                    lowestPotContribution = p.pot

            #Make a new split pot
            potAmount = 0
            for p in self.players:
                deduction = min(lowestPotContribution, p.pot)
                p.pot -= deduction
                potAmount += deduction

            splitIDs = winningIDs[:]
            splitPots.append((potAmount, splitIDs))

            #Remove all players who are no longer inHand from the winningIDs
            for p in self.players:
                if p.id in winningIDs and p.pot <= 0:
                    winningIDs.remove(p.id)

        #Any remaining money should return back to the original owner
        for p in self.players:
            p.bank += p.pot
            p.pot = 0

        #Now we need to distribute the splitPots (or single pot if there was no all-in plays)
        for splitPot in splitPots:
            amount, ids = splitPot
            fraction = int(amount / len(ids))
            remainder = amount % len(ids)
            for ID in ids:
                p = self.getPlayerByID(ID)
                p.bank += fraction
                if remainder > 0:
                    p.bank += remainder
                    remainder -= 1

        #Remove bankrupt players from the game
        for p in self.players:
            if p.bank < 0:
                #Something went wrong and the player has negative money
                assert False
            elif p.bank == 0:
                self.removeFromGame(p)

        self.passToPlayers({
            state.State.CONTINUE_ONLY: True,
            state.State.CONTINUE_TEXT: displayText
        })

        #Increment the dealer

        p = self.getPlayerByID(self.currentDealer)
        p.isDealer = False
        while True:

            self.currentDealer = (self.currentDealer + 1) % self.numPlayers

            p = self.getPlayerByID(self.currentDealer)

            assert p != None

            if p.isInGame == True:
                break

        p.isDealer = True
예제 #9
0
def peg_logic(hand_playing=None, stack=None, count=None, turncard=None):
    h = hand.Hand(list_of_cards=hand_playing, turncard=turncard)
    return h.peg_selection(stack, count)
예제 #10
0
def reset_hands(lst_of_players):
    for player_obj in lst_of_players:
        player_obj.hand_of_cards = hand.Hand()
    return True
예제 #11
0
 def peg_sequence(self):
     verbose.pegging()
     verbose.continue_prompt()
     #temporary copy to restore player.cards to original state after peg_sequence() is complete
     hand1 = self.player_one.cards.copy()
     hand2 = self.player_two.cards.copy()
     if self.player_one.is_dealer:
         is_p1_turn = False
     else:
         is_p1_turn = False
     
     while self.game_not_over and (self.player_one.cards or self.player_two.cards):
         self.peg_count = 0
         stack = hand.Hand([])
         while (self.game_not_over and self.peg_count < 31) and (self.player_one.can_peg(self.peg_count) or self.player_two.can_peg(self.peg_count)):
             if is_p1_turn and self.player_one.can_peg(self.peg_count):
                 selected = self.player_one.peg_one(stack.hand, self.peg_count, self.turncard)
                 self.player_one.cards.remove(selected)
                 stack.hand.append(selected)
                 self.peg_count += selected.value
                 verbose.peg_one(self.player_one, selected, self.peg_count)
                 peg_points = stack.determine_peg_points(self.peg_count)
                 if peg_points > 0:
                     self.player_one.score += peg_points
                     verbose.peg_points(self.player_one, peg_points)
                     if self.player_one.score <= 121:
                         verbose.post_score(self.player_one, self.player_two)
                     self.update_board()
                 is_p1_turn = False
                 p1_played_last = True
                 if not self.game_not_over:
                     break
             if self.player_two.can_peg(self.peg_count):
                 selected = self.player_two.peg_one(stack.hand, self.peg_count, self.turncard)
                 self.player_two.cards.remove(selected)
                 stack.hand.append(selected)
                 self.peg_count += selected.value
                 verbose.peg_one(self.player_two, selected, self.peg_count)
                 peg_points = stack.determine_peg_points(self.peg_count)
                 if peg_points > 0:
                     self.player_two.score += peg_points
                     verbose.peg_points(self.player_two, peg_points)
                     if self.player_two.score <= 121:
                         verbose.post_score(self.player_one, self.player_two)
                     self.update_board()
                 if not self.game_not_over:
                     break
                 p1_played_last = False
                 is_p1_turn = True
             elif self.player_one.can_peg(self.peg_count):
                 is_p1_turn = True
         if self.peg_count < 31:
             if p1_played_last:
                 verbose.peg_go(self.player_one)
                 self.player_one.score += 1
                 verbose.post_score(self.player_one, self.player_two)
                 self.update_board()
             else:
                 verbose.peg_go(self.player_two)
                 self.player_two.score += 1
                 verbose.post_score(self.player_one, self.player_two)
                 self.update_board()
         if not self.game_not_over:
             break
     self.player_one.cards = hand1
     self.player_two.cards = hand2
     self.board.display_board()
예제 #12
0
파일: task.py 프로젝트: legan4ik/cards
"""
Implement a Deck of Cards, which can be used to fill Hands of Cards
"""

import card
import deck
import hand

# creating card
card1 = card.Card("Spades", '2')

# init deck
deck1 = deck.Deck()
print(deck1.remaining())

# init hand
hand1 = hand.Hand()
hand1.addCard(card1)
hand1.sortByValue()
hand1.addCard(deck1.deal())
print(hand1)
예제 #13
0
#!/usr/bin/env python3
"""
Main applikation window for the blackjack game.
"""
import deck
import hand

# Create X number of Hands (one for each player) based on previous input.
playingPlayers = list()
# Create 1 deck.
ourDeck = deck.Deck()
# Shuffle deck.
ourDeck.shuffle()

for i in range(3):
    playingPlayers.append(hand.Hand())
    # Give each player 2 starting cards.
    playingPlayers[i].takeCard(ourDeck)
    playingPlayers[i].takeCard(ourDeck)

# Save players that have stayed:
stayedPlayers = list()

# ---------------- Gameloop ----------------
# Create a loop that goes from player to player.
for i, player in enumerate(playingPlayers):
    playing = True

    # Ask if the player wants to play.
    playerChoice = input("Do you want to stay? yes/no y/n\n-->")
예제 #14
0
		def __init__(self):
			#Each player has its own hand instance to get the score and the categories used. 
			self.hand = hand.Hand()
			self.categoriesUsed = []
예제 #15
0
파일: test.py 프로젝트: waliidd/honeybot
import hand
import player
import pot
#import game_init

deck = deck.Deck()

print(deck.show_deck())
print(deck.nth_card(23))
print(deck.nth_card(23).show_card(), deck.nth_card(23).figure(), deck.nth_card(23).color(), deck.nth_card(23).value())
print(deck.draw_by_number(1).show_card())
print(deck.show_deck())
print(deck.draw_by_name('AS').show_card())
print(deck.show_deck())
print(board.Board(deck.make_board()).show_board())
print(hand.Hand(deck.make_hand()).show_hand())
print(len(deck.show_deck()))
print(deck.show_deck())
print(deck.nth_card(66).show_card())

board = board.Board(deck.make_board())

print(board.show_board())
print(deck.show_deck())
print(board.flop())
print(board.flop1())
print(board.flop2())
print(board.flop3())
print(board.turn())
print(board.river())
예제 #16
0
 def make_hand(self, a_card):
     if self.name == 'Dealer':
         a_bet = 0
     else:
         a_bet = self.get_bet()
     self.hands.append(hand.Hand(a_bet, a_card))