本文整理汇总了Python中Robot.Robot.registerMoveCallBack方法的典型用法代码示例。如果您正苦于以下问题:Python Robot.registerMoveCallBack方法的具体用法?Python Robot.registerMoveCallBack怎么用?Python Robot.registerMoveCallBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Robot.Robot
的用法示例。
在下文中一共展示了Robot.registerMoveCallBack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Robot import Robot [as 别名]
# 或者: from Robot.Robot import registerMoveCallBack [as 别名]
class Simulation:
def __init__(self,propsfile):
self.canvas = Tk()
self.props = json.load(open(propsfile))
self.worldMap = WorldMap(propsfile)
self.wg = WorldGrid(self.canvas,self.props,self.worldMap)
self.wg.registerCallBack(self.processEvent)
self.robot = Robot(self.props,self.worldMap)
self.robot.registerSenseCallBack(self.sense)
self.robot.registerMoveCallBack(self.move)
self.rRow = -1
self.rCol = -1
self.randomizeRobotPosition()
self.robot.sense()
self.shadeSquares()
def randomizeRobotPosition(self):
# randomly select the starting robot location --
# do this until a valid square (i.e., not a wall) is
# selected
found = False
while (found == False):
row = random.randint(0,self.worldMap.nRows-1)
col = random.randint(0,self.worldMap.nCols-1)
if(self.worldMap.isValidSquare(row,col)):
found = True
self.rRow = row
self.rCol = col
def move(self,dirc):
row = self.rRow
col = self.rCol
if(dirc == 1): # NORTH
row -= 1
elif(dirc == 2): # EAST
col += 1
elif(dirc == 4): # SOUTH
row += 1
elif(dirc == 8): # WEST
col -= 1
else:
print "ERROR: Invalid move direction"
self.rRow = row
self.rCol = col
def sense(self):
# NORTH
meas = 0
if(self.worldMap.isValidSquare(self.rRow-1,self.rCol)):
meas = meas | 1
# EAST
if(self.worldMap.isValidSquare(self.rRow,self.rCol+1)):
meas = meas | 2
# SOUTH
if(self.worldMap.isValidSquare(self.rRow+1,self.rCol)):
meas = meas | 4
# WEST
if(self.worldMap.isValidSquare(self.rRow,self.rCol-1)):
meas = meas | 8
return meas
def run(self):
self.wg.draw()
self.shadeSquares()
self.wg.drawRobot(self.rRow,self.rCol)
self.canvas.geometry(self.props["windowDimensions"])
self.canvas.mainloop()
def shadeSquares(self):
probabilities = self.robot.mapProbabilities
for i in range(0,len(probabilities)):
for j in range(0,len(probabilities[i])):
if(self.worldMap.isWall(i,j)==False):
if(self.robot.mapProbabilities[i][j]>0):
# 0 is black, 255 is white
c = 125 - math.floor(self.robot.mapProbabilities[i][j]*125.0)
#c = 255 - int(self.robot.mapProbabilities[i][j]*255.0)
cstr = "#%02x%02x%02x" % (0,c,0)
self.wg.shadeSquare(i,j,cstr)
else:
cstr = "#%02x%02x%02x" % (255,255,255)
self.wg.shadeSquare(i,j,cstr)
#.........这里部分代码省略.........