Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## warbot.kernel
Class Brain

    java.lang.Object
      madkit.kernel.AbstractAgent
          warbot.kernel.Brain

All Implemented Interfaces:
  java.io.Serializable, ReferenceableAgent

Direct Known Subclasses:
  Ant, BPVHome, CMExplorer, CMHome, CMRocketLauncher, gecko_team_fortress, gecko_team_spy, gecko_team_warrior, GGG_WB, HomeKiller, OlivXavBase, OlivXavDetector, OlivXavMissileLauncher, RastaRocket, Robot, ScriptedBrain

    public abstract class Brain

extends AbstractAgent
implements ReferenceableAgent, java.io.Serializable

The main super class of robot developpers. This class gives all the avaible primitives that brains can use to control their body. these methods must be invoked inside the `doIt` method. Some of them represent actions that cost time and energy. The `doIt` method describes what the body has to do in one turn. Implementation of a robot behavior, by subclassing this `Brain` class or by designing Python or Jess scripts must take care of the following features.

Many actions may be done only once per turn. This is true for instance of the methods: move, `eat`, `take`, `drop`, `launchRocket`, and `buildRocket`.

Only one of these actions may be actually performed per turn, thus calling these methods several times per turn is useless!!

For example :

        public void doIt(){
            move();
            move();
            launchRocket(120);
        }

will only consists in an attempt to launch a rocket in the direction 120. The two `move`invocations will be overwritten by the invocation of the `launchRocket` action.

Some methods are only available for a specific type of robot's body. Only RocketLaunchers may actually shoot and build rockets. Calling such an action to an Explorer will lead to nothing. Each type of robot also differs in their speed, initial energy, detecting range. Information about these attributes may be required with the getter `getXXX()` where `XXX` is the attribute to be known. To perceive the world a robot has to ask for the `getPercepts` method that returns an array of Percepts, i.e. an array of objects which are all instance of the `Percept` class. To actually know the type of percept, you must use the `getPerceptType` method that returns a String corresponding to the type of entity.

Here are the percept types and their related entity class:

        Obstacle        Wall (or PalmTree)
        Food            Hamburger
        Rocket          Rocket
        Explorer        Explorer
        RocketLauncher  RocketLauncher
        Home            Home

See the Percept for more information about the use of percepts.

See Also:
  Serialized Form

Constructor Summary
`Brain()`

