如果可能,我想将以下两个子句(彼此完全相反)重构为一个:
if who == 0:
score = take_turn(strategy0(score0, score1), score1, select_dice(score0, score1))
if score == 0:
score1 += strategy0(score0, score1)
else:
score0 += score
elif who == 1:
score = take_turn(strategy1(score1, score0), score0, select_dice(score1, score0))
if score == 0:
score0 += strategy1(score1, score0)
else:
score1 += score
我怎样才能做到以下几点
def other(who)
return 1 - who
score = take_turn(strategy+who(score+who, score+other), score+other, select_dice(score+who, score+other))
if score == 0:
score+other += strategy+who(score+who, score+other)
else:
score+who += score
您的代码很复杂,因为您分散了相关的数据
因此,您所要做的就是收集数据并将其作为参数传递
这里有一些可能的场景,我将使用字典来编写以下代码
我认为类实现更好,你应该试试
相关问题 更多 >
编程相关推荐