重複の可能性:
最大再帰深度?
私のコードには別の問題があります。私は Vpython で最初のプログラムを書いており、2 つのガスを混合するシミュレーションを作成する必要があります。最初は境界線に問題がありましたが、ボール (ガス粒子を表す) が境界線内にとどまると、別の問題が発生します。数秒後、関数のソース コードの下に表示されるエラーが表示されます。
コード:
def MovingTheBall(listOfBalls,position,numCell,flagOfExecution):
flag = 0
if flagOfExecution==0:
positionTmp = position
else:
positionTmp = (position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0)
for i in range( 0, len(listOfBalls) ):
if positionTmp==listOfBalls[i].pos:
flag=1
if flag==1:
return MovingTheBall(lista,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
else:
if positionTmp[0]==0 or positionTmp[0]>=numCell or positionTmp[0]<=-numCell or positionTmp[1]>=numCell or positionTmp[1]<=-numCell:
return MovingTheBall(lista,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
return positionTmp
エラーは次のとおりです。
return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
File "gaz.txt", line 138, in MovingTheBall
return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
File "gaz.txt", line 138, in MovingTheBall
return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
File "gaz.txt", line 138, in MovingTheBall
return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
File "gaz.txt", line 138, in MovingTheBall
return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
File "gaz.txt", line 138, in MovingTheBall
return MovingTheBall(listOfBalls,(position[0]+choice([-1,0,1]),position[1]+choice([-1,0,1]),0),numCell,1)
File "gaz.txt", line 130, in MovingTheBall
if positionTmp==listOfBalls[i].pos:
RuntimeError: maximum recursion depth exceeded while calling a Python object
私の機能を単純化する方法を考えられる人はいますか?
ループしながら関数を実行します。
while 1:
rate(20)
for i in range(0,len(self.listOfBalls)):
self.listOfBalls[i].pos=poruszanie(self.listOfBalls,self.listOfBalls[i].pos,self.numCell,0)