de.farafin.snEADy.player
Class Player

java.lang.Object
  extended by de.farafin.snEADy.player.Player
All Implemented Interfaces:
PubConstants, java.io.Serializable
Direct Known Subclasses:
C_Dummy, C_Human

public abstract class Player
extends java.lang.Object
implements PubConstants, java.io.Serializable

This is the basic player class which your player should be extended from. The interface 'Serializable' is necessary for us to controll how much ram-space a player needs. Please implement it in each of your classes, there is not more to do than just implement it, no realization of methods is required. Java gives this interface standard methods which we use for controlling the Players ram-space.

Dies ist die Basisspieler Klasse von welcher der euer Spieler abgeleitet werden soll. Das Interface 'Serializable' ist nötuig, damit wir kontrollieren können wie viel ram-Speicher ein Spieler benutzt. Bitte implementiert dieses Interface in jede eurer Klassen, aber ihr braucht keine Methoden davon zu realisieren. Java gibt Standardmethoden vor, die wir benutzen um den Speicherverbrauch das Spielers festzustellen.

Version:
$Revision: 1.26 $
Author:
roland, lars
See Also:
Serialized Form

Field Summary
static java.lang.String comment
          Overwrite this variable to print it in the player menu.
private  long maxTime
          The maximal amount of time in milliseconds the player is allowed to think.
private  C_DebugMonitor monitor
          This is the small window for debug informations of the player

Dies ist das kleine Fenster für die debug-ausgaben der Spieler.
static java.lang.String name
          This is a static name you should overwride in your own player class.
private  long startTime
          Here is the system time stored at which the players calculation method was started.
private  int turnDirection
          The direction the head of the snake should turn to.
 
Fields inherited from interface de.farafin.snEADy.player.PubConstants
EAST, EXIT, FREE, IN_ACTION, IN_EXIT, IN_HEAVEN, LENGTH, MOVE_EAST, MOVE_NORTH, MOVE_SOUTH, MOVE_WEST, NORTH, PLAYER_0, PLAYER_1, PLAYER_2, PLAYER_3, PLAYER_4, PLAYER_5, PLAYER_6, PLAYER_7, PLAYER_8, PLAYER_9, POINTS, SHORTER, SLOWDOWN, SOUTH, SPEED, TURN_LEFT, TURN_NONE, TURN_RIGHT, WALL, WEST
 
Constructor Summary
Player()
          default constructor
 
Method Summary
protected abstract  void calculate(GameInfo gInfo, LevelInfo lInfo, SnakeInfo[] sInfo, OwnSnakeInfo oInfo)
          This is the method you should implement.
 java.lang.String getName()
           
 int getTurnDirection()
           
protected  long msDone()
          this Method returns the number of milliseconds the player has calculated jet.
protected  long msLeft()
          this Method returns the number of milliseconds the player has left for his calculation.
 void say(java.lang.String str)
          This method prints your string into the debug monitor window.
 void sayNow(java.lang.String str)
          This method prints your string into the debug monitor window.
protected  void setDirection(int dir)
           
 void setMonitor(C_DebugMonitor monitor)
           
protected  void setTurnDirection(int turn)
           
 void startCalculation(GameInfo gInfo, LevelInfo lInfo, SnakeInfo[] sInfo, OwnSnakeInfo oInfo)
          This method is called when the player begins to calculate his next move.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

public static final java.lang.String name
This is a static name you should overwride in your own player class. Please do not write it into your constructor because than it is not possible to print the name in the load dialog.

Dies ist der statische Name eures Spielers den ihr in eurer eigenen Klasse überschreiben solltet. Bitte benutzt nicht den Konstruktor dazu, denn sonst wird der Name nicht im Lade-Dialog angezeigt.

See Also:
Constant Field Values

turnDirection

private int turnDirection
The direction the head of the snake should turn to.

Die Richtung in die sich der Kopf der schlange drehen soll.

See Also:
PubConstants.TURN_LEFT, PubConstants.TURN_NONE, PubConstants.TURN_RIGHT

startTime

private long startTime
Here is the system time stored at which the players calculation method was started. It will be renewed every time the player starts his calculation.

Hier wird die Systemzeit gespeichert an der der Spieler seine Berechnung gestartet hat. Der wert wird jedes mal neu gesetzt wenn der Spieler seine Berechnung startet.


maxTime

private long maxTime
The maximal amount of time in milliseconds the player is allowed to think.

Die maximale Anzahl an Millisekunden, die der Spieler überlegen darf.


monitor

private C_DebugMonitor monitor
This is the small window for debug informations of the player

Dies ist das kleine Fenster für die debug-ausgaben der Spieler.


comment

public static final java.lang.String comment
Overwrite this variable to print it in the player menu.

Überschreibt diese Variable um sie im Player Menü anzuzeigen.

See Also:
Constant Field Values
Constructor Detail

Player

public Player()
default constructor

Method Detail

startCalculation

public final void startCalculation(GameInfo gInfo,
                                   LevelInfo lInfo,
                                   SnakeInfo[] sInfo,
                                   OwnSnakeInfo oInfo)
This method is called when the player begins to calculate his next move. It is an extra method call to compute the start time.

Diese Funktion wird aufgerufen wenn der Spieler seine Berechnung begint. Es wird diese Funktion extra aufgerufen damit die Startzeit berechnet werden kann.

Parameters:
gInfo - game informations
Spiel Informationen
lInfo - level informations
Level Informationen
sInfo - an array of informations about all other snakes in the field.
Ein Array von Informationen über alle anderen Spieler auf dem Spielfeld.
oInfo - Informations about the own Snake
Informationen über die eigene Schlange.
See Also:
GameInfo, LevelInfo, SnakeInfo, OwnSnakeInfo

calculate

protected abstract void calculate(GameInfo gInfo,
                                  LevelInfo lInfo,
                                  SnakeInfo[] sInfo,
                                  OwnSnakeInfo oInfo)
This is the method you should implement. Here it should be decided to which value turnDirection is set. This method will be called for each player in every game cycle.
Diese Methode soll von euch implementiert werden. Es muss nur entschieden werden auf welchen Wert turnDirection gesetzt wird. Die Methode wird für jeden Spieler in jedem game Zyclus ein mal aufgerufen.

Parameters:
gInfo - game informations
Spiel Informationen
lInfo - level informations
Level Informationen
sInfo - an array of informations about all other snakes in the field.
Ein Array von Informationen über alle anderen Spieler auf dem Spielfeld.
oInfo - Informations about the own Snake
Informationen über die eigene Schlange.
See Also:
GameInfo, LevelInfo, SnakeInfo, OwnSnakeInfo

msLeft

protected final long msLeft()
this Method returns the number of milliseconds the player has left for his calculation. Note that that the internal timer of the pc is not very precise and depends on the hardware and operating system.You can estimate a precisition of around 15 - 16 milliseconds.

Diese Methode gibt die Anzahl an Millisekunden zurrück, die der Spieler schon überlegt. Bedenkt bitte, dass die der interne Timer des PC's nicht sehr genau ist und dass die Genauigkeit von Hardware und Betriebssystem abhängig ist. Ihr könnt von einer Genauigkeit von ungefär 15 bis 16 Millisekunden aus gehen.

Returns:
Returns the number of millisecons that are left for calculation.

msDone

protected final long msDone()
this Method returns the number of milliseconds the player has calculated jet. Note that that the internal timer of the pc is not very precise and depends on the hardware and operating system.You can estimate a precisition of around 15 - 16 milliseconds.

Diese Methode gibt die Anzahl an Millisekunden zurrück, die der Spieler schon überlegt. Bedenkt bitte, dass die der interne Timer des PC's nicht sehr genau ist und dass die Genauigkeit von Hardware und Betriebssystem abhängig ist. Ihr könnt von einer Genauigkeit von ungefär 15 bis 16 Millisekunden aus gehen.

Returns:
Returns the number of millisecons which the calculation of the player still runs.

getTurnDirection

public final int getTurnDirection()
Returns:
Returns the turnDirection.

setTurnDirection

protected final void setTurnDirection(int turn)
Parameters:
turn - set the direction the player should turn to.

setDirection

protected final void setDirection(int dir)
Parameters:
dir - set the direction the player should go to.

getName

public final java.lang.String getName()

say

public final void say(java.lang.String str)
This method prints your string into the debug monitor window. Because printing text is very time consumting, the text is stored in a buffer and printed when the player is done with calculation.

Diese Methode gibt einen String in den Debug Monitor aus. Weil textausgaben sehr Zeitintensiv sind, wird der Text in einem Buffer zwischengespeichert und ausgegeben wenn der Spieler seine Berechnung beendet hat.

Parameters:
str - the string that should be printed

sayNow

public final void sayNow(java.lang.String str)
This method prints your string into the debug monitor window. The string is printed directly, without buffering. Note that printing text is very time consumting and your player will have perceptible less time to calculate if you do this too often!

Diese Methode gibt einen String in den Debug Monitor aus. Der String wird direkt ausgegeben, ohne zwischen zu speichern. Bedenke dass Textausgabe sehr Zeitintensiv ist! Der Spieler wird spürbar weniger Zeit für seine Berechnungen haben wenn diese Methode zu oft aufgerufen wird.

Parameters:
str - the string that should be printed

setMonitor

public final void setMonitor(C_DebugMonitor monitor)
Parameters:
monitor - The monitor to set. (not very intresting for the player)