def __init__(self):
     super().__init__('Dealer', self)
     self.deck = CardDeck()
     self.busted = False
     self.black_jack = False
     self.is_processing_done = False
     self.is_standing = False
 def __init__(
     self
 ):  # Constructor to initalize the dealer info and ensure that Player class' (the base class) constructor is invoked as necessary
     super().__init__("Dealer",
                      self)  # Invokes the Player class' constructor
     self.deck = CardDeck()  # Creates a new CardDeck object
     self.natural_blackjack_dflag = 0
class Dealer(Player):
    def __init__(
        self
    ):  # Constructor to initalize the dealer info and ensure that Player class' (the base class) constructor is invoked as necessary
        super().__init__("Dealer",
                         self)  # Invokes the Player class' constructor
        self.deck = CardDeck()  # Creates a new CardDeck object
        self.natural_blackjack_dflag = 0

    def shuffle_deck(
            self):  # The dealer uses the Cardeck Object to shuffle the deck
        self.deck.shuffle()  # Shuffles the deck

    def signal_hit(
        self, player
    ):  # Used to request a card after which, the dealer picks up a card from the top of the pile and gives it to the person who requested the card
        player.deal_to(self.deck.draw()
                       )  # The dealer draws the topmost card from the deck

    def play_round(self):  # Simulates the dealer playing a round of blackjack
        if self.card_sum < 17:  # The dealer hits as long his card sum is less than 17
            self.deal_to(self.deck.draw(
            ))  # The dealer hits (draws a car from the top of the deck)
            self.play_round(
            )  # Recursively calls play round till the dealer's card sum is more than 16 after which, the dealer stands
Exemple #4
0
 def __init__(self):
     self.deck = CardDeck()
     self.deck.shuffle()
     self.placed_cards = []
     for _ in range(0, 9):
         card = self.deck.take()
         self.placed_cards.append(card)
Exemple #5
0
class Dealer(Player):

    def __init__(self):
        super().__init__("Dealer", None)
        self.deck = CardDeck()

    def shuffle_deck(self):
        """
        >>> import random; random.seed(1)
        >>> dealer = Dealer()
        >>> dealer.shuffle_deck()
        >>> str(dealer.deck)[0:20]
        '10 8 10 6 8 9 3 10 2'
        """
        self.deck.shuffle()

    def signal_hit(self, player):
        """
        A method called by players when they want to hit
        Player objects should pass their `self` references to this method
        Should deal one card to the player that signalled a hit

        These doctests will not run properly if the `deal_to` method 
        in the `Player` class is not properly implemented

        >>> import random; random.seed(1)
        >>> dealer = Dealer()
        >>> dealer.shuffle_deck()
        >>> player = Player(None, None)
        >>> dealer.signal_hit(player)
        >>> player.hand
        [10]
        """
        card = self.deck.draw()
        if card:
            player.deal_to(card)

    def play_round(self):
        """
        A dealer should hit if his hand totals to 16 or less

        >>> import random; random.seed(1)
        >>> dealer = Dealer()
        >>> dealer.shuffle_deck()
        >>> dealer.play_round()
        >>> dealer.hand
        [10, 8]
        """
        while not self.busted and self.card_sum <= 16:
            self.signal_hit(self)
Exemple #6
0
    def __init__(self, num_players: int, player_names: List[str]):
        LOG.info("Call to GameBoard.__init__")

        self.red_deck = CardDeck(
            "People"
        )  # Are these the right color to category mappings?  If we want to stick with colors, that's fine
        self.white_deck = CardDeck("Events")
        self.blue_deck = CardDeck("Places")
        self.green_deck = CardDeck("Independence Day")

        self.die = Die(num_sides=6)
        self.game_positions = GamePositions()

        self.players = []
        self.current_player = None  # It might be useful to have this property to easily access the player whose turn it is
        self.direction = ""  # The direction the player has chosen to move (not yet sure what values this can take)

        self.pixel_to_position_scaling_factor = 78  # Multiple a game_position location (in matrix) by this number to get the pixel location equivalent
        self.pixel_to_position_offset = (
            12, 12
        )  # add these x and y values to the scaled pixel location to get starting square (since it isn't in top left corner)

        colors = ['red', 'white', 'blue', 'green']
        for player_num in range(0, num_players):
            self.players.append(
                Mover(name=player_names[player_num],
                      mover_color=colors[player_num],
                      start_pos_x=0,
                      start_pos_y=0))
