コード例 #1
0
 def testdeckremovebottom(self):
     c = DeckOfCards([
         '1020', '1020', '1020', '1020', '1020', '1020', '1020', '1020',
         '1020', '1020'
     ])
     c.dealTop()
     self.assertEqual(len(c), 9)
コード例 #2
0
    def __init__(self, current_players):

        self._current_players = current_players
        self._deck = DeckOfCards()
        self._current_players.append(Players("Kurpiye"))

        print("Game started..")
コード例 #3
0
 def test_isEmpty(self):
     d = DeckOfCards([1, 2])
     self.assertNotEqual(len(d), 0)
     d = DeckOfCards()
     self.assertEqual(len(d), 0)
     d = DeckOfCards([])
     self.assertEqual(len(d), 0)
コード例 #4
0
 def test_deal_all_unequal_hands(self):
     d = DeckOfCards([0, 1, 2, 3, 4, 5, 6])
     p = d.deal(2)
     self.assertEqual(len(d), 0)
     assert ([p[0].dealTop() for i in range(4)] == [6, 4, 2, 0])
     assert ([p[1].dealTop() for i in range(3)] == [5, 3, 1])
     self.assertEqual(len(p[0]), 0)
     self.assertEqual(len(p[1]), 0)
コード例 #5
0
 def test_create_deck_from_list(self):
     s = "a b c d"
     d = DeckOfCards(s.split())
     self.assertNotEqual(len(d), 0)
     self.assertEqual(d.dealTop(), 'a')
     self.assertEqual(d.dealTop(), 'b')
     self.assertEqual(d.dealTop(), 'c')
     self.assertEqual(d.dealTop(), 'd')
     self.assertEqual(len(d), 0)
コード例 #6
0
 def test_deal_all_3ways(self):
     d = DeckOfCards([0, 1, 2, 3, 4, 5, 6, 7, 8])
     p = d.deal(3)
     self.assertEqual(len(d), 0)
     assert ([p[0].dealTop() for i in range(3)] == [6, 3, 0])
     assert ([p[1].dealTop() for i in range(3)] == [7, 4, 1])
     assert ([p[2].dealTop() for i in range(3)] == [8, 5, 2])
     self.assertEqual(len(p[0]), 0)
     self.assertEqual(len(p[1]), 0)
     self.assertEqual(len(p[2]), 0)
コード例 #7
0
 def test_dealTop_and_dealBottom(self):
     s = "111 222 333 444 555 666 777 888 999"
     d = DeckOfCards(s.split())
     self.assertNotEqual(len(d), 0)
     assert (d.dealTop() == '111')
     assert (d.dealBottom() == '999')
     assert (d.dealTop() == '222')
     assert (d.dealBottom() == '888')
     assert (d.dealTop() == '333')
     assert (d.dealBottom() == '777')
     assert (d.dealBottom() == '666')
     assert (d.dealBottom() == '555')
     assert (d.dealTop() == '444')
     self.assertEqual(len(d), 0)
コード例 #8
0
 def test_addPileBottom(self):
     p = DeckOfCards([3, 4])
     d = DeckOfCards([1, 2])
     d.addPileBottom(p)
     self.assertEqual(len(p), 0)
     assert (d.dealTop() == 1)
     assert (d.dealTop() == 2)
     assert (d.dealTop() == 3)
     assert (d.dealTop() == 4)
     self.assertEqual(len(d), 0)
コード例 #9
0
 def test_addBottom(self):
     d = DeckOfCards([1, 2, 3])
     d.addBottom(4)
     d.addBottom(5)
     assert (d.dealBottom() == 5)
     assert (d.dealBottom() == 4)
     assert (d.dealBottom() == 3)
コード例 #10
0
 def test_addTop(self):
     d = DeckOfCards([3, 4, 5, 6, 7, 8])
     d.addTop(2)
     d.addTop(1)
     assert (d.dealTop() == 1)
     assert (d.dealTop() == 2)
     assert (d.dealTop() == 3)
コード例 #11
0
 def test_create_empty_deck(self):
     d = DeckOfCards()
     assert (len(d) == 0)
コード例 #12
0
def main():
    deck = DeckOfCards()
    deck.shuffle()
    input("Press a key to draw a card. ")
    last = deck.draw_card()
    print("Your choose card is: {}".format(last))
    print("Returning the card to the deck...")
    deck.add_card(last)
    deck.shuffle()

    card_found = False
    while not card_found and deck.num_cards_in_deck() > 0:
        input("Press a key to draw a card. ")
        new_card = deck.draw_card()
        print("Your choose card is: {}".format(new_card))
