The roboworld Universe
The roboworld
universe is made of the World
.
World
consists of a discrete rectangular Grid
cells, a goal position, and Robo
a roboter that can move from cell to cell.
Robo’s World
The World
can be seen as a rectangular bounded cellular automaton (a discrete rectangular Grid
cells where each cell is in a state).
Each cell can be in exactly one of the following states:
- LEAF (green)
a leaf can be picked up by
Robo
if he stands on it.Robo
can carry an infinite amount of leafs. Leafs are traversable.- STONE (orange)
a stone in front can be picked up by
Robo
butRobo
can only carry one stone. Stones are not traversable.- WALL (dark grey)
a wall is an immovable barrier, i.e., it is not traversable.
- EMPTY (light grey)
the cell is empty and traversable.
Robo
is positioned at the blue cell where the intensity indicates its orientation.
The goal is positioned at the purple cell.
Cells in the state LEAF and EMPTY are traversable while cells in the state STONE or WALL can not be occubied by Robo
.
We use the matrix-like indexing that starts from 0
, i.e. row before column, such that cell[1][2]
is the cell in the second row and the third column.
Display the World
- roboworld.World.show(self, scale=0.5, visualizer=<function World.<lambda>>) matplotlib.figure.Figure
Returns a displayabel representation (a figure) of the world.
- Parameters
scale (int) – Optional scaling of the figure.
visualizer (Function (Robo, float) -> Figure) – Optional function that contructs the figure.
- Returns
A displayabel representation (a figure) of the world.
- Return type
Figure
- roboworld.World.animate(self, scale=0.5, animator=<function World.<lambda>>) matplotlib.animation.FuncAnimation
Returns a displayable animation of the recorder that was lastely added to the roboter. A recorder records the movements and actions of the robo. The generated animation reflects this. The Animation is defined by the animator (strategy pattern)
- Parameters
scale (int) – Optional scaling of the figure.
animator (Function (Robo, float) -> FuncAnimation) – Optional function that contructs the animation.
- Returns
A displayable animation of the recorder that was lastely added to the roboter.
- Return type
FuncAnimation
Hint
Instead of constructing the animation you can display it within a Jupyter notebook by calling roboworld.animate(world)
.
- roboworld.animate(world: roboworld.world.World) any
Displays an animation of the world in a Jupyter notebook.
- Parameters
length (World) – The world that will be animated.
Access the World
- roboworld.World.get_robo(self)
Returns the Robo of the world.
- Returns
The Robo of the world.
- Return type
RoboProxy
Hint
It is recommended to access robo
using world.robo
where world
is a World
.
- roboworld.World.is_successful(self)
Returns True if and only if the Robo found its goal.
- Returns
True if and only if the Robo found its goal.
- Return type
bool
Hint
The goal position as well as Robo
do not contribute to the state of a cell.
Therefore, a cell in state LEAF remains in state LEAF even if Robo
or the goal is positioned at this cell.
Important
Students should only interact with World
indirectly by using Robo
.
Robo
Robo
is a quite limited machine that can only execute a few basic intructions.
These instructions can be categories into movement (change yourself), self-observation (sensor yourself), observation of the world (sensor the world), world manipulations (change the world) and utilty instructions.
Movement
- roboworld.Robo.move(self) roboworld.vector.D2DVector
Moves Robo one cell ahead.
- Raises
WallInFrontException – If there is an (immoveable, not traverseable) wall in front (WALL or boundary of the world).
StoneInFrontException – If there is a stone (moveable, not traverseable) in front.
- Returns
Robo’s new position.
- Return type
D2DVector
- roboworld.Robo.turn_left(self) None
Robo turns 90 degrees to the left (counter-clockwise order NORTH->WEST->SOUTH->EAST).
Sensor Yourself
- roboworld.Robo.is_facing_north(self) bool
Returns True if and only if robo is oriented towords the north.
- Returns
True if and only if robo is oriented towords the north.
- Return type
bool
- roboworld.Robo.is_carrying_stone(self) bool
Returns True if and only if robo is carrying a stone.
- Returns
True if and only if robo is carrying a stone.
- Return type
bool
- roboworld.Robo.is_carrying_leafs(self) bool
Returns True if and only if thre the robo carries any leafs.
- Returns
True if and only if thre the robo carries any leafs.
- Return type
bool
Change the World
- roboworld.Robo.take_leaf(self) None
Takes a leaf at Robo’s current position.
- Raises
LeafMissingException – If there is no leaf the Robo’s position.
- roboworld.Robo.put_leaf(self) None
Puts a leaf at Robo’s current position.
- Raises
NoMoreLeafsException – If Robo does not carry any leaf.
CellOccupiedException – If there is an object (leaf, wall, stone) at the current cell.
- roboworld.Robo.put_stone_in_front(self) None
Puts the carrying stone down in front.
- Raises
SpaceIsEmptyException – If Robo does not carry a stone.
WallInFrontException – If there is a wall in front, i.e., no stone.
StoneInFrontException – If there is another stone in front.
LeafInFrontException – If there is a leaf in front.
- roboworld.Robo.take_stone_in_front(self) None
Takes a stone that is in front.
- Raises
SpaceIsFullException – If Robo does already carry a stone.
WallInFrontException – If there is a wall in front, i.e., no stone.
LeafInFrontException – If there is a leaf in front.
StoneMissingException – If there is no stone in front.
- roboworld.Robo.set_mark(self) None
Marks the current cell, i.e., position.
- roboworld.Robo.unset_mark(self) None
Unmarks the current cell, i.e., position.
Sensor the World
- roboworld.Robo.is_wall_in_front(self) bool
Returns True if and only if there is an (immoveable) wall or the boundary of the world in front.
- Returns
True if and only if there is an (immoveable) wall or the boundary of the world in front.
- Return type
bool
- roboworld.Robo.is_leaf_in_front(self) bool
Returns True if and only if thre is a leaf in front.
- Returns
True if and only if thre is a leaf in front.
- Return type
bool
- roboworld.Robo.is_stone_in_front(self) bool
Returns True if and only if there is a stone in front of robo.
- Returns
True if and only if there is a stone in front of robo.
- Return type
bool
- roboworld.Robo.is_mark_in_front(self) bool
Returns True if and only if there is a mark in front.
- Returns
True if and only if there is a mark in front.
- Return type
bool
- roboworld.Robo.is_at_goal(self) bool
Returns True if and only if robo is standing at the goal.
- Returns
True if and only if robo is standing at the goal.
- Return type
bool
Utility
- roboworld.Robo.toss(self) bool
Returns randomly True or False.
- Returns
Either True or False by chance 50/50.
- Return type
bool
Students have to prorgamm more sophisticated methods by themselves by combining multiple instructions.
The learning goal is that they, step by step, build a set of functions to navigate within different Worlds
.
And by doing so, they hopefully pick up the most important programming fundamentals.