def start_game(self,
                   players: Sequence,
                   target_points: int = 1000) -> object:
        """

        :param players: 
        :param target_points: 
        :return: The Game History
        """
        check_all_isinstance(players, TichuPlayer)
        self._players = players

        game_history = list(
        )  # list of alternating gamestates and actions   # TODO make class

        for k, player in enumerate(players):
            player.reset()
            player.id = k

        game_state = self._get_init_game_state(players)
        game_history.append(game_state)
        while not game_state.is_terminal():
            round_history = self._start_round(current_gamestate=game_state)
            game_history.extend(round_history)

        return game_history
 def __init__(self, team1, team2, winner_team, points, target_points,
              rounds):
     check_isinstance(team1, Team)
     check_isinstance(team2, Team)
     check_isinstance(winner_team, Team)
     check_isinstance(points, tuple)
     check_param(len(points) == 2)
     check_isinstance(target_points, int)
     check_all_isinstance(rounds, RoundHistory)
     check_param(len(rounds) > 0)
     super().__init__()
    def __init__(self, pairs):
        check_param(len(pairs) >= 2)
        check_all_isinstance(pairs, Pair)

        pairheights = {p.height for p in pairs}
        check_param(
            len(pairheights) == len(pairs))  # all pairs have different height
        check_param(max(pairheights) - min(pairheights) +
                    1 == len(pairs))  # pairs are consecutive

        cards = set(itertools.chain(*[p.cards for p in pairs]))
        check_param(
            len(cards) == 2 * len(pairs), param=pairs
        )  # no duplicated card (takes care of multiple phoenix use)
        super().__init__(cards)
        self._height = max(pairheights)
        self._lowest_pair_height = min(pairheights)
        self._pairs = pairs
    def __init__(self, initial_points, final_points, points, grand_tichu_hands,
                 before_swap_hands, card_swaps, complete_hands,
                 announced_grand_tichus, announced_tichus, tricks, handcards,
                 ranking, events):
        check_isinstance(initial_points, tuple)
        check_isinstance(final_points, tuple)
        check_isinstance(points, tuple)
        check_param(
            len(initial_points) == len(final_points) == len(points) == 2)

        check_all_isinstance(
            [grand_tichu_hands, before_swap_hands, complete_hands],
            HandCardSnapshot)

        if card_swaps != frozenset():
            check_isinstance(card_swaps, frozenset)
            check_all_isinstance(card_swaps, SwapCardAction)
            check_param(len(card_swaps) == 12, param=card_swaps)
            check_param(len({sca.player_pos for sca in card_swaps}) == 4)
            check_param(len({sca.to for sca in card_swaps}) == 4)

        check_isinstance(announced_grand_tichus, frozenset)
        check_isinstance(announced_tichus, frozenset)

        check_all_isinstance(tricks, Trick)

        check_all_isinstance(handcards, HandCardSnapshot)
        check_param(len(tricks) == len(handcards))

        check_isinstance(ranking, tuple)
        check_param(len(ranking) <= 4)

        check_isinstance(events, tuple)
        check_all_isinstance(events, GameEvent)

        super().__init__()
Esempio n. 5
0
    def __init__(self, parent, state=None, initial_reward_ratio=float("inf")):
        """

        :param parent: MonteCarloTreeNode; The parent node of this None
        :param state: MctsState of this none
        :param initial_reward_ratio: The initial reward ratio (when the node was not yet visited)
        """
        check_isinstance(state, MctsState)
        parent is None or check_isinstance(parent, MonteCarloTreeNode)
        super().__init__(parent=parent, data=state)

        self._visited_count = 0
        self._reward_count = 0
        self._reward_ratio = self._reward_count / self._visited_count if self._visited_count != 0 else initial_reward_ratio

        self._possible_actions = set(state.possible_actions())
        assert check_all_isinstance(self._possible_actions, PlayerAction)
        self._expanded_actions = set()
        self._remaining_actions = list(self._possible_actions)
 def points(self, points):
     check_isinstance(points, tuple)
     check_param(len(points) == 2)
     check_all_isinstance(points, int)
     self._points = points
 def __init__(self, cards):
     check_param(len(cards) > 0, cards)
     check_all_isinstance(cards, Card)
     self._cards = ImmutableCards(cards)
     check_true(len(self._cards) == len(cards))
 def __init__(self, handcards0, handcards1, handcards2, handcards3):
     check_all_isinstance([handcards0, handcards1, handcards2, handcards3],
                          ImmutableCards)
     super().__init__()