注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
各位注意理解discount。不是真的7折,5折。 而是每个discount可以抵扣一张对应颜色的token! 比如买了2张蓝色的卡,以后每次购买都可以重复抵扣2张蓝色token!
"""
https://images-na.ssl-images-ama ... 0v8qNysKL.SX522.jpg
+-----+
Point value --> |2 G| <-- Card Color
| |
Cost --> |5B |
|3G |
+-----+
Notation: Red - R, Blue - B, Black - K, Green - G, White - W
Player:
the amount of tokens
card_list
Card:
point
cost[(token_type, amount)]
color
can_purchase(Player, Card): boolean
make_purchase(Player, Card): void
Q:
1. discount? free discount.
2. If I buy a blue card with 0 point, get a discount.
GoldTokens:
1.Card won't need gold tokens.
2.Use A
edge case:
1.Valid
"""
from collections import defaultdict
class Player:
def __init__(self, token_dic):
#dic['R'] = amount
self.token_dic = token_dic
self.card_list = []
self.discount_dic = defaultdict(int)
class Card:
def __init__(self, point, cost_token_dic, color):
self.point = point
self.cost_token_dic = cost_token_dic
self.color = color
def can_purchase(player, card):
#Iterate every token that the card needs
gold_token_remain = player.token_dic['A']
for token, amount in card.cost_token_dic.items():
if player.token_dic[token] + player.discount_dic[token] + gold_token_remain < amount:
return False
if player.token_dic[token] + player.discount_dic[token] < amount:
gold_token_remain -= (amount - player.token_dic[token] - player.discount_dic[token])
retur您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 使用VIP即刻解锁阅读权限或查看其他获取积分的方式 游客,您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 VIP即刻解锁阅读权限 或 查看其他获取积分的方式 ot;
print(can_purchase(player, card))
make_purchase(player, card)
print(player.token_dic, player.card_list)
print(can_purchase(player, card))
cost_token_dic2 = {'R':2}
card2 = Card(0, cost_token_dic2, 'G')
print(can_purchase(player, card))
cost_token_dic3 = {'B':2}
card3 = Card(0, cost_token_dic3, 'G')
print(can_purchase(player, card))
cost_token_dic4 = {'G':2}
card4 = Card(0, cost_token_dic4, 'G')
print(can_purchase(player, card))
# discount_dic['G'] = 3
# discount_dic['B'] = 1
""" |