本文整理汇总了Python中app.App.moved方法的典型用法代码示例。如果您正苦于以下问题:Python App.moved方法的具体用法?Python App.moved怎么用?Python App.moved使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.App
的用法示例。
在下文中一共展示了App.moved方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from app import App [as 别名]
# 或者: from app.App import moved [as 别名]
#.........这里部分代码省略.........
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()
def turn_90_deg_clock_wise(self):
print "Turning 90 degree clockwise"
def turn_90_deg_anti_clock_wise(self):
print "Turning 90 degree anticlockwise"
def move_straight(self,next_x,next_y):
print "Moving straight now"
self.app.moved(next_x, next_y)
self.current_position = (next_x, next_y)