drunkbot module
import direction class Drunkbot(object): ''' NOTE! IMPLEMENT THE METHODS DEFINED HERE! The class Drunkbot represents the "brains" (or AI) of robots which stagger from place to place. The AI of such a robot brains is based purely on a (pseudo)random number generator. See the documentation of robotworld.RobotWorld ''' def __init__(self, body, random_seed): '''NOTE! IMPLEMENT THIS. Creates a new drunkbot brain that controls the given robot body. Each Drunkbot has its own unique Random object (a random number generator). Drunkbot does not create a new Random number generator every time this method is called. See the documentation of random (in https://docs.python.org/3.4/library/random.html). Parameter body is the robot whose actions the nosebot brain is supposed to control: Robot Parameter random_seed is the seed that feeds the random generator that guides the bot: int ''' pass def move_body(self): ''' NOTE! IMPLEMENT THIS. Moves the robot. A drunkbot selects a random direction and tries to move to the adjacent square in that direction. If there is a wall or another robot in that square, the robot will collide (and does not move). If the drunkbot collides with something, it remains facing whatever it collided with and ends its turn there. If the drunkbot did not collide with anything, it turns in a new direction after moving. The new facing is again selected again at random. Note: this means that assuming that the drunkbot did not collide, it picks two random directions per turn, one to move in and one to face in. The drunkbot selects a random direction using the following algorithm: - Get all the direction constants in a list, in the order defined by the direction module. - Select a random list item (for example, using random.choice(sequence)). - Use the direction found. This method assumes that it is called only if the robot is not broken or stuck. See direction.get_values() See random.choice() ''' pass def get_random_direction(self): ''' NOTE! IMPLEMENT THIS. Selects a random direction. Returns: random direction: tuple ''' pass
Classes
class Drunkbot
NOTE! IMPLEMENT THE METHODS DEFINED HERE!
The class Drunkbot represents the "brains" (or AI) of robots which stagger from place to place. The AI of such a robot brains is based purely on a (pseudo)random number generator.
See the documentation of robotworld.RobotWorld
class Drunkbot(object): ''' NOTE! IMPLEMENT THE METHODS DEFINED HERE! The class Drunkbot represents the "brains" (or AI) of robots which stagger from place to place. The AI of such a robot brains is based purely on a (pseudo)random number generator. See the documentation of robotworld.RobotWorld ''' def __init__(self, body, random_seed): '''NOTE! IMPLEMENT THIS. Creates a new drunkbot brain that controls the given robot body. Each Drunkbot has its own unique Random object (a random number generator). Drunkbot does not create a new Random number generator every time this method is called. See the documentation of random (in https://docs.python.org/3.4/library/random.html). Parameter body is the robot whose actions the nosebot brain is supposed to control: Robot Parameter random_seed is the seed that feeds the random generator that guides the bot: int ''' pass def move_body(self): ''' NOTE! IMPLEMENT THIS. Moves the robot. A drunkbot selects a random direction and tries to move to the adjacent square in that direction. If there is a wall or another robot in that square, the robot will collide (and does not move). If the drunkbot collides with something, it remains facing whatever it collided with and ends its turn there. If the drunkbot did not collide with anything, it turns in a new direction after moving. The new facing is again selected again at random. Note: this means that assuming that the drunkbot did not collide, it picks two random directions per turn, one to move in and one to face in. The drunkbot selects a random direction using the following algorithm: - Get all the direction constants in a list, in the order defined by the direction module. - Select a random list item (for example, using random.choice(sequence)). - Use the direction found. This method assumes that it is called only if the robot is not broken or stuck. See direction.get_values() See random.choice() ''' pass def get_random_direction(self): ''' NOTE! IMPLEMENT THIS. Selects a random direction. Returns: random direction: tuple ''' pass
Ancestors (in MRO)
- Drunkbot
- __builtin__.object
Methods
def __init__(
self, body, random_seed)
NOTE! IMPLEMENT THIS.
Creates a new drunkbot brain that controls the given robot body.
Each Drunkbot has its own unique Random object (a random number generator). Drunkbot does not create a new Random number generator every time this method is called.
See the documentation of random (in https://docs.python.org/3.4/library/random.html).
Parameter body is the robot whose actions the nosebot brain is supposed to control: Robot
Parameter random_seed is the seed that feeds the random generator that guides the bot: int
def __init__(self, body, random_seed): '''NOTE! IMPLEMENT THIS. Creates a new drunkbot brain that controls the given robot body. Each Drunkbot has its own unique Random object (a random number generator). Drunkbot does not create a new Random number generator every time this method is called. See the documentation of random (in https://docs.python.org/3.4/library/random.html). Parameter body is the robot whose actions the nosebot brain is supposed to control: Robot Parameter random_seed is the seed that feeds the random generator that guides the bot: int ''' pass
def get_random_direction(
self)
NOTE! IMPLEMENT THIS.
Selects a random direction.
Returns: random direction: tuple
def get_random_direction(self): ''' NOTE! IMPLEMENT THIS. Selects a random direction. Returns: random direction: tuple ''' pass
def move_body(
self)
NOTE! IMPLEMENT THIS.
Moves the robot. A drunkbot selects a random direction and tries to move to the adjacent square in that direction. If there is a wall or another robot in that square, the robot will collide (and does not move). If the drunkbot collides with something, it remains facing whatever it collided with and ends its turn there. If the drunkbot did not collide with anything, it turns in a new direction after moving. The new facing is again selected again at random. Note: this means that assuming that the drunkbot did not collide, it picks two random directions per turn, one to move in and one to face in.
The drunkbot selects a random direction using the following algorithm:
-
Get all the direction constants in a list, in the order defined by the direction module.
-
Select a random list item (for example, using random.choice(sequence)).
-
Use the direction found.
This method assumes that it is called only if the robot is not broken or stuck.
See direction.get_values()
See random.choice()
def move_body(self): ''' NOTE! IMPLEMENT THIS. Moves the robot. A drunkbot selects a random direction and tries to move to the adjacent square in that direction. If there is a wall or another robot in that square, the robot will collide (and does not move). If the drunkbot collides with something, it remains facing whatever it collided with and ends its turn there. If the drunkbot did not collide with anything, it turns in a new direction after moving. The new facing is again selected again at random. Note: this means that assuming that the drunkbot did not collide, it picks two random directions per turn, one to move in and one to face in. The drunkbot selects a random direction using the following algorithm: - Get all the direction constants in a list, in the order defined by the direction module. - Select a random list item (for example, using random.choice(sequence)). - Use the direction found. This method assumes that it is called only if the robot is not broken or stuck. See direction.get_values() See random.choice() ''' pass