예제 #1
0
 def prepare_bidding(self):
     # Randomly pick a starting player, whom also is the current bid winner
     self.current_player = random.randint(1, NUM_OF_PLAYERS) - 1
     print("Starting Player: {0:d}".format(self.current_player))
     self.passes = 0
     self.table_status["bid"] = 11  # Lowest Bid: 1 Club by default
     self.first_player = True  # Starting bidder "privilege" to raise the starting bid
     msg = "Current Bid: {0:d} {1:s}".format(
         self.table_status["bid"] // 10,
         cards.get_suit_string(self.table_status["bid"] % 10))
     self.write_message(msg, line=1, delay_time=0)
     self.display_current_player(self.current_player)
     msg = 'Bid Leader: Player {0:d}'.format(
         (self.current_player - self.passes - 1 *
          (not self.first_player)) % 4)
     self.write_message(msg, line=2, delay_time=1)
예제 #2
0
    def prepare_bidding(self):
        # Randomly pick a starting player, whom also is the current bid winner
        self.current_player = random.randint(1, NUM_OF_PLAYERS) - 1
        print("Starting Player: {0:d}".format(self.current_player))
        self.passes = 0
        self.table_status["bid"] = 11  # Lowest Bid: 1 Club by default
        self.first_player = True  # Starting bidder "privilege" to raise the starting bid
        msg = "Current Bid: {0:d} {1:s}".format(
            self.table_status["bid"] // 10,
            cards.get_suit_string(self.table_status["bid"] % 10))
        self.write_message(msg, line=1, delay_time=0)
        self.display_current_player(self.current_player)
        self.update_player_bid(self.current_player, 11, update_now=False)
        msg = 'Bid Leader: Player {0:d}'.format(
            (self.current_player - self.passes - 1 *
             (not self.first_player)) % NUM_OF_PLAYERS)
        self.write_message(msg, line=2, delay_time=0.5)

        if not self.terminal_play:
            self.calling_panel.cancel_button.visible = True
            self.calling_panel.change_lists_elements(
                [str(i + 1) for i in range(7)],
                ['Clubs', 'Diamonds', 'Hearts', 'Spades', 'No Trump'])
