示例#1
0
 def finish_game(self, *args):
     # calculate winners, rewards etc.
     game = Game(players=self.playerlist,
                 game_state=self.current_game_state)
     game_mode = self.current_game_state['game_mode']
     if game_mode[0] != NO_GAME:
         game_mode_str = GAME_MODE_TEXTS[game_mode]
         final_score = game.score_offensive_players()
         rewards = game.get_payouts()
         winners = game.determine_winners()
         # display results on result screen
         result_screen = self.manager.get_screen('result_screen')
         if final_score > 60:
             result_screen.ids[
                 'winners'].text = '{} gewonnen von {} mit {} Punkten'.format(
                     game_mode_str, winners, final_score)
         else:
             result_screen.ids[
                 'winners'].text = '{} gewonnen von {} mit {} Punkten'.format(
                     game_mode_str, winners, final_score)
         result_screen.ids['rewards'].text = 'Auszahlung : ' + format(
             rewards)
         self.manager.current = 'result_screen'
     else:
         game_mode_str = GAME_MODE_TEXTS[game_mode]
         rewards = game.get_payouts()
         # display results on result screen
         result_screen = self.manager.get_screen('result_screen')
         result_screen.ids['winners'].text = 'Zamgschmissen'
         result_screen.ids['rewards'].text = 'Auszahlung : ' + format(
             rewards)
         self.manager.current = 'result_screen'
示例#2
0
 def simulation(self, selected_node):
     if self.simulation_player_list is None:
         playerlist = [RandomPlayer(), RandomPlayer(), RandomPlayer(), RandomPlayer()]
         # if bidding isn't over and >= 2 proposals are made, in simulation uct_player should stick with his proposal
         game = Game(players=playerlist, game_state=selected_node.game_state)
         if not game.bidding_game.finished():
             player_pos = self.get_player_position(selected_node.game_state)
             favorite_mode = selected_node.game_state['mode_proposals'][(player_pos - game.leading_player_index) % 4]
             playerlist[player_pos] = DummyPlayer(favorite_mode=favorite_mode)
     else:
         playerlist = self.simulation_player_list
     # in case the game mode is not yet publicly declared (in bidding phase), take a random suit
     sim_game_state = deepcopy(selected_node.game_state)
     game_type = sim_game_state['game_mode'][0]
     game_suit = sim_game_state['game_mode'][1]
     if game_type == PARTNER_MODE and game_suit is None:
         ran_suit = random.choice([BELLS, ACORNS, LEAVES])
         sim_game_state['game_mode'] = (game_type, ran_suit)
     # if game_type is not known yet, but at least two proposals are made:
     elif game_type > PARTNER_MODE and len(sim_game_state['mode_proposals']) <= 4 \
             and sim_game_state['declaring_player'] != sim_game_state['current_player_index']:
         sim_game_state['game_mode'] = random.choice([(WENZ, None), (SOLO, ACORNS), (SOLO, HEARTS),
                                                      (SOLO, BELLS), (SOLO, LEAVES)])
     game_simulation = Game(players=playerlist, game_state=deepcopy(sim_game_state))
     game_simulation.play()
     rewards = game_simulation.get_payouts()
     return rewards
def play_standardized_tournament(playerlist):
    total_rewards = [0, 0, 0, 0]

    with open('game_states_before_bidding.p', 'rb') as f:

        for game_num in range(1, 101):
            print('-------  Starting game {}  ------'.format(game_num))
            gamestate = pickle.load(f)

            # play each game four times, in a way that each player had every hand once
            for i in range(4):
                print('Round ', i)
                permuted_playerlist = playerlist[i:4] + playerlist[:i]
                game = Game(players=permuted_playerlist, game_state=gamestate)
                game.play()
                payouts = game.get_payouts()
                print('Game mode : ', game.bidding_game.game_mode)
                print('Offensive players : ',
                      [(pl - i) % 4
                       for pl in game.bidding_game.offensive_players])
                print('Payouts : ', [payouts[(pl - i) % 4] for pl in range(4)])
                for j in range(4):
                    total_rewards[j] += payouts[(j - i) % 4]

        print('\n Final Results : ', total_rewards)
示例#4
0
def main():

    tournament_game_states = schafkopf.tournaments.game_states_trick_play.sample_game_states[:
                                                                                             40]
    total_scores = [0, 0, 0, 0]

    for num in range(len(tournament_game_states)):
        start_time = time.time()
        game_state = tournament_game_states[num]
        game = Game(game_state=game_state, players=playerlist)
        game.play()
        rewards = game.get_payouts()
        for i in range(4):
            total_scores[i] += rewards[i]
        end_time = time.time()
        print("Game {} took {} seconds".format(num + 1, end_time - start_time))
        print("Rewards : ", rewards)

    print("Final scores : ", total_scores)