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_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.12 $
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.
private  java.lang.String name
          The name of the player.
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, 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.
protected  void say(OwnSnakeInfo oInfo, java.lang.String str)
          This method prints your string into the debug monitor window.
protected  void sayNow(OwnSnakeInfo oInfo, java.lang.String str)
          This method prints your string into the debug monitor window.
 void setMonitor(C_DebugMonitor monitor)
           
protected  void setName(java.lang.String name)
           
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

private java.lang.String name
The name of the player. This string will be read if it was successfully build an instance of the player. So if you like to have a different playername then you your filename, define that in your constructor.

Der Name des Spielers. Der String wird ausgelesen wenn erfolgreich eine Instanz vom Spieler erzeut wurde. Wenn ihr also in der Anzeige einen anderen Namen als den Dateinamen haben wollte dann setzt ihn in eurem Konstruktor.


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 java.lang.String comment
Overwrite this variable to print it in the player menu.

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

Constructor Detail

Player

public Player()
default constructor

Method Detail

startCalculation

public 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 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 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.

getName

public java.lang.String getName()
Returns:
Returns the name.

setName

protected void setName(java.lang.String name)
Parameters:
name - The name to set.

getTurnDirection

public int getTurnDirection()
Returns:
Returns the turnDirection.

setTurnDirection

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

say

protected void say(OwnSnakeInfo oInfo,
                   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:
oInfo - OwnSnakeInfo, is required to identify the player who prints the text
str - the string that should be printed

sayNow

protected void sayNow(OwnSnakeInfo oInfo,
                      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:
oInfo - OwnSnakeInfo, is required to identify the player who prints the text
str - the string that should be printed

setMonitor

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