1. About Mentor
  2. Using Mentor
  3. Basic Commands
  4. Sensing Commands
  5. Programming Structures

1. About Mentor

Mentor is an educational tool to allow people that are new to programming a machine (with focus on students), to acquire and develop computational thinking skills, building a sound foundation to learn programming languages (emphasis on Java) and know how to program generalised machines. The user is able to control a robot (from the generation of Automata. There will be other generations in future releases.) It always has the name IO and you can choose its appearance with several predefined images.

2. Using Mentor

Using the basic features of the program is pretty straight-forward. The toolbar with the large icons can guide you through it. First, click on the map button to open an existing map. Then, choose the appearance of the robot by clicking on the button with R2D2 (shame on you if you don't know him!) and the robot will then be placed at the appropriate starting point in the map. Finally you have to load a behaviour for the robot by clicking the battery button, and finally click on the play button to observe the behaviour of the robot in this map! Open this manual by clicking on the Help button if you need any help.

At any point in the process you can go back and start over by changing whatever it is you wish to change. Note that after you have started to observe the behaviour of the robot, you cannot do anything else but wait for it to finish and if you want at the end see the log file. Or you can stop observing it pressing the stop button that stops the execution, where you will be able to see the logging it did until that point. All actions above can be accessed through the File menu and keyboard shortcuts. Also, you can enable or disable the toolbar through the Settings menu if you feel it is intrusive, you can adjust the animation speed of the robot, and you can set your logging preferences.

In the Tools menu you can find a handy application to easily create maps in 3 steps. It is advised that you have made a pen and paper draft of the map you would like to create in advance, even if you will get feedback when painting tiles or putting creatures on it. Behaviour files must have the extension ".handler" and follow specific rules. You will have to create a file with that extension and the name of the file must follow the Java conventions for Class names, otherwise it will not be able to load the behaviour. All commands need to be included in the brackets after a method named "exectureAlgorithm()".

To see an example of this, let us assume that we want to create a behaviour that makes the robot move 3 steps south, then paint 1 tile in front of it black and then follow with 2 white tiles, all that in the "Empty" map. So, the desired map exists, but not the behaviour we want. In order to understand this better it is advised to read the following sections explaining commands, checks and structures first. They are very insightful for syntax so go ahead and read them. The behaviour we want to create is:

robot.south(3);
robot.paintBlack();
robot.forward(1);
robot.paintWhite();
robot.forward(2);
robot.stopPainting();
So what should we do? We open Notepad or TextPad, or any other good text editor suited for creating simple ASCII files, and then we have to create the method mentioned earlier, which includes the commands above. The text we type should look like:
public void executeAlgorithm()
{
	robot.south(3);
	robot.paintBlack();
	robot.forward(1);
	robot.paintWhite();
	robot.forward(2);
	robot.stopPainting();
}
All we need to do now is save this file with a proper name. If we want to name it My First Behaviour then the full name of the file has to be "MyFirstBehaviour.handler". Then you can go and open the empty map, locate the folder where you saved the behaviour file and load it! The default directory the program opens to is the directory inside the folder of the program named "user". It is a good idea to keep all map and behaviour files there for quick access.

Top

3. Basic Commands

Here follow the basic commands that you can use when writing a behaviour for the controllable robot in Mentor. Remember that you will have to type "robot." before every command and add a semicolon ';' after it. For example, if you want to instruct the robot to move one step forward, the command should be "robot.forward(1);". If the commands are not used in this way when creating a behaviour for the robot, then the robot will not be able to understand and load this behaviour, at all!

Command Robot Actions
forward(n)
Robot moves forward n tiles.
backward(n)
Robot moves backwards n tiles.
turnLeft()
Robot turns 90 degrees to the left.
turnRight()
Robot turns 90 degrees to the right.
north(n)
Makes the robot head north and move n steps forward.
Using the number '0' will only make the robot head north.
south(n)
Makes the robot head south and move n steps forward.
Using the number '0' will only make the robot head south.
east(n)
Makes the robot head east and move n steps forward.
Using the number '0' will only make the robot head east.
west(n)
Makes the robot head west and move n steps forward.
Using the number '0' will only make the robot head west.
paintWhite()
When the robot next tries to move from the tile it is occupying,
the tile will be painted white, even if the robot hits an obstacle.
paintBlack()
When the robot next tries to move from the tile it is occupying,
the tile will be painted black, even if the robot hits an obstacle.
stopPainting()
The robot will stop painting tiles if instructed to do so earlier.
pickUpCreature()
Robot picks up a creature. Must be facing the creature.
e.g. robot.pickUpCreature() picks up the creature in front of it.
The robot can carry only one creature with its hands.
putDownCreature()
Robot puts down a creature it is carrying with its hands. The tile in front
of the robot must be empty and it must be carrying a creature.
e.g. robot.putDownCreature() puts down the creature in the tile in front if empty.
More advanced behaviour
pickUpCreature("name")
Robot picks up the creature by name. Must be facing the creature.
e.g. robot.pickUpCreature("Lilly") picks up the creature named Lilly.
Quotes are needed. The robot can currently carry a cargo of up to 10 creatures.
putDownCreature("name")
Robot puts down a creature it is carrying in its cargo by name. The tile in front
of the robot must be empty and it must have in its cargo the specified creature.
e.g. robot.putDownCreature("Lilly") puts down the creature named Lilly.
paintWithColor(Color.nameOfColor)
Robot paints from now on with the color specified by nameOfColor
Options for nameOfColor are: Color.BLACK, Color.GREEN, Color.PINK, Color.RED, Color.WHITE, Color.YELLOW.
e.g. robot.paintWithColor(Color.PINK) paints the next tile Heron will move with pink color.
Top

4. Sensing Commands

Apart from the basic commands explained above that can be used to instruct the robot to move around and perform some basic actions, the robot has some more advanced ones that can help it sense the world. The following commands must be used in programming structures, which will be explained in the following section, such as loops and if-statements, in order to create a much more effective, efficient, or generally more complex behaviour for it. If they are not used as such they will not make the robot do anything and will have no impact whatsoever. These commands perform checks and they return to the robot the result (this way the robot senses the environment), which can be either true or false. Same rules as above apply for using these commands.

Sense Command Check Result
frontIsClear()
rightIsClear()
leftIsClear()
Used to check if the tiles around the robot are not obstacles, but empty spaces.
The robot can move freely in such tiles and paint them white or black, as well.
frontIsObstacle()
rightIsObstacle()
leftIsObstacle()
Used to check if the tiles around the robot are obstacles, such as walls or creatures.
The robot cannot move in such tiles or paint them and has to move around them.
frontIsCreature("name")
rightIsCreature("name")
leftIsCreature("name")
Used to check if a creature with that name is currently occuping the tiles around the robot.
This tile is also an obstacle. Remember that picking up a creature requires facing it first!
e.g. "robot.leftIsCreature("Lilly");" will return true if Lilly occupies the tile left of it.
frontIsCreature()
rightIsCreature()
leftIsCreature()
Used to check if a creature (any) is currently occuping the tiles around the robot.
This tile is also an obstacle. Remember that picking up a creature requires facing it first!
e.g. "robot.leftIsCreature();" will return true if any creature occupies the tile left of it.
frontIsColor(Color.name)
rightIsColor(Color.name)
leftIsColor(Color.name)
Used to check if the tiles around the robot are painted with a color. Replace the name only.
e.g. "robot.leftIsColor(Color.BLACK);" will return true if the tile left of it is painted black.
flipCoin()
The robot flips a coin and will get a result of true 50% of the time, and 50% it will be false.
This check can be very useful when there is a need to randomize the behaviour of the robot.
Top

5. Programming Structures

if Structures: Changing the flow of the program execution

if Syntax Explanation
if ( logical expression )
{
	block of statements
}
Logical expression that describes a desired condition and can be evaluated to either true or false.
In case the logical expression is evaluated as true (the condition is true at the time of execution) then this block of statements defined between the starting curly bracket { and the closing curly bracket } is executed. Otherwise, if the condition is false, the block is ignored, not executed.
Example:
if ( robot.frontIsClear() )
{
	robot.forward(1);
}
if ( logical expression )
{
	(1st) block of statements
}
else
{
	another (2nd) block
}
In case the logical expression is evaluated as true then only this block of statements is executed and the 2nd is ignored.
Otherwise (else), if the condition is false, the 1st block is ignored, and only this 2nd block is executed.
Example:
if ( robot.frontIsClear() )
{
	robot.forward(1);
}
else
{
	robot.turnRight();
}
if ( condition_1 )
{
  	(1st) block of statements
}
else if ( condition_2 )
{
	(2nd) block of statements
}
...
else if ( condition_n )
{
	(nth) block of statements
}
else
{
	(3rd) block of statements
}
						
if ( robot.leftIsObstacle() && ! robot.rightIsObstacle() )
{
  	robot.turnRight();
}
else if ( !robot.leftIsObstacle() && robot.rightIsObstacle() )
{
	robot.turnLeft();
}
else
{
	if (robot.flipCoin())
	{
		robot.turnLeft();
	}
	else
	{
		robot.turnRight();
	}
}
						
Top