Method Summary
`int` | `bagSize()` return the current nb of objects in the robot's bag.
`void` | `broadcast(java.lang.String groupName, java.lang.String roleName, java.lang.String m)` Sends a WarbotMessage with performative m to all agents with role roleName in group groupName
`void` | `broadcast(java.lang.String groupName, java.lang.String roleName, java.lang.String m, java.lang.String a)` Sends a WarbotMessage with performative m and argument a to all agents with role roleName in group groupName
`void` | `broadcast(java.lang.String groupName, java.lang.String roleName, java.lang.String m, java.lang.String[] c)` Sends a WarbotMessage with performative m and an array of String arguments c to all agents with role roleName in group groupName
`void` | `broadcast(java.lang.String groupName, java.lang.String roleName, java.lang.String m, java.lang.String a1, java.lang.String a2)` Sends a WarbotMessage with performative m and arguments a1 and a2 to all agents with role roleName in group groupName
`void` | `broadcastMessage(java.lang.String groupName, java.lang.String roleName, Message m)` In warbot you can only send messages that are instance of the class madkit.messages.StringMessage.
`void` | `buildRocket()` try to do the action of building a rocket for future launch.
`void` | `createAgent(java.lang.String str)` Tries to create an agent with the available resources.
`double` | `distanceTo(Percept p)` returns the distance relative to the perceived entity
`abstract void` | `doIt()` This method controls the behavior of a robot.
`void` | `drop(int index)` Drop and put in the environment the item that the robot got in its bag.
`void` | `dropAll()` Drop and put in the environment everything the robot got in its bag Drop the item if it is possible.
`void` | `eat(Food fd)` Try to eat some Food (Food is a percept like everything in warbot world), This action may only be performed once per turn (when the robot is actived), Thus, it is useless to call it several time in the doIt (it will have no effect)
`void` | `edit()`
`int` | `getBagCapacity()` return the capacity of the robot's bag
`Percept[]` | `getBagPercepts()` returns all the things you have in the robot's bag.
`int` | `getCoveredDistance()` returns the distance covered for the last unit of time.
`int` | `getEnergyLevel()`
`double` | `getHeading()` get the robot's current heading
`int` | `getMaximumEnergy()`
`Percept[]` | `getPercepts()` Gets all the percepts available in the detection range.
`int` | `getResourceLevel()`
`int` | `getRocketNumber()` how many rocket do the robot currently hold
`boolean` | `getShot()`
`java.lang.String` | `getTeam()`
`void` | `init()` Method invoked just after creation of the Brain and before the activate() method.
`boolean` | `isBagEmpty()` return true if the robot's bag if empty.
`boolean` | `isBagFull()` return true if the robot's bag if full.
`boolean` | `isMoving()` Tells if the robot has moved in the preceding turn or not.
`boolean` | `isMyBagEmpty()`
`boolean` | `isMyBagFull()`
`boolean` | `isShowUserMessage()`
`void` | `launchRocket(double direction)` try to do the action of launching a rocket in the desired direction to perform such an action the robot's body must have the ability to launch rockets (like a RocketLauncher) As the action move, it is useless to call this method several time in the doIt: at most just one rocket will be launched.
`void` | `move()` Try to move the robot in the world This action may only be performed once per turn (when the robot is actived), Thus, it is useless to call it several time in the doIt (it will have no effect)
`void` | `randomHeading()` Give a random direction to the robot
`WarbotMessage` | `readMessage()` Reads a message in the message box.
`protected void` | `receiveMessage(Message m)` Put a message into the mailbox and update the relative coordinates of the sender Kernel action, don't invoke this method yourself...
`void` | `send(AgentAddress target, java.lang.String m)` Sends a WarbotMessage with performative m to the target agent
`void` | `send(AgentAddress target, java.lang.String m, java.lang.String a)` Sends a WarbotMessage with performative m and argument a to the target agent
`void` | `send(AgentAddress target, java.lang.String m, java.lang.String[] c)` Sends a WarbotMessage with performative m and an array of String arguments c to the target agent
`void` | `send(AgentAddress target, java.lang.String m, java.lang.String a1, java.lang.String a2)` Sends a WarbotMessage with performative m and arguments a1 and a2 to the target agent
`void` | `sendMessage(AgentAddress target, Message m)` In warbot you can only send messages that are instance of the class WarbotMessage.
`void` | `sendMessage(java.lang.String groupName, java.lang.String roleName, Message m)` In warbot you can only send messages that are instance of the class WarbotMessage.
`void` | `setHeading(double direction)` set the robot direction, direction
`void` | `setUserMessage(java.lang.String s)`
`void` | `showUserMessage(boolean b)`
`void` | `take(Transportable f)` try to put something in the robot's bag.
`double` | `towards(double a, double b)` returns the direction heading to the relative point a,b

Methods inherited from class madkit.kernel.AbstractAgent
`activate, broadcastMessage, connectedWithCommunity, createGroup, createGroup, debug, destroyGroup, disposeMyGUI, end, foundGroup, getAddress, getAgentsWithRole, getAgentsWithRole, getAgentWithRole, getAgentWithRole, getAvailableCommunities, getBean, getController, getCurrentKernelAddress, getDebug, getExistingGroups, getExistingGroups, getExistingRoles, getExistingRoles, getGroups, getGUIObject, getMessageBoxSize, getMyGroups, getMyGroups, getMyRoles, getMyRoles, getName, getRoles, hasGUI, hashCode, hideMyGUI, initGUI, isBelongingToGroup, isBelongingToGroup, isCommunity, isGroup, isGroup, isMemberOf, isMemberOf, isMessageBoxEmpty, isRole, isRole, joinGroup, killAgent, launchAgent, launchAgent, leaveGroup, leaveGroup, leaveRole, leaveRole, nextMessage, print, println, redisplayMyGUI, requestRole, requestRole, requestRole, restoreAgent, sendMessage, setBean, setController, setDebug, setGUIObject, setName, setOutput, setOutputWriter, toString, windowClosing`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### Brain

    public Brain()

