Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## de.farafin.snEADy
Class M_Main

    java.lang.Object
      de.farafin.snEADy.M_Main

All Implemented Interfaces:
  I_Constants, I_PlayFieldConstants, I_GameStats, I_Main_interface

    public final class M_Main

extends java.lang.Object
implements I_Main_interface, I_Constants, I_GameStats, I_PlayFieldConstants

The main is for the organisation of the program. should the game be paused or what should be initialized.. all this is handled by the M_Main. Also the dataflow from gameEngine to the controll interface is lead over main.

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

Field Summary
`private C_LogFileWriter` | `controlLog` logs what was told to the control function from the beginning on.
`private M_GameEngine` | `gameEngine` an instance of the gameEngine module
`private D_GameInfo` | `gameInfo` the game info that the manEngine gets after the play feald changed
`private int` | `gameState` The current game State..
`private M_GraphixEngineUI` | `gui` the instance of the graphic module
`private D_GameInfo` | `initGameInfo` the initial gameInfo. its stored to make it possible to restart teh game.
`private static M_Main` | `instance` the instance of the main Engine.. there is always only one per program
`private boolean` | `lockedControl` if control needs some time, it must be looked, so that nothing bad can happen.. not very clean... sorry
`private C_DebugMonitor` | `monitor` the debug monitor for the player
`private GameParameter` | `parameter` parameter set of GameParameter
`private static int` | `version` Version Number

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`

Fields inherited from interface de.farafin.snEADy.I_GameStats
`GAME_ABBORT, GAME_INIT, GAME_PAUSE, GAME_RECOVER, GAME_RUNNING, GAME_SAFE, PROG_END, PROG_INIT`

Fields inherited from interface de.farafin.snEADy.communication.I_PlayFieldConstants
`EXIT, FIELD_B, FIELD_C, FIELD_D, FIELD_E, FIELD_F, FIELD_G, FIELD_H, FIELD_I, FIELD_J, FIELD_K, FIELD_L, FIELD_M, FIELD_N, FIELD_O, FIELD_P, FIELD_Q, FIELD_R, FIELD_S, FIELD_T, FIELD_U, FIELD_V, FIELD_W, FIELD_X, FIELD_Y, FIELD_Z, FREE, GOODY_f, GOODY_g, GOODY_h, GOODY_i, GOODY_j, GOODY_k, GOODY_l, GOODY_m, GOODY_n, GOODY_o, GOODY_p, GOODY_q, GOODY_r, GOODY_s, GOODY_t, GOODY_u, GOODY_v, GOODY_w, GOODY_x, GOODY_y, GOODY_z, LENGTH, PLAYER_0, PLAYER_1, PLAYER_2, PLAYER_3, PLAYER_4, PLAYER_5, PLAYER_6, PLAYER_7, PLAYER_8, PLAYER_9, POINTS, SHORT, SLOW, SPEED, WALL`

Constructor Summary
`private` | `M_Main()` constructor of M_Main

Method Summary
`boolean` | `control(java.lang.String command)` possible Comments: All commands are posed in the string. without the ',' at the end!
`private void` | `gameRecover(java.lang.String rootPath, java.lang.String fileName)` recover a game with a before safed game.
`private void` | `gameSafe()` Safe the current game
`protected int` | `getGameState()`
`protected static M_Main` | `getInstance()` prevents that more than one instance of the class exists in the program
`D_Level` | `getLevelHeader(java.lang.String levelName)` loads a level without the playfield
`protected C_DebugMonitor` | `getMonitor()`
`protected GameParameter` | `getParameter()`
`java.lang.String` | `getPlayerComment(java.lang.String playerName)`
`private void` | `imergencyPause()`
`private void` | `kill()` kills all threads and ends the program
`private D_Level` | `loadLevel(java.lang.String levelName)` Loads a level of a specified file.
`private java.lang.Class` | `loadPlayerClass(java.lang.String className)`
`private boolean` | `loadScript(java.lang.String root, java.lang.String fileName)`
`static void` | `main(java.lang.String[] args)`
`private void` | `quit(int x)` ends the program
`private void` | `recover(D_RecoverData recoverData)` recover a saved game
`private void` | `startGame(D_GameInfo initData)` starts the game at the beginning, just to say: starts the gameEngine Maincycle
`private void` | `startScript(java.lang.String[] args)` loads and computs the start script.
`protected void` | `update(D_GameInfo gameInfo, C_Human[] humanInstances)` set the gameInfo and updates the graphic
`private void` | `writeResults()` writes the game results to result.log

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### gameEngine

    private M_GameEngine gameEngine

  an instance of the gameEngine module

### gui

    private M_GraphixEngineUI gui

  the instance of the graphic module

### gameInfo

    private D_GameInfo gameInfo

  the game info that the manEngine gets after the play feald changed

### initGameInfo

    private D_GameInfo initGameInfo

  the initial gameInfo. its stored to make it possible to restart teh game.

### gameState

    private int gameState

  The current game State..

### lockedControl

    private boolean lockedControl

  if control needs some time, it must be looked, so that nothing bad can happen.. not very clean... sorry

### controlLog

    private C_LogFileWriter controlLog

  logs what was told to the control function from the beginning on. DO NOT USE AS SCRIPT

### parameter

    private final GameParameter parameter

  parameter set of GameParameter

### instance

    private static M_Main instance

  the instance of the main Engine.. there is always only one per program

### monitor

    private final C_DebugMonitor monitor

  the debug monitor for the player

### version

    private static int version

  Version Number

Constructor Detail

### M_Main

    private M_Main()

  constructor of M_Main

  See Also:
    `getInstance()`

Method Detail

### loadPlayerClass

    private java.lang.Class loadPlayerClass(java.lang.String className)

  Parameters:
    `className` - the name of the class that should be loaded
  Returns:
    an instance of the loaded class or null if the load failed

### getPlayerComment

    public java.lang.String getPlayerComment(java.lang.String playerName)

  Specified by:
    `getPlayerComment` in interface `I_Main_interface`
  Parameters:
    `playerName` - the class of which the comment should be red from
  Returns:
    the comment
  See Also:
    `Player.comment`

### getLevelHeader

    public D_Level getLevelHeader(java.lang.String levelName)

  Description copied from interface: `I_Main_interface`
  loads a level without the playfield

  Specified by:
    `getLevelHeader` in interface `I_Main_interface`
  Parameters:
    `levelName` - the name of the level that should be loaded
  Returns:
    the loaded level, but without the playfield
  See Also:
    `C_LevelLoader`

### loadLevel

    private D_Level loadLevel(java.lang.String levelName)

  Loads a level of a specified file. Also computes errors of the file and the case that the file is not found.

  Parameters:
    `levelName` - the name of the level that should be loaded
  Returns:
    the level

### startGame

    private void startGame(D_GameInfo initData)

  starts the game at the beginning, just to say: starts the gameEngine Maincycle

  Parameters:
    `initData` -

### recover

    private void recover(D_RecoverData recoverData)

  recover a saved game

  Parameters:
    `recoverData` -

### startScript

    private void startScript(java.lang.String[] args)

  loads and computs the start script.

  Parameters:
    `args` - the arguments which are given the program

### loadScript

    private boolean loadScript(java.lang.String root,
                               java.lang.String fileName)

  Parameters:
    `root` -
    `fileName` -
  Returns:
    boolean

### writeResults

    private void writeResults()

  writes the game results to result.log

### update

    protected void update(D_GameInfo gameInfo,
                          C_Human[] humanInstances)

  set the gameInfo and updates the graphic

  Parameters:
    `gameInfo` - the game info that should be used. its only a reference-copy
    `humanInstances` - instances of human player Classes

### gameRecover

    private void gameRecover(java.lang.String rootPath,
                             java.lang.String fileName)

  recover a game with a before safed game.

  Parameters:
    `rootPath` -
    `fileName` -

### gameSafe

    private void gameSafe()

  Safe the current game

### imergencyPause

    private void imergencyPause()

### kill

    private void kill()

  kills all threads and ends the program

### getGameState

    protected int getGameState()

  Returns:
    Returns the gameState.

### getParameter

    protected GameParameter getParameter()

  Returns:
    Returns the parameter.

### getMonitor

    protected C_DebugMonitor getMonitor()

  Returns:
    Returns the monitor.

### getInstance

    protected static M_Main 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

### main

    public static void main(java.lang.String[] args)

  Parameters:
    `args` - main method: should work with arguments

### control

    public boolean control(java.lang.String command)

  possible Comments: All commands are posed in the string. without the ',' at the end!
  - set, the command to set a parameter that can be set at any time
  - For the next two parameter the calculation is equal: if points are computed, the calculation starts in the point a snake losses a segment or dies. and gives all snakes that have at least one segment in the calculation radius its points. it only counts the nearest segment of the snake, and the nearer the segment is, the more points are given. The calculation is for both of the next identical: The distance is defined as Manhatten distance: that meens d = dx + dy. The fields near the center gains points of this amount: 2^(POINTS_..._RADIUS - d)
    If a snake runns into an other snake, the other snake gets additionally the maximum points. the maximum number is 2^(..._POINTS_RADIUS - 1). -1 because the center gets 2^(..._POINTS_RADIUS)
  - set damage_points_radius, the point radius if the head of a snake runns into a wall or other snake. Default is 3; must be >= 1
  - set kill_points_radius, the point radius if a snake is killed. Default is 6; must be >= 0
  - set easy_points, if a snake bites it self, all snakes which touch the snake at any point, gains easy_points number of points. Default is 0; must be >= 0
  - As the bonus points the two parameters above, if snake runns into an other, the other gains extra stuff. But this time, it gains Length. It is a floating point parameter because it should be possible to gain for example 0.5 length each time a Snake runs into an other snake. The value is stored and if its greater than 1 the snake gets the length.
  - set damage_length_grow, the length a snake gets each time an other snake runs into it. Default is 0.5; must be >= 0.0
  - set kill_point_goodies, If a nake dies, it imitats this number of point goodies. each with goody_points_value points. kill_point_goodies is the number of point-goodies that should be spreed out when a snake dies. Default is 5, must be >= 0
  - Because we have a discrete time in that game we need some tricks to reallize different speeds. so we decided to make it this way: each snake can think x times until the body mooves. the thinking times are constant, but the number of thinking times until the body moves can change.
  - set min_move_delay, the minimum number of thinking cycles a snake can have. Default is 2; must be >= 1
  - set init_move_delay, the initial number of thinking cycles a snake can have. Default is 4; it must be true: min_move_delay <= init_move_delay <= max_move_delay
  - set max_move_delay, the maximum number of thinking cycles a snake can have. Default is 6; must be > INIT_SNAKE_DELAY
  - set init_length, the lenth the snake should start with Default is 10
  - set auto_grow_delay, each auto_grow_delay number gameTime cycles, a snake gains one length. if the value is 1, the game is Tron-Style. Default is 20; must be >= 1
  - set auto_slowdown_delay, after auto_slowdown_delay number of gameTime cycles, the snake will get one DELAY-point slower. Default is 1000; must be >= 1
  - set max_goody_occ_delay, the time until the next goody occures is uniform distributed. after a randum number of cycles, the next goody occures on the fied.. Default is 200; must be >= 1
  - To reallize different estimations of wich goodies occures, there is a second uniform distributed random value. The propability of that a goody is placed on the field, is GOODY_.._OCC / (sum of all GOODY_.._OCC)
  - set goody_speed_occ, speed goodies. Default is 2; must be >= 0
  - set goody_slowdown_occ, speed goodies. Default is 1; must be >= 0
  - set goody_length_occ, length goodies. Default is 7; must be >= 0
  - set goody_points_occ, points goodies. Default is 0; must be >= 0
  - set goody_shorter_occ, shorter goodies. Default is 0; must be >= 0
  - set goody_length_value, The length a snake gets each time it eats a length-goody. Default is 20; must be >= 0
  - set goody_points_value, The points a snake gets each time it eats a points-goody. Default is 10; must be >= 0
  - set goody_shorter_value, The length a snake losses each time it eats a shorter-goody. Default is 5; must be >= 0
  - set min_cycle_ms, this is ment for the game with human players. because if each player runns as fast as it can, the game might be very fluctating in its speed. To give the player at least the chacne to react iof the computer calculates very fast, this value is set to a minimum of time in Milliseconds a game cycle will take
    note if there are many player in the field, the game will slow down because there are more player that needs its time ti think. even if you like to run the game as fast as possible, if the player need more time for their calculation, the game might be much slower than min_cycle_ms.
    min_cycle_ms must be less than max_thinking_ms, if it is set to more than max_thinking_ms, max_thinking_ms is set to min_cycle_ms.
    Default is 50, must be >= 1
  - set max_thinking_ms, sets the number of milli-seconds each player should think. this number is indipendent from timeout_ms. it is the time in milliseconds each player should think maximum. This is too the value (de.farafin.snEADy.player.GameInfo.thinkingMS), the player is given for his calculation.
    max_thinking_ms must be bigger than min_cycle_ms and less than timeout_ms. if max_thinking_ms doesnt fit into this intervall, min_cycle_ms bzw timeout_ms is set to max_thinking_ms. Default is 100, must be >= 1
  - set timeout_ms, timeout_ms is the deadline in milliseconds for the player. if the player needs more time than timeout_ms, the player will be kicked. if the value is 0, it will be waited until the player is done with calculation, no kick at all. if timeout is not 0, it must be bigger than max_thinking_ms, if it is not, max_thinking_ms is set to timeout_ms. default is 100, must be >= 0
  - set analyse_ms, At the frist thinking phasis, this time is added to the normal timeout_ms each player has. At the very first thinking phasis (gameTime == 0), the player should be able to analyse the board. This time should be set large enough to make this analyse possible. Default is 10000; must be >= 1.
  - set max_player_memsets the maximum size (in kB) a loaded player is allowed to allocate during the game. if the player takes too much, he will be kicked out of the game. If max_player_mem is set to 0, there will be no check for the player memory. Default is 8192 (= 8MB); must be >= 0
  - set max_mem_check_delay, The mem check is very time consuming, so its not done every cycle. To avoid every bad Idea, the next check time is computed by a random number with uniform distibution. This is the maximum number of Cycles between two checks. Default is 100, must be >= 1
  - set exit_time, sets the number of the gameCycle in which the exit should open. if its not set, it never occurs. Default is 5000, must be >= 0
  - set suddend_time, sets the number of the gameCycle in which the Sudden Death should start. if its not set, it never happends. Default is 7000, must be >= 0
  - set survival_points, the bonus points a snake gets if it survives(reaches the exit). survival_points * the place the snake reaches the exit (the last snake gets most points). Default is 50, must be >= 0
  - set show_subcycles, the graphic can be updated often or not so often. 1: the game field is printed one time after every player thought one time (its updated synchonized with the gameTime)
    0: the game field is printed each time after a player thought
    Default is 0; must be 1 or 0
  - set logging, bool: should logFiles be written for this game? 1 = yes, 0 = no Default is 1; must be 1 or 0
  - set print_calc_ms, if set to 1, the milliseconds each player needed for its moove is printed, else its not printed. Remember, printing everythin into the console consumts a lot of system power. read the player.log if you are interested in a longer simulation. Default is 0; must be 1 or 0
  - set print_player_mem, if set to 1, each time the space of a player is calculated, the result is printed, else its not printed. Default is 0; must be 1 or 0
  - loadplayer player_name, loads a new player with the specified name. The name is the name of the class file of the player. (Linux/Solaris: watch big Letters here!)
  - loadhuman player_name, loads a new human and gives it the name.
  - delplayer number, delets the player with the given number. its the index of the array that is given to gui.
  - delplayer name, deletes the first player with the given name.
  - loadlevel level_name, loads the level with the specified name. The name is the filename of the level. (Linux/Solaris: watch big Letters here!)
  - run, starts the game if it is not running; pauses game if its running and resums if it is pause (realization of the run button)
  - start, starts the game
  - stop, stops the game and returns to the initialization mode, loads the same configuration as it was before the game was started.
  - pause, if the game is running and it should be paused, this function stops the current calculation process. but it is waited until the actual player ends his thinking phases and updates the world one more time. After pause ended, the next cycle starts with the calculation of the next player. If you need an absolute pause at once, use imergancyPause.
  - print, printrs the actual play field into the console
  - quit, ends the program in a gently way, writs log fiels usw.
  - kill, kills the program. no log fiels are written. WARNING: there are depricated methods used!!
  - emergencyPause, pauses the program imidiatly, WARNING: there are depricated methods used!!
  - openmonitor, openes the debug monitor if it isn't still opended.
  - closemonitor, closes the debug monitor if it isn't still closed.

  Specified by:
    `control` in interface `I_Main_interface`
  Parameters:
    `command` - the command that should performed
  Returns:
    if it was sucessfull computed

### quit

    private void quit(int x)

  ends the program

  Parameters:
    `x` - the parameter of exit

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD