robocode
Class Condition

java.lang.Object
  |
  +--robocode.Condition
Direct Known Subclasses:
GunTurnCompleteCondition, MoveCompleteCondition, RadarTurnCompleteCondition, TurnCompleteCondition

public abstract class Condition
extends Object

Condition is used to define custom waitFor and custom events for a AdvancedRobot. The code below is taken from the sample robot named Target. See Target.java for details.

	  addCustomEvent(
			new Condition("triggerhit") { 
			  public boolean test() {
				  return (getEnergy() <= trigger);
				};
			}
		);
  
You should note that by extending Condition, you are actually creating an inner class -- so if you distribute your robot, there will be multiple class files. (i.e. Target$1.class)

See Also:
AdvancedRobot.waitFor(robocode.Condition), AdvancedRobot.addCustomEvent(robocode.Condition), AdvancedRobot.removeCustomEvent(robocode.Condition), AdvancedRobot.onCustomEvent(robocode.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.
Condition(String name)
          Creates a new Condition with the specified name, and default priority.
Condition(String name, int priority)
          Creates a new Condition with the specified name and priority.
 
Method Summary
 String getName()
           
 int getPriority()
           
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

priority

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


name

public String name
The name of this condition

Constructor Detail

Condition

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


Condition

public Condition(String name)
Creates a new Condition with the specified name, and default priority.


Condition

public Condition(String name,
                 int priority)
Creates a new Condition with the specified name and priority.

Method Detail

getName

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

getPriority

public int getPriority()
Returns:
the priority of this condition

setName

public void setName(String newName)
Sets the name of this condition

Parameters:
newName - java.lang.String

setPriority

public void setPriority(int newPriority)
Sets the priority of this condition

Parameters:
newPriority - int

test

public abstract boolean test()
Overriding the test() method is the point of a Condition. The game will call your test() function, and take action if it returns true. This is valid for both waitFor and addCustomEvent.

You may not take any actions inside of test().

Returns:
true if the condition has been met, false otherwise.