示例#1
0
    def continue_bidding(self, *args):
        curr_pl = self.current_game_state['current_player_index']
        game = Game(players=self.playerlist,
                    game_state=self.current_game_state)

        if curr_pl == self.human_player_index:
            # set callbacks for legal actions
            legal_actions = game.get_possible_actions()
            for action in legal_actions:
                action_id = BIDDING_IDS[action]
                btn = self.ids[action_id]
                self.set_callback(btn=btn,
                                  callback=partial(self.make_second_proposal,
                                                   action))
        else:
            curr_pl = game.get_current_player()
            game.next_action()
            self.current_game_state = game.get_game_state()
            label_id = 'player{}_proposal'.format(curr_pl)
            # update proposal text
            last_proposal = self.current_game_state['mode_proposals'][-1]
            if last_proposal[0] == NO_GAME:
                self.set_proposition_text(label_id, 'Weiter')
            elif last_proposal[0] == PARTNER_MODE:
                self.set_proposition_text(label_id, 'I hätt a Saupiel!')
            elif last_proposal[0] == WENZ:
                self.set_proposition_text(label_id, 'I hätt an Wenz')
            elif last_proposal[0] == SOLO:
                self.set_proposition_text(label_id, 'I hätt a Solo!')

        if game.bidding_game.finished():
            self.prepare_trick_play()
        else:
            self.continue_bidding()
示例#2
0
    def play_next_card(self, *args):
        game = Game(players=self.playerlist,
                    game_state=self.current_game_state)

        if not game.finished():
            curr_pl = game.get_current_player()

            if curr_pl == self.human_player_index:
                # set callbacks for legal actions
                legal_actions = game.get_possible_actions()

                for card in legal_actions:
                    # determine which button corresponds to this card
                    widget_ids = ['card_{}'.format(i) for i in range(1, 9)]
                    for widget_id in widget_ids:
                        btn = self.ids[widget_id]
                        if btn.text == str(card):
                            break
                    assert btn
                    self.set_callback(btn=btn,
                                      callback=partial(self.choose_card, card))
            else:

                # play opponent game, update current game state
                game.next_action()
                self.current_game_state = game.get_game_state()
                # display image

                widget_id = 'player{}_card'.format(curr_pl)

                if game.trick_game.current_trick.num_cards != 0:
                    card = self.current_game_state['current_trick'].cards[
                        curr_pl]
                else:
                    card = self.current_game_state['tricks'][-1].cards[curr_pl]

                file_path = self.get_filepath(card)
                self.add_widget_to_display_by_id(widget_id)
                self.ids[widget_id].source = file_path

                if game.trick_game.current_trick.num_cards == 0:
                    self.finish_trick()
                else:
                    self.play_next_card()

        else:
            self.finish_game()