| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
from pyrobot.brain import Brain
class Avoid(Brain):
def wander(self, minSide):
# if approaching an obstacle to the left side, turn right
if min([s.distance() for s in self.robot.range["front-left"]]) < minSide:
self.move(0,-0.3)
# if approaching an obstacle to the right side, turn left
elif min([s.distance() for s in self.robot.range["front-right"]]) < minSide:
self.move(0,0.3)
else: # go forward
self.move(0.5, 0)
def step(self):
self.wander(1)
def INIT(engine):
return Avoid('Avoid', engine) |