Exemple #7
0
class Dealer(Player):
    def __init__(self):
        self.deck = CardDeck()
        super().__init__('Dealer', self)

        return

    def shuffle_deck(self):

        self.deck.shuffle()
        return

    def signal_hit(self, player):

        player.deal_to(self.deck.draw())
        return

    def play_round(self):

        while self.card_sum < 17:
            self.deal_to(self.deck.draw())
        return
Exemple #8
0
    def __init__(self):
        self.deck = CardDeck()
        super().__init__('Dealer', self)

        return
class Dealer(Player):

    def __init__(self):
        super().__init__('Dealer', self)
        self.deck = CardDeck()
        self.busted = False
        self.black_jack = False
        self.is_processing_done = False
        self.is_standing = False


    def shuffle_deck(self):
        """
        >>> import random; random.seed(1)
        >>> dealer = Dealer()
        >>> dealer.shuffle_deck()
        >>> str(dealer.deck)[0:20]
        '10 8 10 6 8 9 3 10 2'
        """
        self.deck.shuffle()

    def signal_hit(self, player):
        """
        A method called by players when they want to hit
        Player objects should pass their `self` references to this method
        Should deal one card to the player that signalled a hit

        These doctests will not run properly if the `deal_to` method 
        in the `Player` class is not properly implemented

        >>> import random; random.seed(1)
        >>> dealer = Dealer()
        >>> dealer.shuffle_deck()
        >>> player = Player(None, None)
        >>> dealer.signal_hit(player)
        >>> player.hand
        [10]
        """

        if player != None:
            player.deal_to(self.deck.draw())
        else:
            self.deal_to(self.deck.draw())

        


    def play_round(self):
        """
        A dealer should hit if his hand totals to 16 or less

        >>> import random; random.seed(1)
        >>> dealer = Dealer()
        >>> dealer.shuffle_deck()
        >>> dealer.play_round()
        >>> dealer.play_round()
        >>> dealer.hand
        [10, 8]
        """
        if len(self.hand) < 2:
            if len(self.hand) == 0:
                self.signal_hit(None)
                return
            if len(self.hand) == 1:
                self.signal_hit(None)
                if self.card_sum > 16 and self.card_sum < 21:
                    self.is_standing = True
                    return
                if self.card_sum == 21:
                    self.busted = True
                    self.black_jack = True
                    return
                if self.card_sum > 21:
                    self.busted = True
                    return
        if self.card_sum <= 16:
            while self.card_sum <= 16:
                self.signal_hit(None)
                if self.card_sum > 16 and self.card_sum < 21:
                    self.is_standing = True
                    break
                if self.card_sum == 21:
                    self.busted = True
                    self.black_jack = True
                    break
                if self.card_sum > 21:
                    self.busted = True
                    break
                    
    def get_name(self):
        return self.__class__.__name__
    
    def __str__(self):
        """Return string representation for str()."""
        return f'Dealer: {self.hand} 0/0/0'
Exemple #10
0
 def __init__(self, deck=None, shuffling_requested=True):
     self._deck = deck if deck else CardDeck().cards
     self.discard_pile = []
     self.shuffling_requested = shuffling_requested
     self.draw_pile = self.shuffled_cards
     self.shown_cards = []
