马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
规则:有三扇门,每扇门一开始都是关着的,门后有着随机数量的金币,点击一次后,对应的门会打开,开门时不会获得金币,若继续点击该门则获得对应门后的金币,每隔3轮,未被点击的门会关闭,并且门后的金币数重新随机产生,每个人有100次点击的机会,金币数量最多的人获胜.
门:
1.有开关两种状态,且关闭时不能获取金币,起始状态为关
2.门后的金币数在(1.50)之间随机产生
3.每隔3轮,未被点击的门要进行重置
人:
1.具有金币数量起始为0
2.具有一百次机会
import random as r
class Door:
def __init__(self, state=False):#初始化门的状态
self.state = state
self.gold_coin = r.randint(1, 50)
self.num = 3
def count(self):#保证被选中的门不会被刷新
if not self.state:
self.state = True
print(self.gold_coin)
elif self.state:
print(self.gold_coin)
self.num += 1
def refresh(self):#三轮未被选中的门刷新
if self.num == 0:
self.num = 3
self.gold_coin = r.randint(1, 50)
self.state = False
else:
self.num -= 1
class Human:
def __init__(self):#初始化人的状态
self.max = 0
self.click = 100
self.goldcoinsum = 0
def strategy(chioce=1):
a = Door()
b = Door()
c = Door()
h = Human()
whichdoor = ""
otherdoors = []
if chioce == 1:
a.count()
b.count()
c.count()
a.refresh()
b.refresh()
c.refresh()
h.click -= 3
h.max = max(a.gold_coin, b.gold_coin, c.gold_coin)#选最大的金币数的门
if a.gold_coin > b.gold_coin and a.gold_coin > c.gold_coin:#判断哪个门金币数最大
whichdoor = a
otherdoors = [b, c]
elif b.gold_coin < a.gold_coin < c.gold_coin:
whichdoor = c
otherdoors = [b, a]
else:
whichdoor = b
otherdoors = [a, c]
while h.click > 0:#策略的循环
h.goldcoinsum += h.max
h.click -= 1
whichdoor.count()
whichdoor.refresh()
otherdoors[0].refresh()
otherdoors[1].refresh()
print("您最终的金币总数为%d" % h.goldcoinsum)
strategy()
写的有点烂,大佬轻喷 |