Method Detail

### edit

    public void edit()

### init

    public void init()

  Method invoked just after creation of the Brain and before the activate() method. Make all initializations which are not based on the agent here...

### towards

    public final double towards(double a,
                                double b)

  returns the direction heading to the relative point a,b

### distanceTo

    public double distanceTo(Percept p)

  returns the distance relative to the perceived entity

### getCoveredDistance

    public int getCoveredDistance()

  returns the distance covered for the last unit of time. Usually 2

### doIt

    public abstract void doIt()

  This method controls the behavior of a robot. It is called once per turn. This method must be implemented in subclasses of this class.

### move

    public void move()

  Try to move the robot in the world This action may only be performed once per turn (when the robot is actived), Thus, it is useless to call it several time in the doIt (it will have no effect)

### eat

    public void eat(Food fd)

  Try to eat some Food (Food is a percept like everything in warbot world), This action may only be performed once per turn (when the robot is actived), Thus, it is useless to call it several time in the doIt (it will have no effect)

### take

    public void take(Transportable f)

  try to put something in the robot's bag. This thing must be a 'Transportable'. For the moment, only Food is considered to be transportable... This action may only be performed once per turn (when the robot is actived), Thus, it is useless to call it several time in the doIt (it will have no effect)

### getTeam

    public java.lang.String getTeam()

  Returns:
    the team of the robot

### getEnergyLevel

    public int getEnergyLevel()

### getMaximumEnergy

    public int getMaximumEnergy()

### getShot

    public boolean getShot()

### receiveMessage

    protected final void receiveMessage(Message m)

  Put a message into the mailbox and update the relative coordinates of the sender Kernel action, don't invoke this method yourself...

  Overrides:
    `receiveMessage` in class `AbstractAgent`
  Parameters:
    `m` - the message

### isBagEmpty

    public boolean isBagEmpty()

  return true if the robot's bag if empty.

### isMyBagEmpty

    public boolean isMyBagEmpty()

### isBagFull

    public boolean isBagFull()

  return true if the robot's bag if full.

### isMyBagFull

    public boolean isMyBagFull()

### bagSize

    public int bagSize()

  return the current nb of objects in the robot's bag.

### getBagCapacity

    public int getBagCapacity()

  return the capacity of the robot's bag

### getBagPercepts

    public Percept[] getBagPercepts()

  returns all the things you have in the robot's bag. Actually your return an array of percepts, not the real things your robots hold

### drop

    public void drop(int index)

  Drop and put in the environment the item that the robot got in its bag. This item is referenced by its index in the bag Drop the item if it is possible. Do nothing if the index is out of the range of the bag.

### dropAll

    public void dropAll()

  Drop and put in the environment everything the robot got in its bag Drop the item if it is possible.

### createAgent

    public void createAgent(java.lang.String str)

  Tries to create an agent with the available resources. Only Home can create agents..

  Parameters:
    `str,` - the name of the agent to be created as defined in the formalism file..

### launchRocket

    public void launchRocket(double direction)

  try to do the action of launching a rocket in the desired direction to perform such an action the robot's body must have the ability to launch rockets (like a RocketLauncher) As the action move, it is useless to call this method several time in the doIt: at most just one rocket will be launched. It takes some time to be able to send a new rocket. For instance it takes 3 turns for a RocketLauncher to be able to send a rocket again

### buildRocket

    public void buildRocket()

  try to do the action of building a rocket for future launch. It takes some energy to build a rocket. This action may only be performed once per turn (when the robot is actived), Thus, it is useless to call it several time in the doIt (it will have no effect)

### getRocketNumber

    public int getRocketNumber()

  how many rocket do the robot currently hold

### setHeading

    public void setHeading(double direction)

  set the robot direction, direction

### getHeading

    public double getHeading()

  get the robot's current heading

