Create an Exercise

Teachers can define their exercises by

  1. chose/create a suitable World

  2. and define the challenge for it.

Chose a World

In general, one can distinguish between

Solving a problem instance

If the world creation is not randomized, one might want to allow students to solve a specific problem. They look at the World and move Robo accordingly. Therefore, they do not rely on loops.

Solving a set of problems

If the world creation is or can be randomized, one might want to force students to solve a whole set of problems. For example, navigate Robo through a randomized maze (generated by complex_maze())

There are a lot of predefined worlds that can be the basis for the teacher’s exercises. Use the following factory functions to make use of them. To do call

>>> import roboworld as rw
>>> world = rw.factory_function(...)
>>> ...

Beginners

These Worlds can be the basis for learning the concept of method calls and conditionals. If one uses fixed dimensions of the World, students can solve those puzzles without using loops.

roboworld.leaf_corridor() roboworld.world.World

Returns a (1 times 7 world) corridor with 3 leafs.

Returns

A (1 times 7) world (corridor) containing 3 leafs.

Return type

World

Example exercise: Move ``Robo``from left to right. You will encounter LEAFS (green) along the way. Pick up all the LEAFS!

Challenge: Students have to move Robo, test for LEAFS and pick them up.

_images/world-leaf-corridor.png
roboworld.corridor(length=10, random_headway=False, nstones=0) roboworld.world.World

Returns a corridor (1 times length world) filled with randomly placed moveable stones. The roboter is placed right at the beginning of the corridor. There can be at most length-3 stones because there can be no at the cell occupied by the roboter and the goal. Furthermore at least one neighboring cell of the roboter has to be empty, otherwise the roboter is stuck (impossible task).

Parameters
  • length (int) – Optional length of the corridor.

  • random_headway (bool) – Optional, if True the orientation of Robo is randomly choosen. Otherwise Robo is oriented towards the EAST.

  • nstones (int) – Optional randomly placed stones.

Returns

A (1 times length) world (corridor) containing stones.

Return type

World

Example exercise: Move Robo``from left to right. You will encounter STONES (orange) along the way. ``Robo can only carry one STONE at a time.

Challenge: Students have to move Robo, test for STONES, pick them up and put them down again. Therefore, they also have to turn Robo multiple times.

_images/world-corridor.png
roboworld.new_world(nrows=5, ncols=9, robo_position=None, goal_position=None) roboworld.world.World

Returns a new empty world. If goal_position is None, then it is placed randomly. If robo_position is None, then it is placed in the center of the world.

Parameters
  • nrows (int) – Number of rows of the world.

  • ncols (int) – Number of columns of the world

  • robo_position (D2DVector) – Optional starting position of the roboter

  • goal_position (D2DVector) – Optional position of roboter’s goal

Returns

A new completely empty world.

Return type

World

Example exercise: Move Robo (blue) to its goal (purple).

Challenge: Students have to move Robo. If the World is randomized (e.g., random goal position), students have to come up with a search strategy!

_images/world-new-world.png
roboworld.tunnel(tunnel_length: int = 4, length: int = 8, goal_at_end=True) roboworld.world.World

Returns a (3 times length) large world conisting of a tunnel. The tunnel is randomly placed.

Parameters
  • tunnel_length (int) – Optional length of the tunnel.

  • length (int) – Optional length of the corridor.

  • goal_at_end (bool) – Optional either the goal is palced at the start (False) or end (True) of the tunnel.

Raises

ValueError – If it is not possible to construct a valid world.

Returns

A corridor containing a tunnel.

Return type

World

Example exercise: Move Robo (blue) to the tunnel exit (purple) (or entry) without using robo.is_at_goal().

Challenge: Students have to define the tunnel exit and entry (the wall on the left and right) and test for it while walking towards the WEST.

_images/world-tunnel.png

Intermediates

The next set of Worlds can be used to introduce loops.

roboworld.simple_slalom(length: int = 8, nwalls: int = 3) roboworld.world.World

Returns a (3 times length) world where immovable walls are randomly placed in the center.

Parameters
  • length (int) – Optional length of the corridor.

  • nwalls (int) – Optional randomly placed walls.

Returns

A (3 times length) world where immovable walls are randomly placed in the center.

Return type

World

Example exercise: Move Robo (blue) to its goal by passing all WALLS (dark grey) from NORTH to SOUTH or vice versa, i.e., walk a slalom!

Challenge: Students have to generate a slalom movement pattern using multiple left turns and move instructions.

_images/world-simple-slalom.png
roboworld.multi_slalom(lentgth: int = 8, ngaps: int = 3) roboworld.world.World

Returns a (3 times length) world where immovable walls are randomly placed in the center. In fact, the center is a wall with ngaps gaps.

Parameters
  • length (int) – Optional number of columns of the world.

  • ngaps (int) – Optional number of gaps within the wall.

Returns

A (3 times length) World where immovable walls are randomly placed in the center.

Return type

World

Example exercise: Move Robo (blue) to its goal by passing all WALLS (dark grey) from NORTH to SOUTH or vice versa, i.e., walk a slalom!

Challenge: Students have to generate a slalom movement pattern using multiple left turns and move instructions.

_images/world-multi-slalom.png
roboworld.round_trip() roboworld.world.World

Returns a (11 times 27) world full of walls where there is only one possible round trip to traverse. The world contains some leafs to work with.

Returns

A (11 times 27) world full of walls where there is only one possible round trip to traverse.

Return type

World

Example exercise: Move Robo (blue) to its goal. Find and pick up all the LEAFS!

Challenge: Students have to generate round-trip movement patterns using multiple left turns and move instructions. They have to test for LEAFS and pick them up. They should abstract new instructions:

  • move Robo through a right corner

  • move Robo through a left corner

