Пример #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 choose_card(self, card, *args):
        # update current game state
        self.playerlist[self.human_player_index].favorite_cards = [card]
        game = Game(players=self.playerlist,
                    game_state=self.current_game_state)
        game.next_action()
        self.current_game_state = game.get_game_state()

        # display image
        widget_id = 'player{}_card'.format(self.human_player_index)
        file_path = self.get_filepath(card)
        self.add_widget_to_display_by_id(widget_id)
        self.ids[widget_id].source = file_path

        # remove all callbacks
        for btn in self.ids['player_hand'].children:
            self.clear_callbacks(btn)

        # remove played card widget
        self.remove_card_from_display(card)

        if game.trick_game.current_trick.num_cards == 0:
            self.finish_trick()
        else:
            self.play_next_card()
Пример #3
0
 def get_new_state(self, game_state, action):
     playerlist = [DummyPlayer(favorite_mode=action, favorite_cards=[action]),
                   DummyPlayer(favorite_mode=action, favorite_cards=[action]),
                   DummyPlayer(favorite_mode=action, favorite_cards=[action]),
                   DummyPlayer(favorite_mode=action, favorite_cards=[action])]
     game = Game(game_state=deepcopy(game_state), players=playerlist)
     game.next_action()
     return game.get_game_state()
Пример #4
0
def example_public_info():
    game_state = sample_game_states[0]
    players = [
        DummyPlayer(favorite_cards=[(OBER, HEARTS), (TEN, BELLS)]),
        DummyPlayer(favorite_cards=[(OBER, ACORNS), (KING, BELLS)]),
        DummyPlayer(favorite_cards=[(SEVEN, HEARTS), (ACE, BELLS)]),
        DummyPlayer(favorite_cards=[(ACE, HEARTS), (EIGHT, BELLS)])
    ]
    game = Game(players=players, game_state=game_state)
    for _ in range(8):
        game.next_action()
    return game.get_public_info()
Пример #5
0
 def make_first_opponent_proposal(self, curr_pl, *args):
     # play one action
     game = Game(players=self.playerlist,
                 game_state=self.current_game_state)
     game.next_action()
     self.current_game_state = game.get_game_state()
     # set proposal text in screen
     last_proposal = self.current_game_state['mode_proposals'][-1]
     label_id = 'player{}_proposal'.format(curr_pl)
     if last_proposal[0] == NO_GAME:
         self.set_proposition_text(label_id, 'Weiter')
     else:
         self.set_proposition_text(label_id, 'I dad spuin!')
Пример #6
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()
Пример #7
0
 def make_first_proposal(self, proposal, *args):
     self.playerlist[self.human_player_index].favorite_mode = proposal
     # update game_state
     game = Game(players=self.playerlist,
                 game_state=self.current_game_state)
     game.next_action()
     self.current_game_state = game.get_game_state()
     # update screen
     label_id = 'player{}_proposal'.format(self.human_player_index)
     if proposal[0] == NO_GAME:
         self.set_proposition_text(label_id, 'Weiter')
     else:
         self.set_proposition_text(label_id, 'I dad spuin!')
     # remove bindings
     for btn in self.ids['mode_buttons'].children:
         self.clear_callbacks(btn)
     self.finish_first_proposals()
Пример #8
0
    def make_second_proposal(self, proposal, *args):
        self.playerlist[self.human_player_index].favorite_mode = proposal
        # update game_state
        game = Game(players=self.playerlist,
                    game_state=self.current_game_state)
        game.next_action()
        self.current_game_state = game.get_game_state()
        # update screen
        label_id = 'player{}_proposal'.format(self.human_player_index)
        if proposal[0] == NO_GAME:
            self.set_proposition_text(label_id, 'Weiter')
        elif proposal[0] == PARTNER_MODE:
            self.set_proposition_text(label_id, 'I hätt a Sauspiel!')
        elif proposal[0] == WENZ:
            self.set_proposition_text(label_id, 'I hätt an Wenz!')
        elif proposal[0] == SOLO:
            self.set_proposition_text(label_id, 'I hätt a Solo!')
        # remove bindings
        for btn in self.ids['mode_buttons'].children:
            self.clear_callbacks(btn)

        self.continue_bidding()