2017-06-11 4 views
0

pythonでrhinoのステップ関数を作成しようとしています。 この関数は、逆方向に移動することなく、ランダムな方向にステップを進めることになっています。 どのようにステップバックを防ぐのですか?Pythonでrhinoのステップバックを防ぐ

import rhinoscriptsyntax as rs 
import random as r 
r.seed(seed) 



class Walker: 

def __init__(self): 
    self.x = 0 
    self.y = 0 


def point(self): 
    shape = rs.AddPoint(self.x, self.y, 0) 
    return shape 

def step(self): 
    choice = r.randint(0,3) 
     choice = r.randint(1,3) 
    if (choice == 0): 
     self.x = self.x + r.choice(uList) 
    elif (choice == 1): 
     self.x = self.x - r.choice(uList) 
    elif (choice == 2): 
     self.y = self.y + r.choice(uList) 
    else: 
     self.y = self.y - r.choice(uList) 

uList = [8,11,14] 

w = Walker() 


pList = [] 
for t in range(time): 
w.step() 
pList.append(w.point()) 

for t-1 in range(time): 

a = pList 
+0

あなたは何を後方に呼びますか? 'x '方向?もしそうなら、 'self.x'に(正の)数字を追加するだけです。 –

答えて

0

この行:

choice = r.randint(0,3) 

がランダムに4つの方向のいずれかを選択します。しかし、あなたが後ろに行くことを望まないなら、あなたは前方、左、右だけを望んでいます。パラメータをrandint()に変更して、3つの可能な数値から選択し、の逆方向のいずれかの方向に対応するものを避けます。

関連する問題