de.farafin.snEADy
Class M_PlayerHandler

java.lang.Object
  extended by de.farafin.snEADy.M_PlayerHandler
All Implemented Interfaces:
I_Constants

public final class M_PlayerHandler
extends java.lang.Object
implements I_Constants

M_PlayerHandler manages the player that should play the game. it is necessary to controll the threads and who is next to calculate.

Version:
$Revision: 1.54 $
Author:
lars, roland

Nested Class Summary
private  class M_PlayerHandler.PlayerInfo
          informations for the player
private  class M_PlayerHandler.PlayerRun
          realize the player handling TODO roland: make it more effective: dont need to make a new insrtance every time!!
 
Field Summary
private  boolean imergencyPaused
          flag if game was imergency paused
private static M_PlayerHandler instance
          Comment for inst
private  int lastPlayer
          Index of the last player who was calculated.
private  int nextMemCheck
          for storing the information of which player should be controlled the space nextMemCheck
private  long nextSizeControllTime
          the gameTime when the next time the size of player should be checked
private  GameParameter parameter
          parameter set of GameParameter
private  long playerCalculationtime
          mesures the time a player needs to calculate its moove.
private  M_PlayerHandler.PlayerInfo playerInfo
          a prototype of playerInfo, so it doesnt need to be a new instance constructed every time.
private  Player[] playerInstances
          Instances of the Player-Classes.
private  C_LogFileWriter playerLog
          a logfile to safe the players moves
private  M_PlayerHandler.PlayerRun playerRun
          the thread of the player who is actually calculated
private  java.lang.Thread playerThread
          the thread of the player who is actually calculated
private  java.util.Random randNumber
          random number generator for controll time
 
Fields inherited from interface de.farafin.snEADy.communication.I_Constants
analyse_ms, auto_grow_delay, auto_slowdown_delay, closemonitor, commandConstants, damage_length_grow, damage_points_radius, DEBUG, delplayer, easy_points, emergencyPause, exit_time, FACE_EAST, FACE_NORTH, FACE_SOUTH, FACE_WEST, goody_length_occ, goody_length_value, goody_points_occ, goody_points_value, goody_shorter_occ, goody_shorter_value, goody_slowdown_occ, goody_speed_occ, IN_ACTION, IN_ERROR_EXC, IN_ERROR_INIT, IN_ERROR_SPACE, IN_ERROR_TIME, IN_EXIT, IN_HEAVEN, init_length, init_move_delay, kill, kill_point_goodies, kill_points_radius, loadhuman, loadlevel, loadplayer, logging, max_goody_occ_delay, MAX_HUMAN_PLAYERS, max_mem_check_delay, max_move_delay, max_player_mem, MAX_PLAYERS, max_thinking_ms, min_cycle_ms, min_move_delay, openmonitor, overalldelay, pause, print_calc_ms, print_parameter, print_player_mem, print_playfield, quit, run, show_subcycles, start, stop, suddend_time, survival_points, timeout_ms, TURN_LEFT, TURN_NONE, TURN_RIGHT
 
Constructor Summary
private M_PlayerHandler()
          default constructor
 
Method Summary
protected  void abbort()
          abborts the game
protected static void destroyInstance(M_PlayerHandler playerHandler)
           
protected static M_PlayerHandler getInstance()
          prevents that more than one instance of the class exists in the program
protected  void imergencyPause()
           
protected  void initGame(Player[] players)
           
protected  void kill()
           
protected  void recover(D_RecoverData recoverData)
           
private  void reGenPlayerInfo(int playerIndex, D_GameInfo gameInfo)
          regenerate Player Info. it is no new instance build, but if the length some arrays doesnt fit, it will be renewed.
protected  void runPlayer(D_GameInfo gameInfo, D_PlayerData[] playerData)
          This methods organizes the player calculation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

playerInstances

private Player[] playerInstances
Instances of the Player-Classes. Its a reference copy from GameEngine.


lastPlayer

private int lastPlayer
Index of the last player who was calculated.


playerRun

private M_PlayerHandler.PlayerRun playerRun
the thread of the player who is actually calculated


playerThread

private java.lang.Thread playerThread
the thread of the player who is actually calculated


instance

private static M_PlayerHandler instance
Comment for inst


imergencyPaused

private boolean imergencyPaused
flag if game was imergency paused


playerInfo

private final M_PlayerHandler.PlayerInfo playerInfo
a prototype of playerInfo, so it doesnt need to be a new instance constructed every time.


playerCalculationtime

private long playerCalculationtime
mesures the time a player needs to calculate its moove.


playerLog

private C_LogFileWriter playerLog
a logfile to safe the players moves


randNumber

private java.util.Random randNumber
random number generator for controll time


nextSizeControllTime

private long nextSizeControllTime
the gameTime when the next time the size of player should be checked


nextMemCheck

private int nextMemCheck
for storing the information of which player should be controlled the space nextMemCheck


parameter

private final GameParameter parameter
parameter set of GameParameter

Constructor Detail

M_PlayerHandler

private M_PlayerHandler()
default constructor

Method Detail

reGenPlayerInfo

private void reGenPlayerInfo(int playerIndex,
                             D_GameInfo gameInfo)
regenerate Player Info. it is no new instance build, but if the length some arrays doesnt fit, it will be renewed.

Parameters:
playerIndex -
gameInfo -

initGame

protected void initGame(Player[] players)
Parameters:
players -

recover

protected void recover(D_RecoverData recoverData)
Parameters:
recoverData -

runPlayer

protected void runPlayer(D_GameInfo gameInfo,
                         D_PlayerData[] playerData)
This methods organizes the player calculation.

Parameters:
gameInfo -
playerData -

abbort

protected void abbort()
abborts the game


imergencyPause

protected void imergencyPause()

kill

protected void kill()

getInstance

protected static M_PlayerHandler getInstance()
prevents that more than one instance of the class exists in the program

Returns:
a new instance if it doesnt already exist, if so, it returns the old one

destroyInstance

protected static void destroyInstance(M_PlayerHandler playerHandler)
Parameters:
playerHandler -