Example #1
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
Example #2
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
Example #3
0
def main():
    num_examples = 0
    num_poss = 0
    for i in range(10):
        for state in sample_game_states:
            playerlist = [
                RandomPlayer(),
                RandomPlayer(),
                RandomPlayer(),
                RandomPlayer()
            ]
            game = Game(players=playerlist, game_state=state)

            while not game.finished():
                if len(game.trick_game.tricks) < 7:

                    if game.trick_game.current_trick.num_cards != 0:
                        current_player = game.trick_game.get_current_player()
                        options = game.trick_game.possible_cards(
                            game.trick_game.current_trick,
                            current_player.get_hand())
                        num_poss += len(options)
                        num_examples += 1

                game.trick_game.play_next_card()
                game.trick_game.trick_finished()

    print('Average number of legal cards to play after {} situations is : {}'.
          format(num_examples, num_poss / num_examples))
Example #4
0
from schafkopf.players import RandomPlayer
from schafkopf.players.isuct_player import ISUCTPlayer
from schafkopf.ranks import *
from schafkopf.suits import *
from schafkopf.game_modes import *
import time
from schafkopf.game import Game

playerlist = [
    ISUCTPlayer(name="A",
                num_simulations=100,
                simulation_player_list=None,
                ucb_const=2),
    RandomPlayer(name="B"),
    RandomPlayer(name="C"),
    RandomPlayer(name="D")
]

player_hands_partner = [[(OBER, ACORNS), (OBER, BELLS), (UNTER, BELLS),
                         (ACE, BELLS), (KING, LEAVES), (TEN, ACORNS),
                         (SEVEN, ACORNS), (NINE, ACORNS)],
                        [(OBER, LEAVES), (OBER, HEARTS), (UNTER, ACORNS),
                         (ACE, HEARTS), (SEVEN, HEARTS), (ACE, ACORNS),
                         (KING, BELLS), (SEVEN, BELLS)],
                        [(UNTER, LEAVES), (TEN, LEAVES), (KING, HEARTS),
                         (KING, ACORNS), (TEN, HEARTS), (SEVEN, LEAVES),
                         (EIGHT, ACORNS), (NINE, BELLS)],
                        [(UNTER, HEARTS), (ACE, LEAVES), (TEN, BELLS),
                         (EIGHT, HEARTS), (EIGHT, LEAVES), (EIGHT, BELLS),
                         (NINE, HEARTS), (NINE, LEAVES)]]