Exemple #11
0
def main():
    
    # initialize variable to kick process out of loop 
    loop = 0

    #initialize variable to count the total number of sets that were found
    set_count = 0

      # Define lists that contain card characteristics THESE LISTS WILL GET PASSED IN
    colors = ['R', 'G', 'P']  # Red, Green, Purple
    shapes = ['Ov', 'Di', 'Sg']  # Oval, Diamond, Squiggle
    fills = ['So', 'St', 'Nf']  # Solid, Stripes, Nofill
    counts = ['1', '2', '3']

    # instantiate a card deck
    deck = CardDeck(colors,shapes,fills,counts).build_deck()
    print(deck)

    print('There are '+ str(len(deck))+ ' cards in the deck')

    # select the first 12 cards to start
    cardsInPlay = drawCards(deck,12)
    print('Current Cards in Play: ')
    print(cardsInPlay)
    
    print('There are '+ str(len(deck)) + ' cards remaining in the deck')

    while loop != 2 or len(deck)>=3 :
        # build combos
        comboList = createCombos(cardsInPlay)
        # if a set was found, foundSet will be a string such as 3_St_G_Di,3_So_G_Ov,3_Nf_G_Ss
        foundSet = checkForSets(comboList)

        # If no sets were found among the cards in play
        if foundSet == 'NoSetFound':
            if len(deck) != 0: # if there are still card in the deck
                print('No Set Found')
                # select another three cards from the deck
                threeCards = drawCards(deck,3)
                print('Three new cards: ' + str(threeCards))
                # append cards to Cards in Play so there are now 15 cards in play
                cardsInPlay.append(threeCards[0])
                cardsInPlay.append(threeCards[1])
                cardsInPlay.append(threeCards[2])
            else: # if there are no cards remaining in the deck set flag to exit loop
                loop = 2

        # if a set WAS found:
        else:
            # use split to turn the 3 card string into a list
            setList = foundSet.split(',')
            print('SET found: ' + str(setList))
            set_count = set_count + 1
            print('Set count: ' + str(set_count))
            # remove the three cards from Cards In Play
            for card in setList:
                cardsInPlay.remove(card)

            print()

            if len(cardsInPlay) == 9:
                if len(deck)>=3:
                    threeCards = drawCards(deck,3)
                    cardsInPlay.append(threeCards[0])
                    cardsInPlay.append(threeCards[1])
                    cardsInPlay.append(threeCards[2])
                else:
                    loop += 1

        if loop !=2:
            print('Cards In Play: ' + str(cardsInPlay))
            #stop = input(print('There are '+ str(len(deck)) + ' cards remaining in the deck'))
            print('There are ' + str(len(deck)) + ' cards remaining in the deck')
            #print(deck)

    print('No SETs found in remaining Cards in Play')
    print('Total SETs found: ' + str(set_count))
Exemple #12
0
 def __init__(self):
     super().__init__("Dealer", None)
     self.deck = CardDeck()
Exemple #13
0
class Kabal:
    deck: CardDeck
    placed_cards: list

    def __init__(self):
        self.deck = CardDeck()
        self.deck.shuffle()
        self.placed_cards = []
        for _ in range(0, 9):
            card = self.deck.take()
            self.placed_cards.append(card)

    def write_status(self):
        return f"{self}\nCards left: {len(self.deck)}"

    def __str__(self):
        text = "Cards placed: \n"
        text += "Index\tCardType\tCardValue\n\n"
        index: int = 0
        for card in self.placed_cards:
            text += f"{str(index)}\t{str(card)}\n"
            index += 1
        return text

    def is_game_over(self):
        return len(self.deck) <= 0

    def place_two_cards(self, placement_index_one, placement_index_two):
        if not self.__check_cards_placement(placement_index_one,
                                            placement_index_two):
            return
        self.placed_cards[placement_index_one] = self.deck.take()
        self.placed_cards[placement_index_two] = self.deck.take()

    def place_three_cards(self, placement_index_one, placement_index_two,
                          placement_index_three):
        if not self.__check_cards_placement(placement_index_one,
                                            placement_index_two,
                                            placement_index_three):
            return
        self.placed_cards[placement_index_one] = self.deck.take()
        self.placed_cards[placement_index_two] = self.deck.take()
        self.placed_cards[placement_index_three] = self.deck.take()

    @staticmethod
    def __check_two_cards(value_one, value_two):
        if value_one + value_two == 11:
            return True
        print("Cards don't equal 11, invalid configuration")
        return False

    @staticmethod
    def __check_three_cards(value_one, value_two, value_three):
        if value_one >= 11 and value_two >= 11 and value_three >= 11:
            return True
        print("Not all cards are image cards, invalid configuration")
        return False

    def __check_cards_placement(self, index_one, index_two, index_three=-1):
        if index_three != -1:
            return self.__check_three_cards(
                self.placed_cards[index_one].value,
                self.placed_cards[index_two].value,
                self.placed_cards[index_three].value)
        return self.__check_two_cards(self.placed_cards[index_one].value,
                                      self.placed_cards[index_two].value)
