1. Discounted Card Purchase Functions
Modify the 'can_purchase' and 'purchase' functions to account for discounts a player receives from cards they already own. The discounts come from the number of red, blue, and green gems on the cards in hand. Write test cases to ensure your modified functions work correctly.
2. Function to Execute Card Purchase
Write a function named 'purchase' that allows a player to purchase a card given their collection of gems. If the player can purchase the card, add it to the player's cards; if not, return false. Include test cases to verify the functionality of your function.
3. Function to Check Card Purchase Ability
Write a function named 'can_purchase' that determines if a player can afford a particular card given their collection of gems. The function should return true if the player can afford the card, and false otherwise. Ensure to write test cases to validate your function.