### isMoving

    public boolean isMoving()

  Tells if the robot has moved in the preceding turn or not. This method is very handy to know if the robot is blocked in its way or not.

  Returns:
    true if the robot has moved, false elsewhere

### getPercepts

    public Percept[] getPercepts()

  Gets all the percepts available in the detection range. All percept information are given in relative coordinate to the perceiving robot

  Returns:
    an array of percepts
  See Also:
    `Percept`

### randomHeading

    public void randomHeading()

  Give a random direction to the robot

### showUserMessage

    public void showUserMessage(boolean b)

### setUserMessage

    public void setUserMessage(java.lang.String s)

### isShowUserMessage

    public boolean isShowUserMessage()

### getResourceLevel

    public int getResourceLevel()

### readMessage

    public final WarbotMessage readMessage()

  Reads a message in the message box. Equivalent to

       (WarbotMessage) nextMessage()

  Returns:
    a WarbotMessage if any, null if none

### sendMessage

    public final void sendMessage(java.lang.String groupName,
                                  java.lang.String roleName,
                                  Message m)

  In warbot you can only send messages that are instance of the class WarbotMessage. This in order to do not have the bots exchange object references (yourself for exemple) IT'S A SIMULATION :-)

  Overrides:
    `sendMessage` in class `AbstractAgent`
  Parameters:
    `groupName` - the group name
    `roleName` - the role name
    `m` - the message
  See Also:
    `AbstractAgent.sendMessage(String, String, String, Message)`

### sendMessage

    public final void sendMessage(AgentAddress target,
                                  Message m)

  In warbot you can only send messages that are instance of the class WarbotMessage. This in order to do not have the bots exchange object references (yourself for exemple) IT'S A SIMULATION :-)

  Overrides:
    `sendMessage` in class `AbstractAgent`
  Parameters:
    `target` - AgentAddress of the receiver
    `m` - Message to be sent

### broadcastMessage

    public final void broadcastMessage(java.lang.String groupName,
                                       java.lang.String roleName,
                                       Message m)

  In warbot you can only send messages that are instance of the class madkit.messages.StringMessage. This in order to do not have the bots exchange object references (yourself for exemple) IT'S A SIMULATION :-)

  Overrides:
    `broadcastMessage` in class `AbstractAgent`

### send

    public final void send(AgentAddress target,
                           java.lang.String m)

  Sends a WarbotMessage with performative m to the target agent

### send

    public final void send(AgentAddress target,
                           java.lang.String m,
                           java.lang.String a)

  Sends a WarbotMessage with performative m and argument a to the target agent

### send

    public final void send(AgentAddress target,
                           java.lang.String m,
                           java.lang.String a1,
                           java.lang.String a2)

  Sends a WarbotMessage with performative m and arguments a1 and a2 to the target agent

### send

    public final void send(AgentAddress target,
                           java.lang.String m,
                           java.lang.String[] c)

  Sends a WarbotMessage with performative m and an array of String arguments c to the target agent

### broadcast

    public final void broadcast(java.lang.String groupName,
                                java.lang.String roleName,
                                java.lang.String m)

  Sends a WarbotMessage with performative m to all agents with role roleName in group groupName

### broadcast

    public final void broadcast(java.lang.String groupName,
                                java.lang.String roleName,
                                java.lang.String m,
                                java.lang.String a)

  Sends a WarbotMessage with performative m and argument a to all agents with role roleName in group groupName

### broadcast

    public final void broadcast(java.lang.String groupName,
                                java.lang.String roleName,
                                java.lang.String m,
                                java.lang.String a1,
                                java.lang.String a2)

  Sends a WarbotMessage with performative m and arguments a1 and a2 to all agents with role roleName in group groupName

### broadcast

    public final void broadcast(java.lang.String groupName,
                                java.lang.String roleName,
                                java.lang.String m,
                                java.lang.String[] c)

  Sends a WarbotMessage with performative m and an array of String arguments c to all agents with role roleName in group groupName

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © Madkit Team (O. Gutknecht, J. Ferber, F. Michel et al.) All Rights Reserved.