def subtract_tokens(tokens_a, tokens_b): ''' Compute tokens_a - token_b ie for all color in colors, tokens_a[color] - tokens_b[color] ''' result = game.get_empty_token_bag() for color in result: result[color] = tokens_a[color] - tokens_b[color] return result
def compute_discounted_price(self, card): ''' If you hold bonuses, you have a discount on dvpt cards. This function computes and returns such discounted price ''' discounted_price = game.get_empty_token_bag() for color, price in card.price.items(): discounted_price[color] = positive_part(price - self.bonuses[color]) return discounted_price discounted_price = subtract_tokens(card.price, self.bonuses) for color, price in discounted_price.items(): # Forbid negative prices if price < 0: discounted_price[color] = 0 return discounted_price