1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import numpy as np
- import math
- class Robot( object ):
- """Move o robo distance centimetros"""
- def move(self, distance):
- raise NotImplementedError( "Should have implemented this" )
- """Roda o robo radians no sentido horario"""
- def rotate(self, radians):
- raise NotImplementedError( "Should have implemented this" )
- """Retornar verdadeiro ou falso, verdadeiro se leu branco."""
- def read(self):
- raise NotImplementedError( "Should have implemented this" )
- # ------------------------------------------------------------------------
- class VirtualRobot(Robot):
- def __init__(self, worldmap):
- self.x = np.random.rand()*worldmap.width
- self.y = np.random.rand()*worldmap.height
- self.heading = math.pi*2*np.random.rand()
- self.worldmap = worldmap
- def move(self, distance):
- self.x = self.x + (math.cos(self.heading) * distance)
- self.y = self.y + (math.sin(self.heading) * distance)
- def rotate(self, radians):
- self.heading += float(radians)
- self.heading %= 2 * math.pi
- def read(self):
- return self.worldmap.white(self.x, self.y)
- # ------------------------------------------------------------------------
- class LejosRobot(Robot):
- def __init__(self, worldmap):
- self.x = np.random.rand()*worldmap.width
- self.y = np.random.rand()*worldmap.height
- self.heading = math.pi*2*np.random.rand()
- self.worldmap = worldmap
- def move(self, distance):
- self.x = self.x + (math.cos(self.heading) * distance)
- self.y = self.y + (math.sin(self.heading) * distance)
- def rotate(self, radians):
- self.heading += float(radians)
- self.heading %= 2 * math.pi
- def read(self):
- return self.worldmap.white(self.x, self.y)
|