Exemple #1
0
    def sample_game_state(self, public_info):
        # sample opponent hands
        if public_info["current_trick"] is None:
            current_trick = Trick(
                leading_player_index=public_info["leading_player_index"])
        else:
            current_trick = public_info["current_trick"]

        player_hands = sample_opponent_hands(
            tricks=public_info["tricks"],
            current_trick=current_trick,
            trumpcards=public_info["trumpcards"],
            playerindex=public_info["current_player_index"],
            player_hand=self.hand)

        # recreate possible mode proposals from public info
        mode_proposals = sample_mode_proposals(public_info)

        # add player_hands and possible actions to game state
        game_state = deepcopy(public_info)
        game_state["mode_proposals"] = mode_proposals
        game_state["player_hands"] = player_hands
        game = Game(game_state=game_state,
                    players=[
                        RandomPlayer(),
                        RandomPlayer(),
                        RandomPlayer(),
                        RandomPlayer()
                    ])
        game_state["possible_actions"] = game.get_possible_actions()

        return game_state
Exemple #2
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()
Exemple #3
0
def main():
    game = Game(game_state=game_state_after_bidding, players=playerlist)
    public_info = game.get_public_info()
    curr_player = game.trick_game.get_current_player()

    start_time = time.time()

    print('Start !')

    actions = curr_player.isuct_search(public_info=public_info)
    end_time = time.time()

    print("possible actions : ", game.get_possible_actions())
    print("Best action", actions)
    print("Simulation took {} seconds".format(end_time - start_time))
Exemple #4
0
 def start_bidding(self):
     curr_pl = self.current_game_state['current_player_index']
     while curr_pl != self.human_player_index:
         self.make_first_opponent_proposal(curr_pl)
         curr_pl = self.current_game_state['current_player_index']
     # set callbacks for legal actions
     game = Game(players=self.playerlist,
                 game_state=self.current_game_state)
     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_first_proposal,
                                            action))
Exemple #5
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()