RoboMind Documentation
Documentation
Programming structures
Overview
Introduction
Basisinstructies
Programming structures
- comment
- loops
- if-structures
- logical expressions
- procedures
- end
Example scripts

Programming structures

Here you'll find the grammatical structures that are allowed to define the behavior of the robot.

Comments

# free text that will not be evaluated

All text that appears after a hash, '#', will not be interpreted as instructions. The robot will proceed to read the next line in the script. Use this possibility to annotate parts of the script, just for yourself, as documentation about how these parts work

Loops

বারবার_করো(n){...instructions...}
repeats the instructions between curly brackets exactly n times.

Example:

# a square of 2x2
বারবার_করো(4)
{
	সামনে(2)
	ডানদিকে
}
                  

বারবার_করো{...instructions...}
just keeps repeating the instructions between curly brackets for ever.

Example:

# just goes forward
# (but eventually will stay hitting a wall)
বারবার_করো
{
	সামনে(1)
}

যতক্ষণ(condition){...instructions...}
repeats the instructions between curly brackets as long as the condition holds. This condition must be a perception/seeing instruction (for example সামনে_খালি)

Example:

# keeps going forward, 
# but stops when it can't go any further
যতক্ষণ(সামনে_খালি)
{
	সামনে(1)
}

আর_না
allows you to jump out of the loop (e.g. a repeat section) so it stops performing the instructions between curly brackets. The robot will resume performing the instructions left after the closing curly bracket of the loop.

Example:

# keep going forward, until you can't go any further
বারবার_করো
{
	যদি(সামনে_বাধা)
    {
		আর_না
	}
	নাহলে
	{	
		সামনে(1)
	}
}
                  

If-structures

যদি(condition){...instructions...}
will perform the the instructions between curly brackets, only if the condition holds. Else the robot immediately steps to the instructions written after the closing curly bracket. The condition must be a perception/seeing instruction (for example: সামনে_খালি)

Example:

# if you see white paint on your left, make it black
যদি(বাঁদিকে_সাদা)
{
	বাঁদিকে
	সামনে(1)
	কালো_রং_করো
	রং_বন্ধ
	পিছনে(1)
	ডানদিকে
}
                  

যদি(condition){...instructions...}নাহলে{...instructions...}
will perform the the instructions between the first pair of curly brackets, only if the condition holds. Then it will not perform the instructions of the else block (second pair of instructions). When the condition does not hold, the robot will only perform the instructions in between the second pair of curly brackets. After it performed one of the instruction blocks, it will read the instructions after the last curly bracket. The condition must be a perception/seeing instruction (for example: সামনে_খালি)

Example:

# if you see white paint on your left, make it black
# else drive a few steps forward
যদি(বাঁদিকে_সাদা)
{
	বাঁদিকে
	সামনে(1)
	কালো_রং_করো
	রং_বন্ধ
	পিছনে(1)
	ডানদিকে
}
নাহলে
{
	সামনে(3)
}
                  

Logical
expressions

The conditions of if- and repeatWhile-structures is a so-called logical expression. Such an expression will result in the value ঠিক or ভুল, which is then used to decide to step to the appropriate part of the code to resume execution.

A logical expression can be a perception instruction, e.g.: ঠিক. Basic instructions may also be composed with the boolean operators ~, &, |.

Example:

যদি(বাঁদিকে_সাদা)
{
    বাঁদিকে
    সামনে(1)    
}

The condition can however also be refined to more indicate more precisely when the corresponding instructions should be executed by using (a combination of) the following operators.

Operation
Alternative
notation
Number of
arguments
Explanation
না ~ 1

Negates the value of the argument :

Truth table :
~ ঠিক = ভুল
~ ভুল = ঠিক

Example:
~ সামনে_খালি

আর & 2

Only true when both arguments are true.

Truth table:
ঠিক & ঠিক = ঠিক
ঠিক & ভুল = ভুল
ভুল & ঠিক = ভুল
ভুল & ভুল = ভুল

Example:
সামনে_খালি & ডানদিকে_সাদা

বা | 2

True when at least one of the arguments is true.

Truth table:
ঠিক | ঠিক = ঠিক
ঠিক | ভুল = ঠিক
ভুল | ঠিক = ঠিক
ভুল | ভুল = ভুল

Example:
সামনে_খালি | ডানদিকে_সাদা

The values ঠিক and ভুল can also be applied directly as if it was a perception instruction.

The order of the operators is of importance (just like multiplying and adding numbers). The operation ~ binds strongest, followed by &, followed by |. Brackets can be used to influence the order of evaluation.

Examples:

				
যতক্ষণ(না সামনে_খালি আর (বাঁদিকে_সাদা বা ডানদিকে_সাদা)){
    সামনে(1)
}

যদি(কয়েন_টস আর না ডানদিকে_সাদা)
{
    ডানদিকে
    পিছনে(1)
}

যদি(ঠিক আর ভুল){
    # this instruction is never executed
    সামনে(1)
}
              

Comparing numbers
Another type of logical expressions is number comparison. Then you can make decision based on a given value. For example, only go to the right if a given variable is less than 5.