예제 #3
0
 def update_player_bid(self, player_num, bid, update_now=True):
     """
     Update the display of the player's last bid.
     :param player_num:
     :param update_now:
     :param clear:
     :return:
     """
     self.player_stats[player_num][2].fill(
         (255, 255, 255, 255 * VIEW_TRANSPARENT))
     if not bid:
         rendered_text = self.player_font.render(
             "Pass".format(self.players[player_num].score), True,
             (255, 255, 255)).convert_alpha()
     else:
         bid_text = str(bid // 10) + ' ' + cards.get_suit_string(bid % 10)
         rendered_text = self.player_font.render(
             bid_text.format(self.players[player_num].score), True,
             (255, 255, 255)).convert_alpha()
     self.center_text_on_surface(self.player_stats[player_num][2],
                                 rendered_text,
                                 (255, 255, 255, 255 * VIEW_TRANSPARENT))
     if update_now:
         self.update_table.emit()
예제 #4
0
    def start_bidding(self, game_events):
        """
        The bidding procedure. Flag up if player input required
        :return: Whether bidding is completed
        """
        # Highest bid: 7 NoTrump. No further check required
        if self.passes < NUM_OF_PLAYERS - 1 and self.table_status["bid"] < 75:
            if not self.require_player_input:
                if not self.players[self.current_player].AI:
                    self.require_player_input = True
                    if not self.terminal_play:
                        self.calling_panel.visible = True
                        self.update_table.emit()
                    return False
                else:
                    player_bid = self.players[
                        self.current_player].make_decision(self.game_state, 0)
            else:
                player_bid, msg = self.players[
                    self.current_player].make_decision(self.game_state, 0,
                                                       game_events)
                if msg:
                    self.write_message(msg, delay_time=1, update_now=True)
                if player_bid < 0:
                    return False
                self.require_player_input = False
                self.write_message("", delay_time=0, update_now=False)
                if not self.terminal_play:
                    self.calling_panel.visible = False
                    self.update_table.emit()
            if not player_bid:
                if not self.first_player:  # Starting bidder pass do not count at the start
                    self.passes += 1
            else:
                self.table_status["bid"] = player_bid
                self.passes = 0
                msg = "Current Bid: {0:d} {1:s}".format(
                    self.table_status["bid"] // 10,
                    cards.get_suit_string(self.table_status["bid"] % 10))
                self.write_message(msg, line=1, update_now=False)
                msg = 'Bid Leader: Player {0:d}'.format(self.current_player)
                self.write_message(msg, line=2, update_now=True)

            if self.first_player:
                self.first_player = False
                if player_bid:
                    self.update_player_bid(self.current_player,
                                           player_bid,
                                           update_now=False)
            else:
                self.update_player_bid(self.current_player,
                                       player_bid,
                                       update_now=False)

            if self.table_status["bid"] < 75:
                self.current_player += 1
                self.current_player %= NUM_OF_PLAYERS
            self.display_current_player(self.current_player)

            time.sleep(0.5)
            if self.passes == NUM_OF_PLAYERS - 1 or self.table_status[
                    "bid"] == 75:
                if not self.terminal_play:
                    self.calling_panel.cancel_button.visible = False
                    self.calling_panel.change_lists_elements([
                        '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q',
                        'K', 'A'
                    ], ['Clubs', 'Diamonds', 'Hearts', 'Spades'])
            return False
        else:
            if not self.require_player_input:
                self.write_message("Player {0:d} is the bid winner!".format(
                    self.current_player),
                                   delay_time=1)
                msg = "Player {0:d} is calling a partner...".format(
                    self.current_player)
                self.write_message(msg, delay_time=1)
                self.display_current_player(self.current_player)
                if not self.players[self.current_player].AI:
                    self.require_player_input = True
                    if not self.terminal_play:
                        self.calling_panel.visible = True
                        self.update_table.emit()
                    return False
                else:
                    # Ask for the partner card
                    self.table_status["partner"] = self.players[
                        self.current_player].make_decision(self.game_state, 1)
            else:
                partner, msg = self.players[self.current_player].make_decision(
                    self.game_state, 1, game_events)
                if msg:
                    self.write_message(msg, delay_time=0, update_now=True)

                if not partner:
                    return False

                self.table_status["partner"] = partner
                self.require_player_input = False
                if not self.terminal_play:
                    self.calling_panel.visible = False
                    self.update_table.emit()

            # Setup the table status before the play starts
            self.table_status['partner reveal'] = False
            self.table_status["trump suit"] = self.table_status["bid"] % 10
            self.table_status["trump broken"] = False
            self.table_status['played cards'] = [0, 0, 0, 0]
            if self.table_status['trump suit'] == 5:
                self.table_status["leading player"] = self.current_player
            else:
                self.table_status["leading player"] = (self.current_player +
                                                       1) % NUM_OF_PLAYERS
            self.table_status['defender'][
                'target'] = self.table_status["bid"] // 10 + 6
            self.table_status['attacker'][
                'target'] = 14 - self.table_status['defender']['target']

            # Set the roles of the players
            self.players[self.current_player].role = PlayerRole.DECLARER

            self.write_message('Bidding Complete', delay_time=0)
            msg = 'Trump: {1:s}, Partner: {0:s}'.format(
                cards.get_card_string(self.table_status["partner"]),
                cards.get_suit_string(self.table_status['trump suit']))
            self.write_message(msg, line=1, delay_time=1)
            return True
예제 #5
0
    def start_bidding(self):
        """
        The bidding procedure.
        :return: Whether bidding is completed
        """
        # Highest bid: 7 NoTrump. No further check required
        if self.passes < NUM_OF_PLAYERS - 1 and self.table_status["bid"] < 75:
            player_bid = self.players[self.current_player].make_decision(
                self.game_state, 0)
            if not player_bid:
                if not self.first_player:  # Starting bidder pass do not count at the start
                    self.passes += 1
            else:
                self.table_status["bid"] = player_bid
                self.passes = 0

            if self.table_status["bid"] < 75:
                self.current_player += 1
                self.current_player %= 4
            msg = "Current Bid: {0:d} {1:s}".format(
                self.table_status["bid"] // 10,
                cards.get_suit_string(self.table_status["bid"] % 10))
            self.write_message(msg, line=1, update_now=False)
            msg = 'Bid Leader: Player {0:d}'.format(
                (self.current_player - self.passes - 1 *
                 (not self.first_player)) % 4)
            self.write_message(msg, line=2, update_now=False)
            self.display_current_player(self.current_player)
            if self.first_player:
                self.first_player = False
            time.sleep(0.5)
            return False
        else:
            self.write_message("Player {0:d} is the bid winner!".format(
                self.current_player),
                               delay_time=1)
            msg = "Player {0:d} is calling a partner...".format(
                self.current_player)
            self.write_message(msg, delay_time=1)
            self.display_current_player(self.current_player)
            # Ask for the partner card
            self.table_status["partner"] = self.players[
                self.current_player].make_decision(self.game_state, 1)

            # Setup the table status before the play starts
            self.table_status['partner reveal'] = False
            self.table_status["trump suit"] = self.table_status["bid"] % 10
            self.table_status["trump broken"] = False
            self.table_status['played cards'] = [0, 0, 0, 0]
            if self.table_status['trump suit'] == 5:
                self.table_status["leading player"] = self.current_player
            else:
                self.table_status["leading player"] = (self.current_player +
                                                       1) % 4
            self.table_status['defender'][
                'target'] = self.table_status["bid"] // 10 + 6
            self.table_status['attacker'][
                'target'] = 14 - self.table_status['defender']['target']

            # Set the roles of the players
            self.players[self.current_player].role = PlayerRole.DEFENDER

            self.write_message('Bidding Complete', delay_time=0)
            msg = 'Trump: {1:s}, Partner: {0:s}'.format(
                cards.get_card_string(self.table_status["partner"]),
                cards.get_suit_string(self.table_status['trump suit']))
            self.write_message(msg, line=1, delay_time=1)
            return True