コード例 #13
0
class Game(Players, DeckOfCards):
    def __init__(self, current_players):

        self._current_players = current_players
        self._deck = DeckOfCards()
        self._current_players.append(Players("Kurpiye"))

        print("Game started..")

    def cards_deal(self):
        for i in range(2):
            for player in self._current_players:
                temp_card = self._deck.card_deal()
                player.hand_cards = temp_card
                player.hand_value = self._deck.cardvalue(temp_card)

    def isBlackJack(self):
        for player in self._current_players:
            if player.hand_value == 21:
                player.black_jack = 1
                player.score = 1

    def scoreValues(self):
        if self._current_players[0].black_jack == 1:
            return
        elif self._current_players[0].bust > 0:  # Kurpiye = BUST
            for player in self._current_players[1:]:
                if player.bust == 0 and player.black_jack == 0:  #Player nicht Bust und nicht BlackJack
                    player.score = 1

        elif self._current_players[
                0].bust == 0:  # Kurpiye nicht BUST - valuHands zwieschen 17-21
            for player in self._current_players[1:]:
                if player.black_jack == 0 and self._current_players[
                        0].hand_value > player.hand_value:
                    self._current_players[0].score = 1
                elif player.black_jack == 0 and self._current_players[
                        0].hand_value < player.hand_value and player.bust == 0:
                    player.score = 1
                elif player.black_jack == 0 and self._current_players[
                        0].hand_value == player.hand_value and player.bust == 0:
                    player.score = 0
                    self._current_players[0].score = 0

    def acecontrol(self):
        pass

    # if kurpiyes card2 = 0, it shown as "?"

    def write_values(self, kurpiyes_card2):
        if kurpiyes_card2 == 1:
            for player in self._current_players:
                print(
                    f"{player.name} = {player.hand_cards} => {player.hand_value}",
                    "=> BUST " if player.bust == 1 else '',
                    "!!! Win !!!" if player.score > 0 else '!!! Lose !!!',
                    " => !!! Black Jack !!!" if player.black_jack == 1 else '')

        elif kurpiyes_card2 == 0:
            for player in self._current_players:
                if player.name == "Kurpiye":
                    print(f"{player.name} = {player.hand_cards[0]} + ?")
                else:
                    print(
                        f"{player.name} = {player.hand_cards} => {player.hand_value}",
                        " => !!! Black Jacj !!!"
                        if player.black_jack == 1 else '')
コード例 #14
0
ファイル: test.py プロジェクト: teoizkrov/DeckOfCards
#from card import Card
from collections import deque
from deckofcards import DeckOfCards

#c = Card( "Hearts", 12)
#print( c )
#
#d = deque()
#d.append( c )
#
#for i in d:
#    print( i )

d = DeckOfCards()

print(d)

d.shuffle()

