Exemplo n.º 1
0
def loadShoe(numberOfDecks, cardShoe):
    cutCard = Card(0, 0)
    for deck in range(0, numberOfDecks):
        for suit in range(1, 4):
            for rank in range(1, 14):
                cardShoe.append(Card(rank, suit))
    random.shuffle(cardShoe)  #shuffle the cardShoe
    #index between 70-90% of the BACK of the deck to insert the cutCard
    minIndex = math.floor((52 * numberOfDecks) * .1)
    maxIndex = math.floor((52 * numberOfDecks) * .3)
    cardShoe.insert(random.randint(minIndex, maxIndex), cutCard)
Exemplo n.º 2
0
 def select_deck(
     self,
     name,
     user_id,
 ):
     """Load deck from database"""
     self.connect()
     conn = self.connection
     # Check for existence of deck, TODO for not
     if (self.is_deck_exist(name, user_id)):
         with conn:
             cursor = self.connection.cursor()
             keys = (
                 name,
                 user_id,
             )
             cursor.execute(
                 'SELECT id FROM Decks WHERE (name = ? AND user_id = ?)',
                 keys)
             deck_id = cursor.fetchone()
             cursor.execute(
                 'SELECT name, position, random_id, path_to_image FROM Cards WHERE deck_id = ?',
                 deck_id)
             card_rows = cursor.fetchall()
             card_list = []
             # Unpacking cards
             for c_name, c_position, c_random_id, c_path_to_image in card_rows:
                 card = Card(c_name, c_position, c_random_id,
                             c_path_to_image)
                 card_list.append(card)
             deck = DeckClass.Deck(name, user_id)
             deck.card_list = card_list
             return deck
Exemplo n.º 3
0
 def initializeDeck(self):
     for i in range(1, 4):
         suit = self.suits[i]
         for x in range(1, 13):
             rank = x
             c = Card(rank, suit)
             self.cards.append(c)
Exemplo n.º 4
0
	def __init__(self):
		self._cards = []
		values = range(2,15)
		suits = ["Clubs", "Spades", "Hearts", "Diamonds"]

		for suit in suits:
			for value in values:
				self._cards.append(Card(value, suit))
Exemplo n.º 5
0
 def resetDeck(self):
     self.drawDeck = []
     self.discardDeck = []
     f = open(file)
     for line in f:
         l = (f.readline())
         c = Card(l)
         self.drawDeck.append(c)
Exemplo n.º 6
0
 def __init__(self):
     self.drawDeck = []
     self.discardDeck = []
     f = open(file)
     for line in range(80):
         l1 = f.readline().rstrip()
         l2 = f.readline().rstrip()
         l3 = f.readline().rstrip()
         c = Card(l1, l2, l3)
         self.drawDeck.append(c)
Exemplo n.º 7
0
 def initializeDeck(self):
     #this method populates the cards List
     #with cards
     #loop through the suits
     for i in range(1, 4):
         suit = self.suits[i]
         #loop through the ranks
         for x in range(1, 13):
             rank = x
             #create a card
             c = Card(rank, suit)
             #add to list of cards
             self.cards.append(c)
Exemplo n.º 8
0
 def create(self, deck_name=""):
     """Make new deck with all cards"""
     random_id = 1  # TODO
     if (deck_name == ""):
         deck_name = self.name
     # forming cards
     file_name = get_list_of_cards(deck_name)
     pathes = get_list_of_pathes(deck_name)
     with open(file_name) as file:
         for (line, path) in zip(enumerate(file), pathes):
             position, name = line[0], line[1]   # workaround TODO
             # some problems with multiple unpacking
             self.card_list.append(Card(name, position, random_id, path))
Exemplo n.º 9
0
def shuffle_test():
    list_test = []
    result = []
    for i in range(78):
        list_test.append(Card(str(i), i, i))
    for card in list_test:
        result.append(card.name)
    print(','.join(result))
    result = []
    card_shuffle(list_test)
    for card in list_test:
        result.append(card.name)
    print(','.join(result))
