本文整理汇总了Python中app.App.next_step方法的典型用法代码示例。如果您正苦于以下问题:Python App.next_step方法的具体用法?Python App.next_step怎么用?Python App.next_step使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.App
的用法示例。
在下文中一共展示了App.next_step方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from app import App [as 别名]
# 或者: from app.App import next_step [as 别名]
class BOT:
def __init__(self, grid, source, destination, current_direction):
self.direction = current_direction
self.GRID = grid
self.current_position = source
self.destination = destination
self.app = App(grid, source, destination)
def main(self):
#app = App(self.GRID)
#self.printGrid(GRID_SIZE)
while(self.current_position != self.destination):
next_x,next_y = self.app.next_step(self.current_position[0],self.current_position[1])
if(self.is_safe(next_x,next_y)):
print "Next x = %d, Next y = %d is safe" %(next_x,next_y)
self.move_straight(next_x,next_y)
else:
print "Encountered obstacle at Next x = %d, Next y = %d" %(next_x,next_y)
self.app.mark_obstacle(next_x,next_y)
#self.app.update_grid(self.current_position[0],self.current_position[1])
#import ipdb; ipdb.set_trace()
def printGrid(self,n):
for i in range(n):
for j in range(n):
print self.GRID[i][j],
print
print self.current_position
print self.destination
def is_safe(self,next_x,next_y):
print "current direction %s" %self.direction
if(self.current_position[0] < next_x):
self.turn_north()
elif(self.current_position[0] > next_x):
self.turn_south()
elif(self.current_position[1] < next_y):
self.turn_west()
else:
self.turn_east()
if(next_x == 2 and next_y == 1):
return False
if(self.GRID[next_x][next_y] == "obstacle"):
return False
else:
return True
def turn_south(self):
print "Moving south now"
if(self.direction == "north"):
self.turn_180_deg()
elif(self.direction == "east"):
self.turn_90_deg_clock_wise()
elif(self.direction == "west"):
self.turn_90_deg_anti_clock_wise()
else:
pass
self.direction = "south"
def turn_north(self):
print "Moving north now"
if(self.direction == "south"):
self.turn_180_deg()
elif(self.direction == "west"):
self.turn_90_deg_clock_wise()
elif(self.direction == "east"):
self.turn_90_deg_anti_clock_wise()
else:
pass
self.direction = "north"
def turn_east(self):
print "Moving east now"
if(self.direction == "west"):
self.turn_180_deg()
elif(self.direction == "south"):
self.turn_90_deg_anti_clock_wise()
elif(self.direction == "north"):
self.turn_90_deg_clock_wise()
else:
pass
self.direction = "east"
def turn_west(self):
print "Moving west now"
if(self.direction == "east"):
self.turn_180_deg()
elif(self.direction == "north"):
self.turn_90_deg_anti_clock_wise()
elif(self.direction == "south"):
self.turn_90_deg_clock_wise()
else:
pass
self.direction = "west"
def turn_180_deg(self):
print "Turning 180 degree"
self.turn_90_deg_clock_wise()
self.turn_90_deg_clock_wise()
#.........这里部分代码省略.........