print(d)
コード例 #15
0
    def __init__(self, interface):
        self.gameDeck = DeckOfCards()
        self.o_A = TABLE()
        self.o_B = TABLE()
        self.o_C = TABLE()
        self.o_D = TABLE()
        self.o_E = TABLE()
        self.o_F = TABLE()
        self.o_G = TABLE()
        self.tableau = [
            self.o_A, self.o_B, self.o_C, self.o_D, self.o_E, self.o_F,
            self.o_G
        ]
        self.o_heartGoal = goalPile(Suit.Heart)
        self.o_diamondGoal = goalPile(Suit.Diamond)
        self.o_spadeGoal = goalPile(Suit.Spade)
        self.o_clubGoal = goalPile(Suit.Club)
        self.o_draw = DRAWPILE()
        self.o_discard = DISCARDPILE()
        self.o_temp = transaction(None)
        self.dealCards()
        self.backCard = ColorCardView("Card_Back", Suit.Blank, 0, "__")
        self.buttonBackCard = ColorCardView("Card_Back", Suit.Blank, 0,
                                            "SolitaireGAME..")
        self.milkCard = ColorCardView("Milk", Suit.Milk, 0, ".")

        self.gameTopRow = 2  # for Grid Layout

        self.win = Frame(interface, height=500, width=640, bg=FELT_GREEN)
        self.win.pack()

        # Obligatory Game Label
        Label(self.win, text="SOLITAIRE GAME", bg="White").grid(row=0,
                                                                column=0,
                                                                columnspan=15)
        self.returnCardLabel(self.buttonBackCard, self.win).grid(row=1,
                                                                 column=0)
        for x in range(1, 14):
            self.returnCardLabel(self.backCard, self.win).grid(row=1, column=x)
        for x in range(14, 16):
            self.returnCardLabel(self.buttonBackCard, self.win).grid(row=1,
                                                                     column=x)

        # ***** ***** ***** ***** *****
        # Set up Tableau Buttons
        self.gB_A = Button(self.win,
                           text="Select",
                           name="_A",
                           command=self.changeButtonA)
        self.gB_B = Button(self.win,
                           text="Select",
                           name="_B",
                           command=self.changeButtonB)
        self.gB_C = Button(self.win,
                           text="Select",
                           name="_C",
                           command=self.changeButtonC)
        self.gB_D = Button(self.win,
                           text="Select",
                           name="_D",
                           command=self.changeButtonD)
        self.gB_E = Button(self.win,
                           text="Select",
                           name="_E",
                           command=self.changeButtonE)
        self.gB_F = Button(self.win,
                           text="Select",
                           name="_F",
                           command=self.changeButtonF)
        self.gB_G = Button(self.win,
                           text="Select",
                           name="_G",
                           command=self.changeButtonG)
        self.tableauButtons = [
            self.gB_A, self.gB_B, self.gB_C, self.gB_D, self.gB_E, self.gB_F,
            self.gB_G
        ]

        # Set up Tableau Cards
        self.gL_A = self.returnCardLabel(self.o_A.getTopCard(), self.win)
        self.gL_B = self.returnCardLabel(self.o_B.getTopCard(), self.win)
        self.gL_C = self.returnCardLabel(self.o_C.getTopCard(), self.win)
        self.gL_D = self.returnCardLabel(self.o_D.getTopCard(), self.win)
        self.gL_E = self.returnCardLabel(self.o_E.getTopCard(), self.win)
        self.gL_F = self.returnCardLabel(self.o_F.getTopCard(), self.win)
        self.gL_G = self.returnCardLabel(self.o_G.getTopCard(), self.win)
        self.tableauCards = [
            self.gL_A, self.gL_B, self.gL_C, self.gL_D, self.gL_E, self.gL_F,
            self.gL_G
        ]

        # Tableau Other
        self.gL_AStack = [self.gL_A]
        self.gL_BStack = [self.gL_B]
        self.gL_CStack = [self.gL_C]
        self.gL_DStack = [self.gL_D]
        self.gL_EStack = [self.gL_E]
        self.gL_FStack = [self.gL_F]
        self.gL_GStack = [self.gL_G]
        for xcol in range(2, 14):
            aLabel = self.returnCardLabel(self.milkCard, self.win)
            aLabel.grid(row=2, column=xcol)
            self.gL_AStack.append(aLabel)
            bLabel = self.returnCardLabel(self.milkCard, self.win)
            bLabel.grid(row=3, column=xcol)
            self.gL_BStack.append(bLabel)
            cLabel = self.returnCardLabel(self.milkCard, self.win)
            cLabel.grid(row=4, column=xcol)
            self.gL_CStack.append(cLabel)
            dLabel = self.returnCardLabel(self.milkCard, self.win)
            dLabel.grid(row=5, column=xcol)
            self.gL_DStack.append(dLabel)
            eLabel = self.returnCardLabel(self.milkCard, self.win)
            eLabel.grid(row=6, column=xcol)
            self.gL_EStack.append(eLabel)
            fLabel = self.returnCardLabel(self.milkCard, self.win)
            fLabel.grid(row=7, column=xcol)
            self.gL_FStack.append(fLabel)
            gLabel = self.returnCardLabel(self.milkCard, self.win)
            gLabel.grid(row=8, column=xcol)
            self.gL_GStack.append(gLabel)

        # Set up Goal Buttons
        self.gB_Spades = Button(self.win,
                                text="Place",
                                command=self.placeSpade)
        self.gB_Hearts = Button(self.win,
                                text="Place",
                                command=self.placeHeart)
        self.gB_Clubs = Button(self.win, text="Place", command=self.placeClub)
        self.gB_Diamonds = Button(self.win,
                                  text="Place",
                                  command=self.placeDiamond)
        self.goalButtons = [
            self.gB_Spades, self.gB_Hearts, self.gB_Clubs, self.gB_Diamonds
        ]

        # Set up Goal Spots
        self.gL_Spades = self.returnGoalLabel(self.o_spadeGoal.getTopCard(),
                                              Suit.Spade, self.win)
        self.gL_Hearts = self.returnGoalLabel(self.o_heartGoal.getTopCard(),
                                              Suit.Heart, self.win)
        self.gL_Clubs = self.returnGoalLabel(self.o_clubGoal.getTopCard(),
                                             Suit.Club, self.win)
        self.gL_Diamonds = self.returnGoalLabel(
            self.o_diamondGoal.getTopCard(), Suit.Diamond, self.win)
        self.goalCards = [
            self.gL_Spades, self.gL_Hearts, self.gL_Clubs, self.gL_Diamonds
        ]

        # Set up Discard Spot
        Label(self.win, text="Discard", bg="White").grid(row=self.gameTopRow,
                                                         column=14)
        self.gB_Discard = Button(self.win,
                                 text="Select",
                                 command=self.onClick_gB_Discard)
        self.gL_Discard = self.returnGoalLabel(self.o_discard.getTopCard(),
                                               Suit.Blank, self.win)

        # Set up Draw Spot
        Label(self.win, text="Draw Pile", bg="White").grid(row=self.gameTopRow,
                                                           column=15)
        self.gB_Draw = Button(self.win,
                              text="Draw",
                              command=self.onClick_gB_Draw)

        # ***** ***** ***** ***** *****
        # Place Tableau Buttons
        bCount = self.gameTopRow
        for b in self.tableauButtons:
            b.grid(row=bCount, column=0)
            bCount = bCount + 1

        # Place Tableau Cards
        cCount = self.gameTopRow
        for c in self.tableauCards:
            c.grid(row=cCount, column=1)
            cCount = cCount + 1

        # Place Goal Buttons
        gCount = self.gameTopRow + 3
        for g in self.goalButtons:
            g.grid(row=gCount, column=15)
            gCount = gCount + 1

        # Place Goal Spots
        gcCount = self.gameTopRow + 3
        for gc in self.goalCards:
            gc.grid(row=gcCount, column=14)
            gcCount = gcCount + 1

        # Place Discard Spot
        self.gB_Discard.grid(row=(self.gameTopRow + 1), column=14)
        self.gL_Discard.grid(row=(self.gameTopRow + 2), column=14)

        # Place Draw Spot
        self.gB_Draw.grid(row=(self.gameTopRow + 1), column=15)

        # ***** ***** ***** ***** *****
        # Assign Discard Buttons to Object
        self.o_discard.button = self.gB_Discard
        self.o_discard.label = self.gL_Discard

        # Assign Draw Buttons to Object
        self.o_draw.button = self.gB_Draw

        # Assign Tableau Cards
        self.o_A.button = self.gB_A
        self.o_B.button = self.gB_B
        self.o_C.button = self.gB_C
        self.o_D.button = self.gB_D
        self.o_E.button = self.gB_E
        self.o_F.button = self.gB_F
        self.o_G.button = self.gB_G
        self.o_A.label = self.gL_A
        self.o_B.label = self.gL_B
        self.o_C.label = self.gL_C
        self.o_D.label = self.gL_D
        self.o_E.label = self.gL_E
        self.o_F.label = self.gL_F
        self.o_G.label = self.gL_G
        self.o_A.labelStack = self.gL_AStack
        self.o_B.labelStack = self.gL_BStack
        self.o_C.labelStack = self.gL_CStack
        self.o_D.labelStack = self.gL_DStack
        self.o_E.labelStack = self.gL_EStack
        self.o_F.labelStack = self.gL_FStack
        self.o_G.labelStack = self.gL_GStack

        # Assign Goal Spots
        self.o_spadeGoal.button = self.gB_Spades
        self.o_heartGoal.button = self.gB_Hearts
        self.o_clubGoal.button = self.gB_Clubs
        self.o_diamondGoal.button = self.gB_Diamonds
        self.o_spadeGoal.label = self.gL_Spades
        self.o_heartGoal.label = self.gL_Hearts
        self.o_clubGoal.label = self.gL_Clubs
        self.o_diamondGoal.label = self.gL_Diamonds
コード例 #16
0
 def testdeckoften(self):
     c = DeckOfCards([
         '1020', '1020', '1020', '1020', '1020', '1020', '1020', '1020',
         '1020', '1020'
     ])
     self.assertEqual(len(c), 10)
コード例 #17
0
 def testemptydeck(self):
     c = DeckOfCards()
     self.assertEqual(len(c), 0)
コード例 #18
0
ファイル: setdeck.py プロジェクト: DevonLetendre/SetWar
 def __init__(self, cards=None, pnum=None):
     DeckOfCards.__init__(self, cards)
     self.pnum = pnum
コード例 #19
0
 def __init__(self, cards=None):
     DeckOfCards.__init__(self, cards)