Exemplo n.º 10
0
choices = ["S", "H", "D", "T"]  #choices 0-3
data_file = "500_alldecisions.pickle"

pickle_in = open(data_file, "rb")
data_input = pickle.load(pickle_in)
pickle_in.close()

# data = []
# labels = []
# for datapoint in data_input:
#     data.append(datapoint[:-1])
#     labels.append(datapoint[-1])

incorrect = 0
for softScore, hardScore, dealerCard, card1, canSplit, canDoubleDown, numberOfCards, choice in data_input:
    dealerCard = Card(dealerCard, 1)  #randomly select a value from 0-12
    card1 = Card(card1, 1)  #randomly select a value from 0-12]
    label = choices[labeler(dealerCard, softScore, hardScore, card1, canSplit,
                            canDoubleDown)].lower()
    if (choice != label):
        incorrect += 1
        print(softScore, hardScore, dealerCard, card1, canSplit, canDoubleDown,
              numberOfCards, label, choice)
print(len(data_input))
print(incorrect)

# # Create a new model instance
# model = create_model()
#
# # Restore the weights
# model.load_weights('./checkpoints/TrainedModel')
Exemplo n.º 11
0
TwoCardDatapoints = 500000
ThreeCardDatapoints = 500000
AceThreshhold = 50000  #make sure there are plenty of Ace cases for soft score valuing
train_data_file = "train_data.pickle"
train_labels_file = "train_labels.pickle"
# Stand, Hit, DoubleDown, Split
choices = ["S", "H", "D", "T"]  #choices 0-3

data = []
train_data = []
train_labels = []
counter = 0

while (counter < ThreeCardDatapoints):
    counter += 1
    dealerCard = Card(random.randint(1, 13),
                      random.randint(1, 4))  #randomly select a value from 0-12
    if (counter < AceThreshhold):
        card1 = Card(1, random.randint(1, 4))  #Ace
    else:
        card1 = Card(random.randint(1, 13),
                     random.randint(1, 4))  #randomly select a value from 0-12
    card2 = Card(random.randint(1, 13),
                 random.randint(1, 4))  #randomly select a value from 0-12
    hand = BlackjackHand()
    hand.addCard(card1)
    hand.addCard(card2)
    numberOfCards = len(hand.cards)
    canSplit = hand.canSplit
    canDoubleDown = hand.canDoubleDown
    softScore = hand.getSoftScore()
    hardScore = hand.getHardScore()
Exemplo n.º 12
0
 def populateDeck(self):
     suits = ["h", "d", "c", "s"]
     for s in suits:  #"s" represents the suit of cards
         for i in range(1, 14):  #"i" represents 1
             card = Card(i, s)
             self.cards.append(card)
Exemplo n.º 13
0
from CardClass import Card

c = Card(11, "h")
print(c)
Exemplo n.º 14
0
from CardClass import Card
from PlayerClass import Player
from BlackjackHandClass import BlackjackHand
c1 = Card(1, 1)  #Ace
c2 = Card(13, 1)  #King

p1 = Player("test")
h1 = BlackjackHand()
p1.addHand(h1)
h1.addCard(c1)
h1.addCard(c2)

print("Hand 1: ")
print(h1.cards)
print("Hard: " + str(h1.getHardScore()))  #11
print("Soft: " + str(h1.getSoftScore()))  #Blackjack!

h2 = BlackjackHand()
c1 = Card(1, 1)  #Ace
c2 = Card(4, 1)  #4
c3 = Card(6, 3)  #6
h2.addCard(c1)
h2.addCard(c2)
h2.addCard(c3)
p1.addHand(h2)
print("Hand 2")
print(h2.cards)
print("Hard: " + str(h2.getHardScore()))  #11
print("Soft: " + str(h2.getSoftScore()))  #21

c4 = Card(5, 4)  #6
Exemplo n.º 15
0
from CardClass import Card

c=Card(13, "h")
print (c)
Exemplo n.º 16
0
 def __init__(self):
     self.deck = []
     for suit in suits:
         for rank in ranks:
             self.deck.append(Card(suit,rank))