robocode

Class Condition

Known Direct Subclasses:
GunTurnCompleteCondition, MoveCompleteCondition, RadarTurnCompleteCondition, TurnCompleteCondition

public abstract class Condition
extends Object

Condition is used to define custom AdvancedRobot.waitFor(Condition) and custom events for a AdvancedRobot. The code below is taken from the sample robot named sample.Target. See the sample/Target.java for details.
   addCustomEvent(
       new Condition("triggerhit") {
           public boolean test() {
               return (getEnergy() <= trigger);
           };
       }
   );
 
You should note that by extending Condition this way, you are actually creating an inner class -- so if you distribute your robot, there will be multiple class files. (i.e. Target$1.class)
Authors:
Mathew A. Nelson (original)
Flemming N. Larsen (contributor)
Nathaniel Troutman (contributor)
See Also:
AdvancedRobot.waitFor(Condition), AdvancedRobot.addCustomEvent(Condition), AdvancedRobot.removeCustomEvent(Condition), AdvancedRobot.onCustomEvent(CustomEvent)

Field Summary

String
name
The name of this condition.
int
priority
The priority of this condition.

Constructor Summary

Condition()
Creates a new, unnamed Condition with the default priority, which is 80.
Condition(String name)
Creates a new Condition with the specified name, and default priority, which is 80.
Condition(String name, int priority)
Creates a new Condition with the specified name and priority.

Method Summary

void
cleanup()
Called by the system in order to clean up references to internal objects.
String
getName()
Returns the name of this condition.
int
getPriority()
Returns the priority of this condition.
void
setName(String newName)
Sets the name of this condition.
void
setPriority(int newPriority)
Sets the priority of this condition.
abstract boolean
test()
Overriding the test() method is the point of a Condition.

Field Details

name

public String name
The name of this condition.

priority

public int priority
The priority of this condition. Defaults to 80.

Constructor Details

Condition

public Condition()
Creates a new, unnamed Condition with the default priority, which is 80.

Condition

public Condition(String name)
Creates a new Condition with the specified name, and default priority, which is 80.
Parameters:
name - the name for the new Condition

Condition

public Condition(String name,
                 int priority)
Creates a new Condition with the specified name and priority. A condition priority is a value from 0 - 99. The higher value, the higher priority. The default priority is 80.
Parameters:
name - the name for the new condition
priority - the priority of the new condition

Method Details

cleanup

public void cleanup()
Called by the system in order to clean up references to internal objects.
Since:
1.4.3

getName

public String getName()
Returns the name of this condition.
Returns:
the name of this condition

getPriority

public int getPriority()
Returns the priority of this condition. A condition priority is a value from 0 - 99. The higher value, the higher priority. The default priority is 80.
Returns:
the priority of this condition

setName

public void setName(String newName)
Sets the name of this condition.
Parameters:
newName - the new name of this condition

setPriority

public void setPriority(int newPriority)
Sets the priority of this condition. A condition priority is a value from 0 - 99. The higher value, the higher priority. The default priority is 80.
Parameters:
newPriority - the new priority of this condition.

test

public abstract boolean test()
Returns:
true if the condition has been met, false otherwise.