The version 0.80 introduce the concept of is Object Oriented robots.
In the previous versions of Rars, the robots where defined as a function
con_vec RobotName( situation &s )
This function was called several times in the program for several reasons.
1) A first time with an empty situation, to ask for the name of the
robot.
2) At the beginning of a race, with s.starting = 1, to allow
the robots to prepare themselves for a race, a track.
3) And finally a lot of times with s.starting = 0 during the
simulation.
The simplest robot looks like this.
|
#include "car.h"
con_vec RobotName( situation &s )
if (init_flag == 1)
if( s.starting )
if (stuck(s.backward, s.v, s.vn, s.to_lft,
s.to_rgt, &result.alpha, &result.vc))
result.vc = 20;
// going slowly
return result;
|
From the version Rars 0.80, it is possible to write Object Oriented Robots. Robots are defined as C++ classes subclassing the type Driver
class ObjectOriented : public Driver
associated with a function to create an object
Driver * getObjectOrientedInstance()
This object works like this:
|
#include "car.h"
class Tutorial1 : public Driver
con_vec drive(situation& s)
if( s.starting )
if( stuck( s.backward,
s.v, s.vn, s.to_lft, s.to_rgt, &result.alpha, &result.vc ) )
result.vc = 20;
// going slowly
return result;
Driver * getTutorial1Instance()
|
There are a least 2 main advantages:
1) The object robots can be created several times.
2) The object can declare its color and its name more properly.