更新:我已经确定当try函数失败时发生错误,我想如果我修改代码不使用try和box函数返回false,如果它没有工作可能会解决问题
所以我试图弄清楚关闭盒子的胜利概率 http://www.mastersgames.com/rules/shut-box-rules.htm
我已经完成了大部分工作,所以这个功能关闭了#34;插槽"使用尽可能多的策略。但现在我试图通过使用递归来解决每个骰子滚动序列的组合问题。
问题:列表last_current仅在标记为1的点上进行编辑,然后使用标记" LCC"进行打印,但是稍后在使用标记" LC&#34打印时;,在第2点,列表中的第一个元素已被删除。
global Total_Count
Total_Count = 0
Shut_Count = 0
Startlist = ["1","2","3","4","5","6","7","8","9"]
shutting = []
def box(n,current):
if str(n) in current:
current.remove(str(n))
for i in range(len(shutting)):
current.remove(shutting[i])
shutting.pop()
return current
else:
for i in range(n):
if str(n-i) in current:
shutting.append(str(n-i))
return box(i,current)
break
else:
pass
def recurs(Dice_1,Dice_2,current):
global Total_Count
for i in range(Dice_1):
for j in range(Dice_2):
print(i,j,current)
1) last_current = current
print("LCC",last_current)
try:
n = i + j + 2
print(n,current)
new = box(n,current)
current = new
print("Try",current)
except:
2) print("LC",last_current)
current = last_current
Total_Count += 1
print("Total",Total_Count,"Current",current)
else:
#print(current)
if range(len(current)) == 0:
Total_Count += 1
Shut_Count += 1
print("Total",Total_Count,"Shut",Shut_Count)
else:
recurs(Dice_1,Dice_2,current)
recurs(6,6,Startlist)
print(Total_Count,Shut_Count)
忽略可怕的编码和使用休息时间,我也不希望别人解决问题只是为什么代码破解的解决方案