_images/world-round-trip.png
roboworld.maze() roboworld.world.World

Returns a small 6 times 13 simple maze.

Returns

An empty maze.

Return type

World

Example exercise: Move Robo (blue) to its goal.

Challenge: Students have to recognize that the required movement pattern is repetitive and use this to their advantage.

_images/world-maze.png
roboworld.leaf_cross(nleafs: int = 0) roboworld.world.World

Returns a (9 times 9) world containing leafs forming a cross.

Parameters

nleafs (int) – Optional number of leafs the roboter has in its initial state.

Returns

A (9 times 9) world containing leafs forming a cross.

Return type

World

Example exercise: Move Robo (blue) to its goal. Invert all cells, i.e., if there is no LEAF at a cell, place one. If there is a LEAF at a cell, remove it!

Challenge: Students have to move Robo through the whole World, test for LEAFS, and invert the cells’ state accordingly. If Robo is initialized with enough LEAFS, the exercise is easier because students do not have to worry about visiting too many EMPTY cells consecutively.

_images/world-leaf-cross.png
roboworld.pacman() roboworld.world.World

Returns a (11 times 27) world containing a path occupied by leafs. The idea is that Robo should follow the leafs.

Returns

A (11 times 27) world containing a path occupied by leafs.

Return type

World

Example exercise: Move Robo (blue) to its goal by following the path of LEAFS.

Challenge: Students have to move Robo in a zig-zag movement pattern while Robo sensors the LEAFS accordingly.

_images/world-pacman.png

Experts

roboworld.complex_maze(nrows=10, ncols=10, robo_orientation=None) roboworld.world.World

Returns a complex, randomly generated (nrows times ncols) maze. It is guaranteed that there is a path from the roboter to its goal. If robo_orientation is None, then it is choosen at random. Robo as well as its goal is placed at random positions.

Parameters
  • nrows (int) – Optional Number of rows of the world.

  • ncols (int) – Optional Number of columns of the world

  • robo_direction – Optional starting orientation of the roboter.

Raises

ValueError – if the maze is too small.

Returns

A new completely empty world.

Return type

World

Example exercise 1: Move Robo (blue) through a randomly generated maze to its goal (purple).

Example exercise 2: Let Robo (blue) compute the shortest path through the randomly generated maze to its goal (purple). After computation, move the Robo back to its starting position and walk directly to its goal using the computed shortest path.

Challenge 1: Students have to develop a dept-first search strategy.

Challenge 2: Students must develop a breath-first search strategy, a way to move ‘backward’ and repeat a specific walk.

Hint: The dept-first search can be used to develop a breath-first search strategy.

_images/world-complex-maze.png
roboworld.game_of_life() roboworld.world.World

Returns a (10 times 9) world containing leafs forming a starting configuration for Conway’s Game of Life.

Returns

A (10 times 9) world containing leafs forming a starting configuration for Conway’s Game of Life.

Return type

World

Example exercise: Let Robo play Conway’s Game of Life. Update all cells according to the rules by manipulating the World using Robo.

Challenge: Students have to understand the rules of Conway’s Game of Life. They have to develop a strategy such that the parallel update character of the cells is not broken.

Hints: Robo has enough LEAFS. Put a LEAF on each cell. Robo can mark and unmark a cell, this might be useful.

_images/world-game-of-life.png
roboworld.sorting(n: int = 8) roboworld.world.World

Returns a randomized (n times n+1) world where each column represents a number in a list.

Parameters

n (int) – Optional Number of numbers to sort.

Returns

A (n times n+1) world (corridor) containing stones.

Return type

World

Example exercise: Let Robo sort the LEAF-rows of the World. The consecutive LEAFS of each row of the World represent a number. Bring these rows/numbers from bottom to top in ascending order.

Challenge: Students understand and implement some sorting algorithms (e.g., bubble sort ). They have to abstract Robo instructions in such a way that they can make use of their sorting algorithm.

_images/world-sorting.png

Create Your Own World

The easiest way to construct a customized World is to use yet another factory function.

roboworld.str_to_world(text: str, nleafs: int = 0) roboworld.world.World

Returns a world by parsing a string that represents the world. Single characters have the following semantic:

#: (immovable) WALL

G: Goal position

N: Robo position (orientation==NORTH)

S: Robo position (orientation==SOUTH)

W: Robo position (orientation==WEST)

E: Robo position (orientation==EAST)

R: Robo position (random orientation)

O: STONE

L: LEAF

Everything else: EMPTY

Parameters
  • text (str) – Representation of the world.

  • nleafs (int) – Optional number of leafs the roboter has in its initial state.

Returns

A world constructed from its string representation.

Return type

World

The string representation text has to be a rectangular string, i.e., a multiline string for which each line has the same length. Furthermore, if there is no 'G' (for the goal position), it will be placed at a random EMPTY position. If there is no 'R', 'N', 'W', 'S' or 'E' the robot will be placed at the center of the World; this might be impossible thus causes an exception!

For example:

>>> import roboworld
>>> text= """############
>>> #----LL----#
>>> #----------#
>>> #----R-----#
>>> #-O--------#"""
>>>
>>> world = rw.str_to_world(text)
>>> fig = world.show(scale=0.3)
>>> fig.savefig('world-str-to-world.png')

gives us

_images/world-str-to-world.png

Note that the image is mirrored because position (0, 0) is at the top left.

Define the Challenge

Above we already propose some challenges, but one is free to define a new one. Your challenges will likely depend on each other. For example, in one challenge, students might have to define a function to turn Robo by 180 degrees - a very useful abstraction. This function will certainly be very helpful in solving many other problems.

An example stream of challenges can be found here. The text is written in German.