Пример #1
0
 def _move_princess(self, dealt_card, new_deck):
     """Handle a princess action into a new game state"""
     player = PlayerTools.force_discard(self.player(), dealt_card)
     player = PlayerTools.force_discard(player)
     current_players = Game._set_player(
         self._players, player, self.player_turn())
     return Game(new_deck, current_players, self._turn_index + 1)
Пример #2
0
    def _move_prince(self, current_players, action, deck_new):
        """Handle a prince action into a new game state"""

        player_before_discard = current_players[action.player_target]
        action_updated = action._replace(player=self.player_turn(),
                                         force_discarded=player_before_discard.hand_card,
                                         force_discarder=action.player_target)
        # if there are no more cards, this has no effect
        if len(deck_new) - 1 < 1:
            return Game(deck_new, current_players, self._turn_index + 1,
                        [*self._action_log, action_updated])

        if player_before_discard.hand_card == Card.princess:
            player_post_discard = PlayerTools.force_discard(
                player_before_discard)
            deck_final = deck_new
        else:
            player_post_discard = PlayerTools.force_discard(
                player_before_discard, deck_new[0])
            deck_final = deck_new[1:]

        current_players = Game._set_player(
            current_players, player_post_discard, action.player_target)

        return Game(deck_final, current_players, self._turn_index + 1,
                    [*self._action_log, action_updated])
Пример #3
0
    def _move_baron(self, action, current_players, player_hand_new, deck_new):
        """
        Handle a baron action into a new game state

        Player and target compare hand cards. Player with lower hand
        card is eliminated
        """
        card_target = self._players[action.player_target].hand_card
        if player_hand_new > card_target:
            if not PlayerTools.is_defended(self._players[action.player_target]):
                # target is eliminated
                player_target = PlayerTools.force_discard(
                    self._players[action.player_target])
                current_players = Game._set_player(
                    current_players, player_target, action.player_target)
                action_updated = action._replace(player=self.player_turn(),
                                                 force_discarded=card_target,
                                                 force_discarder=action.player_target)
            else:
                action_updated = action._replace(player=self.player_turn())

        elif player_hand_new == card_target:
            # Tie, nobody wins
            action_updated = action._replace(player=self.player_turn(),
                                             revealed_card=card_target)

        else:
            # player is eliminated
            player = PlayerTools.force_discard(self.player(), player_hand_new)
            player = PlayerTools.force_discard(player)
            current_players = Game._set_player(
                current_players, player, self.player_turn())
            action_updated = action._replace(player=self.player_turn(),
                                             force_discarded=player_hand_new,
                                             force_discarder=action.player)

        return Game(deck_new, current_players, self._turn_index + 1,
                    [*self._action_log, action_updated])
Пример #4
0
    def _move_baron(self, action, current_players, player_hand_new, deck_new):
        """
        Handle a baron action into a new game state

        Player and target compare hand cards. Player with lower hand
        card is eliminated
        """
        card_target = self._players[action.player_target].hand_card
        if player_hand_new > card_target:
            if not PlayerTools.is_defended(self._players[action.player_target]):
                # target is eliminated
                player_target = PlayerTools.force_discard(
                    self._players[action.player_target])
                current_players = Game._set_player(
                    current_players, player_target, action.player_target)
        else:
            # player is eliminated
            player = PlayerTools.force_discard(self.player(), player_hand_new)
            player = PlayerTools.force_discard(player)
            current_players = Game._set_player(
                current_players, player, self.player_turn())

        return Game(deck_new, current_players, self._turn_index + 1)
Пример #5
0
    def _move_guard(self, current_players, action, deck_new):
        """
        Handle a guard action into a new game state

        Player makes a guess to try and eliminate the opponent
        """
        if self._players[action.player_target].hand_card == action.guess and \
                not PlayerTools.is_defended(self._players[action.player_target]):
            # then target player is out
            player_target = PlayerTools.force_discard(
                self._players[action.player_target])
            current_players = Game._set_player(
                current_players, player_target, action.player_target)

        return Game(deck_new, current_players, self._turn_index + 1)