Remote control a slave robot without using an \l;information exchange post\u object\exchange;. The robot should pass over the 6 blue crosses. You must use a \l;string\u cbot\string; to pass the orders to the slave bot. This string contains the order the slave shoud execute, for exemple \c;"move(20)"\n;. You can see that this is the same syntax as used in the CBOT language but we could have chosen any other syntax for exemple something like \c;"advance=20"\n;. The string will be a \c;\l;static\u cbot\static;\n; class member that will be used to communicate from the master to the slave.
The two main actors of this exercise are:
1) The \l;wheeled grabber\u object\botgr; without an energy pack and therefore immobile. This is the master you should program so it will transmit orders to the slave.
2) The slave \l;practice bot\u object\bottr; which is already programmed and just waits for orders from the master.
\b;The slave
First of all we must understand how the program of the slave works. The \l;class\u cbot\class; \c;exchange\n; contains the mechanism for exchaning the orders. We declare a \c;\l;static\u cbot\static;\n; class member \c;m_order\n; which will contain the order to be executed. The word \c;static\n; insures that the member \c;m_order\n; is shared between all instances of the \l;class\u cbot\class; exchange.
\n;The \c;put\n; method will be used by the master robot for transmitting an order. As long as the string \c;m_order\n; is not empty, the slave has not finished the order and the \c;put\n; method will return \c;false\n; and will do nothing.
Another method \c;get\n; will be used by the slave to retrieve the orders. This method returns the string contained in \c;m_order\n; and empties it, so a new order can be accepted:
The outer \c;while\n; loop lasts for ever. The inner \c;while\n; loop waits for an order by using the \c;get\n; method of the \c;exchange\n; class. As soon as \c;get\n; returns a non empty string, the while loop stops.
\c;\s; \l;while\u cbot\while; ( true )
\s; {
\s; \l;while\u cbot\while; ( true )
\s; {
\s; todo = list.get();
\s; if ( todo != "" ) break;
\s; wait(1);
\s; }
\n;
Now we have received the order in the \c;todo\n; variable. All we have to do is execute it:
\c;\s; if ( \l;strfind\u cbot\strfind;(todo, "move") == 0 )