Пример #1
0
def play_throne_room(game):
    """
    You may play an Action card from your hand twice.
    """
    ps = game.player_state
    if 'Action' not in set(c.Type for c in ps.hand):
        print('ThroneRoom: No actions cards in hand')
        return

    card_name = game._respond(game.player, 'ThroneRoom')
    card_class = get_card_class(card_name)
    if card_class.Type != 'Action':
        print(f'ThroneRoom: {card_class.Name()} is not an action card')
        return

    # Play the requested action action card for the first time
    ps.actions += 1
    result = game.play_action_card(card_name)
    if result:
        # Return the action card from the play area to the hand and play it again
        card = ps.play_area.pop()
        ps.actions += 1
        if card.Name() != card_name:
            raise RuntimeError('Something went wrong during throne room!')
        ps.hand.append(card)
        game.play_action_card(card_name)
Пример #2
0
 def _verify_action(self, card_name):
     """verify that the player's card is an action, has the card in their hand, and has at least one action
     return True if the player can play the card, otherwise return False
     """
     card = get_card_class(card_name)
     is_action_card = card.Type == 'Action'
     is_card_in_hand = card.Name() in [card.Name() for card in self.player_state.hand]
     has_actions = self.player_state.actions > 0
     return is_action_card and is_card_in_hand and has_actions
Пример #3
0
    def buy_card(self, money, card_name, condition=lambda: True):
        card_class = get_card_class(card_name)
        can_buy = money >= card_class.Cost and \
                  self.state.supply.get(card_name, 0) > 0 and \
                  condition()
        if can_buy:
            ok = self.game_client.buy(card_name)
            return ok

        return False
Пример #4
0
def play_remodel(game):
    """
    Trash a card from your hand.
    Gain a card costing up to $2 more than it.
    """
    trash, gain = game._respond(game.player, 'Remodel')
    if not has_card_names(game.player_state.hand, [trash]):
        return

    if game.piles.get(gain, 0) == 0:
        return

    trash_card_class = get_card_class(trash)
    gain_card_class = get_card_class(gain)

    if trash_card_class.Cost < gain_card_class.Cost - 2:
        return

    remove_by_name(game.player_state.hand, [trash])
    game.piles[gain] -= 1
    game.player_state.discard_pile.add_to_top([gain_card_class()])
Пример #5
0
def play_workshop(game):
    """
    Gain a card costing up to $4
    """
    card_name = game._respond(game.player, 'Workshop')
    card_class = get_card_class(card_name)
    if game.piles.get(card_name, 0) == 0 or card_class.Cost > 4:
        return

    game.piles[card_name] -= 1

    game.player_state.discard_pile.add_to_top([card_class()])
    game.send_game_event(f'{game.player_name} gained {card_name}')
Пример #6
0
    def _verify_buy(self, card_name):
        """verify the supply if not exhausted, player has enough money and has at least one buy"""
        card_class = get_card_class(card_name)
        if self.player_state.buys < 1:
            return False

        if self._is_pile_empty(card_name):
            return False
        cm = card_util.count_money
        amount = cm(self.player_state.hand) + cm(self.player_state.play_area, False) - self.player_state.used_money
        if amount < card_class.Cost:
            return False

        self.player_state.used_money += card_class.Cost
        return True
Пример #7
0
    def buy(self, card_name):
        """ """
        if self.waiting_for_response:
            return

        if not self._verify_buy(card_name):
            return False

        card_class = get_card_class(card_name)

        self.piles[card_name] -= 1
        self.player_state.discard_pile.add_to_top([card_class()])
        self.player_state.buys -= 1
        self.send_game_event(f'{self.player_name} bought {card_name}')
        self.send_personal_state()

        return True
Пример #8
0
def play_artisan(game):
    """
    Gain a card to your hand costing up to $5.
    Put a card from your hand onto your deck.
    """
    gain, put_onto_deck = game._respond(game.player, 'Artisan')
    if game.piles.get(gain, 0) == 0:
        return

    card_class = get_card_class(gain)
    if card_class is None or card_class.Cost > 5:
        return

    if put_onto_deck not in [gain
                             ] + [c.Name() for c in game.player_state.hand]:
        return

    game.piles[gain] -= 1
    new_card = card_class()
    game.player_state.hand.append(new_card)

    put_onto_deck = remove_by_name(game.player_state.hand, [put_onto_deck])
    game.player_state.draw_deck.add_to_top(put_onto_deck)
Пример #9
0
def play_bureaucrat(game):
    """
        Gain a silver card; put it on top of your deck.
        Each other player reveals a Victory card from
        his hand and puts it on top of his deck (or reveals
        a hand with no Victory cards).
    """
    def choose_victory(response):
        if response is None or response.Type != 'Victory':
            for c in player_state.hand:
                if c.Type == 'Victory':
                    return c
            return None

        for c in player_state.hand:
            if isinstance(c, type(response)):
                return c
        return None

    if not game._is_pile_empty('Silver'):
        game.piles['Silver'] -= 1
        game.player_state.draw_deck.add_to_top([Silver()])
    for player, player_state in game.other_players:
        victory_cards = [c for c in player_state.hand if c.Type == 'Victory']
        if not victory_cards:
            continue

        if len(victory_cards) == 1:
            victory = choose_victory(victory_cards[0])
        else:
            response = game._respond(player, 'Bureaucrat')
            victory = None if response is None else choose_victory(
                get_card_class(response)())

        if victory is not None:
            player_state.draw_deck.add_to_top([victory])
            player_state.hand.remove(victory)