|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectCreature
public abstract class Creature
Extend this class to create your own Creature.
Override the run()
method to implement the Creature's
AI. Within that method the following actions are available (each of
which takes some time steps to execute):
Example:
public class Rover extends Creature { public void run() { while (isAlive()) { if (! moveForward()) { attack(); turnLeft(); } } } }
Each creature executes in its own thread. This means that you must be very careful when using static fields to always used threadsafe classes or to access them through synchronized accessor methods.
Morgan McGuire
morgan@cs.williams.edu
Constructor Summary | |
---|---|
protected |
Creature()
Subclass constructors must not invoke any of the parent class methods from their constructor. |
Method Summary | |
---|---|
protected boolean |
attack()
Attack the creature right in front of you. |
protected void |
delay(int n)
Called by creature operations to enforce the time cost of those operations. |
protected int |
distance(java.awt.Point p2)
Returns the manhattan distance from current position to p2. |
static int |
distance(java.awt.Point p1,
java.awt.Point p2)
Returns the manhattan distance between p1 and p2 |
boolean |
equals(java.lang.Object ob)
Uses the pointer comparision from Object. |
java.lang.String |
getAuthorName()
Allows GUI browsers to display your name as author of this creature. |
java.lang.String |
getClassName()
Name of this species of creature. |
java.lang.String |
getDescription()
Allows GUI browsers to display information and credits about your creature. |
Direction |
getDirection()
Direction this creature is facing. |
int |
getId()
Each creature has a unique number that it can use to distinguish itself from others. |
char |
getLabel()
|
java.awt.Dimension |
getMapDimensions()
Returns the size of the map. |
protected java.awt.Point |
getMovePosition()
Same as getMovePosition(int) with the argument n = 1 |
protected java.awt.Point |
getMovePosition(int n)
The coordinates of the next position this Creature will enter if it moves n times, regardless of whether that position is currently empty. |
java.awt.Point |
getPosition()
Returns the position of this Creature. |
int |
getTime()
Returns the number of time steps since the simulation started. |
Type |
getType()
|
int |
hashCode()
Uses the pointer hashCode from Object. |
boolean |
isAlive()
Returns true if this creature is alive. |
protected boolean |
isEnemy(Observation obs)
Returns true if this observation describes a Creature that is not of this species |
protected Observation |
look()
Look forward. |
protected boolean |
moveBackward()
Call to move your creature backward 1 square without changing its facing direction. |
protected boolean |
moveForward()
Call to move your creature forward 1 square. |
Observation |
observeSelf()
Create an observation describing this creature |
void |
run()
Override this method to make your creature think and move. |
static java.lang.String |
toString(java.awt.Point point)
Prints a point to a string concisely. |
protected void |
turnLeft()
Rotate counter-clockwise 90 degrees. |
protected void |
turnRight()
Rotate clockwise 90 degrees. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected Creature()
Method Detail |
---|
protected final void delay(int n)
public final Type getType()
getType
in interface Entity
public final int getTime()
public final java.lang.String getClassName()
public java.lang.String getAuthorName()
public java.lang.String getDescription()
public java.awt.Dimension getMapDimensions()
public final int getId()
public Observation observeSelf()
protected java.awt.Point getMovePosition(int n)
protected java.awt.Point getMovePosition()
getMovePosition(int)
with the argument n = 1
protected boolean isEnemy(Observation obs)
protected int distance(java.awt.Point p2)
public static int distance(java.awt.Point p1, java.awt.Point p2)
public final int hashCode()
hashCode
in class java.lang.Object
public final boolean equals(java.lang.Object ob)
equals
in class java.lang.Object
public final char getLabel()
getLabel
in interface Entity
public void run()
isAlive
or attempt an action and
catch the ConvertedError
.
run
in interface java.lang.Runnable
public final java.awt.Point getPosition()
public final Direction getDirection()
public final boolean isAlive()
public static java.lang.String toString(java.awt.Point point)
protected boolean moveForward()
Simulator.MOVE_FORWARD_COST
time steps.
protected boolean moveBackward()
Simulator.MOVE_BACKWARD_COST
time steps.
protected Observation look()
Takes about Simulator.LOOK_COST
time steps.
The result of the look is accurate at the end of the
delay, but of course whatever is seen might have moved
by the time the creature actually makes its response.
protected void turnLeft()
Simulator.TURN_COST
time
steps.
protected void turnRight()
Simulator.TURN_COST
time steps.
protected boolean attack()
Whether there is a creature present or not, this takes
about Simulator.ATTACK_COST
time steps. The actual
attack occurs at the beginning the delay.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |