Chapter 2.5 - Notes about writing a strategy

A basic state for default behaviour

In many cases, the behaviour of your strategy concerning a certain message (e. g. the robots left message) is always the same. If you do not want to specify this behaviour for every single state once more, create a "basic" client / server state at first that will serve as a base class for all your server / client states.

If you want to extend the functionality of your base class in some states, simply revoke the super method before.

The Brotfrucht strategy uses such a basic class, too. For example, the reaction to a server tip is always the same here. So reactOnServerTip() can be written in that basic class (bfclientbasicsate.{h|cpp}). When derivating another state from that state, you simply have to write

class BFClientShootHalfState: public BFClientBasicState

(this is copied from the ShootHalfState of Brotfrucht). Of cause, you can add special methods in this state, too.

As told above, you can override the basic method or simply extend it. An example for extending is in BFServerNoRotateState of Brotfrucht:

void BFServerNoRotateState::reset () throw (bad_exception, StrategyException) {

This method is calling and executing reset() in the basic state first and adds then the robot's name to the list of names in the ServerSharedSpecificRepository.

Identify states by names

All states are identified by a scalar value what is not the best for understanding. So it might be a good idea to define an enumeration with self describing names in a separate header file that is included by each state object.

In the Brotfrucht strategy, these files are called bfserverstateenum.h and bfclientstateenum.h. In there, there is nothing else than

namespace Brotfrucht {
  enum BFServerStateEnum {
    DOROTATE    = 1

Now you can switch states by calling setCurrentServerState(DOROTATE) instead of setCurrentServerState(1).

Using the "empty" files

We provide an empty template set for your own strategy. It consists out of the needed basic classes including a basic one derivated state for the server and the client. So you do not need to write them by your own. That will save some time ;)

The files are available within each distribution. They are available as a normal strategy within the RealTimeBattle Team Framework, too. But notice, they're realy empty and do nothing (like the empty.robot in RealTimeBattle).