Exemple #14
0
class GameBoard:
    def __init__(self, num_players: int, player_names: List[str]):
        LOG.info("Call to GameBoard.__init__")

        self.red_deck = CardDeck(
            "People"
        )  # Are these the right color to category mappings?  If we want to stick with colors, that's fine
        self.white_deck = CardDeck("Events")
        self.blue_deck = CardDeck("Places")
        self.green_deck = CardDeck("Independence Day")

        self.die = Die(num_sides=6)
        self.game_positions = GamePositions()

        self.players = []
        self.current_player = None  # It might be useful to have this property to easily access the player whose turn it is
        self.direction = ""  # The direction the player has chosen to move (not yet sure what values this can take)

        self.pixel_to_position_scaling_factor = 78  # Multiple a game_position location (in matrix) by this number to get the pixel location equivalent
        self.pixel_to_position_offset = (
            12, 12
        )  # add these x and y values to the scaled pixel location to get starting square (since it isn't in top left corner)

        colors = ['red', 'white', 'blue', 'green']
        for player_num in range(0, num_players):
            self.players.append(
                Mover(name=player_names[player_num],
                      mover_color=colors[player_num],
                      start_pos_x=0,
                      start_pos_y=0))

        #self.GUI = GameBoardGUI()
        #self.GUI.render(
        #           self,
        #           self.players,
        #           self.pixel_to_position_scaling_factor,
        #           self.pixel_to_position_offset
        #           )

    def main_gameplay_loop_GUI(self):
        self.win_x = 829
        self.win_y = 830
        self.window = Tk()

        self.load = im.open('game_board.jpg')
        self.photoImage = ImageTk.PhotoImage(self.load)

        # Draw board (stationary)
        self.window.title("Trivial Purfuit")
        self.window.configure(background='black')
        self.canvas = Canvas(self.window, width=self.win_x, height=self.win_y)

        self.canvas.create_image(self.win_x / 2,
                                 self.win_y / 2,
                                 image=self.photoImage)
        self.canvas.grid()

        # make label
        self.label = Label(
            self.window,
            text="",
        )
        self.label.grid(row=1, column=0)
        self.set_current_player(self.players[0])

        # make buttons
        b = Button(self.window,
                   text="Roll Die",
                   padx=2,
                   command=self.present_die_GUI)
        b.grid(row=3, column=0)

        b = Button(self.window,
                   text="Forward",
                   padx=2,
                   command=self.set_start_direction_fwd)
        b.grid(row=4, column=1)
        b = Button(self.window,
                   text="Reverse",
                   padx=2,
                   command=self.set_start_direction_rev)
        b.grid(row=4, column=0)

        # update label
        self.set_label_text(
            self.current_player.mover_color +
            " player's turn. Roll the die and select a direction to move!")
        # Draw movers
        self.draw_movers(self.players, self.pixel_to_position_scaling_factor,
                         self.pixel_to_position_offset)

        self.window.mainloop()  # not sure where this lives.  Here?

    def set_start_direction_fwd(self):
        print('Setting direction to "Forward"')
        self.set_label_text('Setting direction to "Forward"')
        self.game_positions.start_direction = "fwd"
        self.move_player()

    def set_start_direction_rev(self):
        print('Setting direction to "Reverse"')
        self.set_label_text('Setting direction to "Reverse"')
        self.game_positions.start_direction = "rev"
        self.move_player()

    def move_player(self):
        new_x_pos, new_y_pos = self.game_positions.find_next_position(
            self.current_player.get_pos()[0],
            self.current_player.get_pos()[1], self.die.last_roll, self.players)

        self.current_player.update_pos(new_x_pos, new_y_pos)
        self.draw_movers(self.players, self.pixel_to_position_scaling_factor,
                         self.pixel_to_position_offset)

        gp_type = self.game_positions.get_position_type(new_x_pos, new_y_pos)
        # Mapp 4 character game_positions to game_board position type
        type = GAME_POSITION_TYPE_MAP[gp_type]
        if type == 'center':
            colors = ['red', 'white', 'blue', 'green']
            n = len(colors) - 1
            i = random.randint(0, n)
            type = colors[i]

        if type != 'roll_again':
            card = self.draw_card_by_type(type)
            # card = self.MINIMAL_INCREMENT_draw_card_by_type(type)
            self.game_positions.render(self.players)
            self.display_question(card)
            self.ask_user_answer()
            answered_correct = self.display_answer(card)
            if (new_x_pos, new_y_pos
                ) in self.game_positions.get_headquarter_positions():
                is_full = self.current_player.add_wedge(type)
                if is_full:
                    self.report_end_of_game()  # should be a conditional

        self.report_end_of_turn()

    def set_label_text(self, text):
        # make label
        #self.label.config(text=text)
        self.label['text'] = text

    def main_gameplay_loop(self):
        while True:
            for player in self.players:
                # I think this should be where the gui is incorporated
                self.take_turn(player)
                self.game_positions.render(self.players)
                self.GUI.render(self.players,
                                self.pixel_to_position_scaling_factor,
                                self.pixel_to_position_offset)

    def present_die(self):
        roll_amount = input(
            "Press Enter to roll the die. Type quit to exit game.")
        if roll_amount == 'quit':
            exit()
        else:
            value = self.die.roll()
            print("Die face value: ", value)
            return value

    def present_die_GUI(self):
        value = self.die.roll()
        self.set_label_text("Die face value: " + str(value))
        print("Die face value: ", value)

        return value

    def take_turn(self, current_player: Mover):
        self.set_current_player(current_player)
        type = 'roll_again'
        answered_correct = False
        while type == 'roll_again' or answered_correct:
            self.game_positions.render(self.players)
            val = self.present_die()
            new_x_pos, new_y_pos = self.game_positions.find_next_position(
                current_player.get_pos()[0],
                current_player.get_pos()[1], val, self.players)
            current_player.update_pos(new_x_pos, new_y_pos)
            # Currently game_positions stores types of positions as 4 character stings
            gp_type = self.game_positions.get_position_type(
                new_x_pos, new_y_pos)
            # Mapp 4 character game_positions to game_board position type
            type = GAME_POSITION_TYPE_MAP[gp_type]
            if type == 'center':
                colors = ['red', 'white', 'blue', 'green']
                n = len(colors) - 1
                i = random.randint(0, n)
                type = colors[i]

            if type != 'roll_again':
                card = self.draw_card_by_type(type)
                #card = self.MINIMAL_INCREMENT_draw_card_by_type(type)
                self.game_positions.render(self.players)
                self.display_question(card)
                self.ask_user_answer()
                answered_correct = self.display_answer(card)
                # logic either needs to sit here to only add a wedge if it is isn't already owned OR let the mover worry about that (latter seems better)
                if (new_x_pos, new_y_pos
                    ) in self.game_positions.get_headquarter_positions():
                    is_full = self.current_player.add_wedge(type)
                    if is_full:
                        self.report_end_of_game()  # should be a conditional

        self.report_end_of_turn()
        return

    def display_question(self, card):
        self.set_label_text(card.type + " question: " + card.question)
        print(card.type, "question:", card.question)

    def ask_user_answer(self):
        pass
        # Ask user to press correct or incorrect button (enter logic to enable these buttons here)
        #input("Press Enter to see the answer.")

    def report_end_of_turn(self):
        input(self.current_player.name +
              ", your turn is now over.  Press Enter to finish.")

    def report_end_of_game(self, winner):
        input(winner + " has won the game!  Press Enter to finish.")
        self.end_game(
        )  # this call might better live outside of this method, like in the calling method (presumably the main gameplay loop)

    def display_answer(self, card):
        print("Answer:", card.answer)
        self.set_label_text("Answer: " + card.answer)
        #self.set_label_text(
        '''
        val = input("Did " + self.current_player.name + " answer the question correctly? [y/n]\n")
        while val not in ['y', 'n']:
            val = input("Did " + self.current_player.name + " answer the question correctly? [y/n]\n")
        if val == 'y':
            return True
        if val == 'n':
            return False
        '''

    def draw_board(self):  # for target increment
        pass

    def set_current_player(self, player):
        print('It is ' + player.name + '\'s turn!')
        self.current_player = player

    def end_game(
        self
    ):  # kick off the sequence of ending the game (proclaim the winner, etc)
        exit

    def MINIMAL_INCREMENT_draw_card_by_type(self, type):
        return Card("place_holder_type", "place_holder_question",
                    "place_holder_answer", "easiest")

    def draw_card_by_type(self, type):  # Move this logic to game board
        if type == "red":
            return self.red_deck.deal_card()
        if type == "white":
            return self.white_deck.deal_card()
        if type == "blue":
            return self.blue_deck.deal_card()
        if type == "green":
            return self.green_deck.deal_card()

    def draw_movers(self, players, pixel_to_position_scaling_factor: float,
                    pixel_to_position_offset: tuple):
        for player in players:
            self.draw_mover(player, pixel_to_position_scaling_factor,
                            pixel_to_position_offset)
        #self.window.update()

    def draw_mover(self, mover, pixel_to_position_scaling_factor: float,
                   pixel_to_position_offset: tuple):

        self.canvas.create_oval(
            pixel_to_position_offset[0] +
            mover.curr_x_pos * pixel_to_position_scaling_factor,
            pixel_to_position_offset[1] +
            mover.curr_y_pos * pixel_to_position_scaling_factor,
            pixel_to_position_offset[0] +
            mover.curr_x_pos * pixel_to_position_scaling_factor + 25,
            pixel_to_position_offset[1] +
            mover.curr_y_pos * pixel_to_position_scaling_factor + 25,
            outline=mover.mover_color,
            fill='grey',
            width=2)

        for wedge in mover.wedges:
            if wedge == "red":
                start = 0
            elif wedge == "yellow":
                start = 90
            elif wedge == "green":
                start = 180
            elif wedge == "blue":
                start = 270

            self.canvas.create_arc(
                pixel_to_position_offset[0] +
                mover.curr_x_pos * pixel_to_position_scaling_factor,
                pixel_to_position_offset[1] +
                mover.curr_y_pos * pixel_to_position_scaling_factor,
                pixel_to_position_offset[0] +
                mover.curr_x_pos * pixel_to_position_scaling_factor + 40,
                pixel_to_position_offset[1] +
                mover.curr_y_pos * pixel_to_position_scaling_factor + 40,
                start=start,
                extent=90,
                outline=mover.mover_color,
                fill=wedge,
                width=2)