Example:

সামনে
maybeToRight(8)
সামনে

পদ্ধতি maybeToRight(n){
    যদি(n < 5){
        ডানদিকে
    }
}
            
This is the complete list of comparators.
Comparator Example: true Example: false Explanation
== 3 == 3 1 == 2 Check for equality
~= 1 ~= 2 3 == 3 Check for inequality
< 1 < 2 3 < 3 Compare values with "less than"
<= 3 <= 3 2 <= 1 Compare values with "less than or equals"
> 2 > 1 3 > 3 Compare values with "greater than"
>= 3 >= 3 1 >= 2 Compare values with "greater than or equals"

Procedures

পদ্ধতি name(par1, par2, ... , parN){...instructions...}
defines a new procedure with the name you want. The procedure can have zero or more parameters, which you may also give useful names. Here they are called par1, par2, . . . , parN. These are the variables you can use in the instruction between curly brackets. The code in a procedure will not be performed automatically, you have to write a 'procedure call' every time you want to perform the instructions in the definition (See next instruction).
Tip: create a new procedure when when you you use a sequence of instructions more than once.

Example:

# define how to draw a rectangle
পদ্ধতি rectangle(width, height)
{
	সাদা_রং_করো
	বারবার_করো(2)
	{
		সামনে(height)
		ডানদিকে
		সামনে(width)
		ডানদিকে
	}
	রং_বন্ধ
}
                  

name(arg1, arg2, . . . , argN)
is the call to the procedure with the corresponding name and the same amount parameters as you have arguments. The argument, here called arg1, arg2, . . . , argN, are the particular values that will be used in the procedure definition.

Example:

# these instructions will be performed
সামনে(1)
rectangle(3,2) # a call to the 'rectangle' procedure
সামনে(3)
rectangle(1,4) # another call with other arguments


# this is the definition of 'rectangle'
পদ্ধতি rectangle(width, height)
{
	সাদা_রং_করো
	বারবার_করো(2)
	{
		সামনে(height)
		ডানদিকে
		সামনে(width)
		ডানদিকে
	}
	রং_বন্ধ
}                  

কাজ_শেষ
To stop executing a procedure before it reaches the end, use কাজ_শেষ from within a পদ্ধতি definition. The program continues executing the commands after the corresponding call.

Example:

# these instructions will be performed
toWall()
ডানদিকে
সামনে

# go forward until you reach a wall
পদ্ধতি toWall()
{
    বারবার_করো
    {
        যদি(সামনে_বাধা)
        {
            # stop "toWall" procedure,
            # continue with right and forward
            কাজ_শেষ
        }
        নাহলে{
            সামনে
        }
    }
}                  

কাজ_শেষ(arg)
To stop executing a procedure before it reaches the end, use কাজ_শেষ from within a পদ্ধতি definition. The program continues executing the commands after the corresponding call.

By default, a procedure return the value zero. You can change this by returning an expression.

Example:

# this instruction will be performed
সামনে(double(3))

# double the given amount
পদ্ধতি double(n)
{
    কাজ_শেষ(2 * n)
}                  

Recursion
Procedures can be defined recursively. That means that you use the procedure you are defining in the procedure definition itself, by calling it. It takes a while to comprehend, but turns out to be a powerfull tool.

Example:

# these instructions will be performed
toWall()
ডানদিকে
সামনে

# go forward until you reach a wall
পদ্ধতি toWall()
{
      # notice that no loops are used
      যদি(সামনে_বাধা)
      {
          # stop "toWall" procedure
          কাজ_শেষ
      }
      নাহলে{
          # do one step
          সামনে
          # and do a recursive call!
          toWall()
      }
}                 

Arithmetic

+,-,*,/
With these operations, you can add, subtract, multiply an divide numbers. Note that the numbers have to be integers (whole numbers).

Example:

# using some arithmetic in expressions
সামনে(2+3)
যদি(3*4 < 13){
    x = 3
    বাঁদিকে(x-2)
}
পিছনে(-(3+4)/2)
                  

Variables

x = ...
With variables you can remember values under a name you can choose yourself. The values of these variables are available later in the entire script. You can get these values, by using the name again. You can remember values of any expression (so: numbers, calculations, logical expressions, see commands, return values).

Example:

# store a number
x = 42

# store another number, based on x
y = x / 2

# store a logical expression
clear = বাঁদিকে_খালি & সামনে_খালি & ডানদিকে_খালি

# store the actual number of steps taken
# until you bumped (returned by "forward")
actual = সামনে(100)

যদি(clear){
     ডানদিকে(2)
     সামনে(actual) # go back
}
বাঁদিকে(y)

                  

End

সমাপ্ত
will cause the entire program to stop when this instruction is performed.

Example:

# stop after 5 steps, or earlier when you encounter a beacon on the right
বারবার_করো(5)
{
	সামনে(1)
	যদি(ডানদিকে_আলো)
	{
		সমাপ্ত # stops execution of the program
	}
}
# normal end of the program
                  
RoboMind - Copyright © 2005 - 2013 - Arvid Halma