de.uni_paderborn.robots.robotArenaInterface.proxy
Class Proxy

java.lang.Object
  |
  +--de.uni_paderborn.robots.robotArenaInterface.proxy.Proxy
All Implemented Interfaces:
RobotFunctions

public class Proxy
extends java.lang.Object
implements RobotFunctions

This class is the proxy to be integrated between the arena and a robot.

See Also:
RobotFunctions, ProxyFactory

Field Summary
private static java.lang.String arenaName
          The name of the arena.
private  boolean doneSomething
          Indicates that the proxy has executed at least one action.
private static int exchangeState
          The current state of the exchange procedure.
private static int finalRound
          The number of the final round.
private static boolean firstOk
          Remembers the first robot's answer until the end of the exchange procedure.
private static CardData firstProposal
          Remembers the first robot's proposal until the end of the exchange procedure.
private static int firstRobotUID
          Remembers the first robot's UID until the end of the exchange procedure.
private static long gameUID
          A unique identifier for the game.
private static ProxyFactory proxyFactory
          Reference to the ProxyFactory for accessing the database.
private  RobotFunctions robot
          The robot this proxy belongs to.
private  int robotUID
          The unique identifier of the robot.
private static int round
          The number of the current round.
private static CardData secondProposal
          Remembers the second robot's proposal until the end of the exchange procedure.
private static int secondRobotUID
          Remembers the second robot's UID until the end of the exchange procedure.
private static java.util.HashSet servedExchangeRobotUIDs
          The unique identifier pairs of the robots which have taken part in the exchange procedure.
private static java.util.HashSet servedRobotUIDs
          The unique identifiers of the robots which have executed a command in the current round.
static int STATE_WAIT_FOR_FIRST_OK
          State for tracking the exchange procedure.
static int STATE_WAIT_FOR_FIRST_PROPOSAL
          State for tracking the exchange procedure.
static int STATE_WAIT_FOR_SECOND_OK
          State for tracking the exchange procedure.
static int STATE_WAIT_FOR_SECOND_PROPOSAL
          State for tracking the exchange procedure.
private  long timeForLastAction
          The time the robot needed for the last action.
 
Constructor Summary
Proxy(RobotFunctions robot, int robotUID)
          Constructs this class.
 
Method Summary
 boolean exchangeOk(CardData myCard, CardData otherCard)
          Asks the robot if it wants to exchange his card with the card of the other robot.
 CardData exchangeProposal(CardData[] cards)
          Asks the robot if it wants to exchange a card.
 AbstractRobotAction getCommand(RobotData robotData)
          Asks the robot for its next command.
 java.lang.Class getRobotClass()
          Returns the class of the robot this proxy is wrapped around.
 int getRobotUID()
          Returns the unique identifier of the robot this proxy is wrapped around.
 long getTimeForLastAction()
          Returns the time the robot needed for the last action.
(package private) static void init(ProxyFactory pf, java.lang.String an)
          Does the required initialization.
(package private) static void newGame(long gu)
          Does the required initialization for a new game.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

STATE_WAIT_FOR_FIRST_PROPOSAL

public static final int STATE_WAIT_FOR_FIRST_PROPOSAL
State for tracking the exchange procedure. In this state no exchange procedure is active.

STATE_WAIT_FOR_SECOND_PROPOSAL

public static final int STATE_WAIT_FOR_SECOND_PROPOSAL
State for tracking the exchange procedure. In this state the first robot has been asked for its proposal.

STATE_WAIT_FOR_FIRST_OK

public static final int STATE_WAIT_FOR_FIRST_OK
State for tracking the exchange procedure. In this state the second robot has been asked for its proposal.

STATE_WAIT_FOR_SECOND_OK

public static final int STATE_WAIT_FOR_SECOND_OK
State for tracking the exchange procedure. In this state the first robot has been asked for its ok.

finalRound

private static int finalRound
The number of the final round.

exchangeState

private static int exchangeState
The current state of the exchange procedure.

firstRobotUID

private static int firstRobotUID
Remembers the first robot's UID until the end of the exchange procedure.

secondRobotUID

private static int secondRobotUID
Remembers the second robot's UID until the end of the exchange procedure.

firstProposal

private static CardData firstProposal
Remembers the first robot's proposal until the end of the exchange procedure.

secondProposal

private static CardData secondProposal
Remembers the second robot's proposal until the end of the exchange procedure.

firstOk

private static boolean firstOk
Remembers the first robot's answer until the end of the exchange procedure.

proxyFactory

private static ProxyFactory proxyFactory
Reference to the ProxyFactory for accessing the database.

arenaName

private static java.lang.String arenaName
The name of the arena.

gameUID

private static long gameUID
A unique identifier for the game.

round

private static int round
The number of the current round.

servedRobotUIDs

private static java.util.HashSet servedRobotUIDs
The unique identifiers of the robots which have executed a command in the current round.

servedExchangeRobotUIDs

private static java.util.HashSet servedExchangeRobotUIDs
The unique identifier pairs of the robots which have taken part in the exchange procedure.

robotUID

private int robotUID
The unique identifier of the robot.

robot

private RobotFunctions robot
The robot this proxy belongs to.

timeForLastAction

private long timeForLastAction
The time the robot needed for the last action.

doneSomething

private boolean doneSomething
Indicates that the proxy has executed at least one action.
Constructor Detail

Proxy

public Proxy(RobotFunctions robot,
             int robotUID)
Constructs this class.
Parameters:
proxyFactory - reference to the proxy factory (for accessing factory methods)
robot - the robot to wrap the proxy around
arenaName - the name of the arena
gameUID - a unique identifier of the game
Method Detail

init

static void init(ProxyFactory pf,
                 java.lang.String an)
Does the required initialization.

newGame

static void newGame(long gu)
Does the required initialization for a new game.

getCommand

public AbstractRobotAction getCommand(RobotData robotData)
Asks the robot for its next command. If the return value is null, it has to be disqualified by the arena.
Specified by:
getCommand in interface RobotFunctions
Parameters:
robotData - the robot's current data set
Returns:
the action the robot wants to execute

exchangeProposal

public CardData exchangeProposal(CardData[] cards)
Asks the robot if it wants to exchange a card. If the robot does not own the returned card, it has to be disqualified by the arena.
Specified by:
exchangeProposal in interface RobotFunctions
Parameters:
cards - the robot's current hand
Returns:
the card the robot wants to exchange or null otherwise

exchangeOk

public boolean exchangeOk(CardData myCard,
                          CardData otherCard)
Asks the robot if it wants to exchange his card with the card of the other robot.
Specified by:
exchangeOk in interface RobotFunctions
Parameters:
myCard - the robot's card to be exchanged with the other robot's card
otherCard - the other robot's card to be exchanged with the robot's card
Returns:
true if the robot want the cards to be exchanged or false otherwise

getRobotUID

public int getRobotUID()
Returns the unique identifier of the robot this proxy is wrapped around.
Returns:
the unique identifier of the robot

getRobotClass

public java.lang.Class getRobotClass()
Returns the class of the robot this proxy is wrapped around.
Returns:
the class of the robot

getTimeForLastAction

public long getTimeForLastAction()
Returns the time the robot needed for the last action. This value is more precise than any measurement in the arena because of the delay of the database.
Returns:
the time for the last action