com.ibm.ruler
Class Ruler

java.lang.Object
  |
  +--com.ibm.ruler.Ruler
All Implemented Interfaces:
IRuler
Direct Known Subclasses:
MyRuler

public abstract class Ruler
extends java.lang.Object
implements IRuler

This class is the superclass of the Ruler that you implement. This class contains helper methods to find out about the state of the world.


Field Summary
static int MOVE_E
           
static int MOVE_N
           
static int MOVE_NE
           
static int MOVE_NONE
           
static int MOVE_NW
           
static int MOVE_S
           
static int MOVE_SE
           
static int MOVE_SW
           
static int MOVE_W
           
 
Method Summary
 void capture(IKnight knight, int direction)
          Order the specified knight to capture in the given direction.
 void createKnights(ICastle castle)
          Order the specified castle to start producing new knights.
 void createPeasants(ICastle castle)
          Order the specified castle to start producing new peasants.
 ICastle[] getCastles()
          Returns the castles owned by this ruler.
 IKnight[] getKnights()
          Returns this ruler's knights.
 int getOwnedLandCount()
          Returns the number of squares of land this ruler currently owns.
 IPeasant[] getPeasants()
          Returns this ruler's peasants.
 int getPoints()
          Returns the number of points that this ruler has accumulated during this match.
abstract  java.lang.String getRulerName()
          Return the name of your ruler.
abstract  java.lang.String getSchoolName()
          Return the name of your school.
abstract  void initialize()
          Called to give you a chance to do initialization.
 void move(IKnight knight, int direction)
          Order the specified knight to move in the given direction.
 void move(IPeasant peasant, int direction)
          Order the specified peasant to move in the given direction.
abstract  void orderSubjects(int lastMoveTime)
          This method is called each turn to allow you to give orders to your peasants, knights, and castles.

Method Detail

capture

public final void capture(IKnight knight,
                          int direction)
Order the specified knight to capture in the given direction. If there is a peasant, knight or castle from an opposing ruler in the square in the specified direction, the knight will attempt to capture it. If the square is empty, the knight will not do anything. The knight's location will not change in either case.

Parameters:
knight - - The knight to give the order to
direction - - The direction the knight should capture in

createKnights

public final void createKnights(ICastle castle)
Order the specified castle to start producing new knights. The castle will produce knights faster when the ruler has more land.

Parameters:
castle - - The castle to give the order to

createPeasants

public final void createPeasants(ICastle castle)
Order the specified castle to start producing new peasants. The castle will produce peasants faster when the ruler has more land.

Parameters:
castle - - The castle to give the order to

getCastles

public final ICastle[] getCastles()
Description copied from interface: IRuler
Returns the castles owned by this ruler. If the ruler has no castles, an empty array will be returned.

Specified by:
getCastles in interface IRuler
Returns:
com.ibm.ruler.ICastle[]

getKnights

public final IKnight[] getKnights()
Description copied from interface: IRuler
Returns this ruler's knights. If the ruler has no knights, an empty array will be returned.

Specified by:
getKnights in interface IRuler
Returns:
com.ibm.ruler.IKnight[]

getOwnedLandCount

public final int getOwnedLandCount()
Description copied from interface: IRuler
Returns the number of squares of land this ruler currently owns.

Specified by:
getOwnedLandCount in interface IRuler
Returns:
int

getPeasants

public final IPeasant[] getPeasants()
Description copied from interface: IRuler
Returns this ruler's peasants. If the ruler has no peasants, an empty array will be returned.

Specified by:
getPeasants in interface IRuler
Returns:
com.ibm.ruler.IPeasant[]

getPoints

public final int getPoints()
Description copied from interface: IRuler
Returns the number of points that this ruler has accumulated during this match.

Specified by:
getPoints in interface IRuler
Returns:
int

getRulerName

public abstract java.lang.String getRulerName()
Return the name of your ruler. This method will only be called once during initialization.

Specified by:
getRulerName in interface IRuler
Returns:
java.lang.String

getSchoolName

public abstract java.lang.String getSchoolName()
Return the name of your school. This method will only be called once during initialization.

Specified by:
getSchoolName in interface IRuler
Returns:
java.lang.String

initialize

public abstract void initialize()
Called to give you a chance to do initialization. This method will be called at the beginning of each match, and you will have a limited amount of time to do initialization. All of your objects and your opponents' objects will already exist.


move

public final void move(IKnight knight,
                       int direction)
Order the specified knight to move in the given direction. If the square is empty (does not contain a peasant, knight, or castle), the knight will move to the adjacent square. Knights do not claim land like peasants.

Parameters:
knight - - The knight to give the order to
direction - - The direction that the knight should move

move

public final void move(IPeasant peasant,
                       int direction)
Order the specified peasant to move in the given direction. If the square is empty (does not contain a peasant, knight, or castle), the peasant will move to the adjacent square. If the square that it moves into is not already claimed by your ruler, the peasant will claim the land.

Parameters:
peasant - - The peasant to give the order to
direction - - The direction that the peasant should move

orderSubjects

public abstract void orderSubjects(int lastMoveTime)
This method is called each turn to allow you to give orders to your peasants, knights, and castles. The parameter specifies the length of time (in ms) that the last call to orderSubjects() took. (The first time that this method is called, lastMoveTime is -1)