【发布时间】:2022-08-05 22:24:47
【问题描述】:
这是UCB CS61A的第一个项目猪的问题5
这是错误的代码(我的代码)
while(score0<goal and score1<goal):
if who==0 :
cur_strategy = strategy0
cur_score = score0
cur_op_score=score1
cur_op_strategy = strategy1
else:
cur_strategy = strategy1
cur_score = score1
cur_op_score=score0
cur_op_strategy = strategy0
cur_score=cur_score+take_turn(cur_strategy(cur_score,cur_op_score),cur_op_score,dice)
if(extra_turn(cur_score,cur_op_score)==False):
who=other(who)
这是正确的代码(我已经测试过了)
while score0 < goal and score1 < goal:
if who == 0:
num_rolls = strategy0(score0, score1)
score0 += take_turn(num_rolls, score1, dice)
who = other(who) if extra_turn(score0, score1) == False else who
else:
num_rolls = strategy1(score1, score0)
score1 += take_turn(num_rolls, score0, dice)
who = other(who) if extra_turn(score1, score0) == False else who
但实际上,我认为这两个代码本质上是相同的。
我不知道这是否是问题(来自项目的报价)
每回合只调用一次策略函数(或冒着破坏 GUI 的风险)。
标签: function