def play_mine(game): """ You may trash a Treasure from your hand. Gain a Treasure to your hand costing up to $3 more than it. """ if not any(c.Type == 'Treasure' for c in game.player_state.hand): return response = game._respond(game.player, 'Mine') hand_treasures = [ c.Name() for c in game.player_state.hand if c.Name() in ('Copper', 'Silver') ] if response not in hand_treasures: return next_treasure = Silver() if response == 'Copper' else Gold() exhausted = game.piles[str(next_treasure)] == 0 if exhausted: return # Trash the current treasure remove_by_name(game.player_state.hand, [response]) # Add next treasure to the hand game.player_state.hand.append(next_treasure)
def test_remove_by_name(self): hand = copy.deepcopy(self.hand) remove_by_name(self.hand, ['Witch']) self.assertListEqual(self.hand, hand) remove_by_name(self.hand, ['Village']) self.assertEqual(self.hand, [self.market, self.village2])
def play_moneylender(game): """ You may trash a Copper from your hand for +$3. """ if not has_card_names(game.player_state.hand, ['Copper']): return # Trash the money lender card remove_by_name(game.player_state.hand, ['Copper']) # Add 3 money game.player_state.used_money -= 3
def play_chapel(game): """ Trash up to 4 cards from your hand. """ cards_to_trash = game._respond(game.player, 'Chapel') if not isinstance(cards_to_trash, List) or len( cards_to_trash) == 0 or len(cards_to_trash) > 4: return if not has_card_names(game.player_state.hand, cards_to_trash): return # trash the selected cards remove_by_name(game.player_state.hand, cards_to_trash)
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()])
def play_cellar(game): """ +1 Action Discard any number of cards, then draw that many. """ game.player_state.actions += 1 cards_to_discard = game._respond(game.player, 'Cellar') if not isinstance(cards_to_discard, List) or len(cards_to_discard) == 0: return if not has_card_names(game.player_state.hand, cards_to_discard): return # discard the selected cards discarded = remove_by_name(game.player_state.hand, cards_to_discard) game.player_state.discard_pile.add_to_top(discarded) # draw new cards game.player_state.draw_cards(len(cards_to_discard))
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)