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.160 $
- Author:
- roland, lars
Fields inherited from interface de.farafin.snEADy.communication.I_Constants |
analyse_ms, auto_grow_delay, auto_slowdown_delay, autogamespeed, closemonitor, damage_length_grow, damage_points_radius, DEBUG, delplayer, easy_points, ejectreplay, emergencyPause, exit_time, FACE_EAST, FACE_NORTH, FACE_SOUTH, FACE_WEST, game_end, 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, loaddummy, loadhuman, loadlevel, loadplayer, loadscript, logging, max_goody_occ_delay, MAX_HUMAN_PLAYERS, max_mem_check_delay, max_move_delay, max_player_mem, MAX_PLAYERS, max_thinking_ms, memkill, min_cycle_ms, min_move_delay, MOVE_EAST, MOVE_NORTH, MOVE_SOUTH, MOVE_WEST, openmonitor, overalldelay, pause, player_controlling, print_calc_ms, print_parameter, print_player_mem, print_playfield, quit, record, recordname, replay, replay_reverse, replay_stepwidth, replay_stepwise, run, set, show_subcycles, start, stop, suddend_time, survival_points, timekill, tolerance_ms, TURN_LEFT, TURN_NONE, TURN_RIGHT |
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_LAST, GOODY_m, GOODY_n, GOODY_o, GOODY_p, GOODY_q, GOODY_r, GOODY_s, GOODY_START, 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 boolean |
gameHasHuman()
|
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)
|
protected C_DebugMonitor |
getMonitor()
|
protected GameParameter |
getParameter()
|
static int |
getVersion()
|
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 |
loadReplay(java.lang.String root,
java.lang.String fileName)
|
private boolean |
loadScript(java.lang.String root,
java.lang.String fileName)
|
static void |
main(java.lang.String[] args)
|
private void |
nogui(java.lang.String[] args)
|
private void |
quit(int x)
ends the program |
private void |
recover(D_RecoverData recoverData)
recover a saved game |
private void |
startScript(java.lang.String[] args)
loads and computs the start script. |
protected void |
update(D_GameInfo gInfo,
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 |
gameEngine
private M_GameEngine gameEngine
- an instance of the gameEngine 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.
recGameInfo
private D_GameInfo recGameInfo
- the initial record gameInfo. its stored to make it possible to restart the 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
scriptEx
private int scriptEx
- if a script is executed, scriptEx is bigger than 0.
it represents the recursive stack depth of the scripts calls
parameter
private final GameParameter parameter
- parameter set of GameParameter
initParameter
private GameParameter initParameter
- parameter set at the beginning of the game
recParameter
private GameParameter recParameter
- parameter set at the beginning of a recording
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 final int version
- Version Number
- See Also:
- Constant Field Values
gui
private boolean gui
- if set to true, no gui is loaded
oldCycleMS
private int oldCycleMS
- extra for autogamespeed
M_Main
private M_Main()
- constructor of M_Main
- See Also:
getInstance()
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
getLevelHeader
public D_Level getLevelHeader(java.lang.String levelName)
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
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
nogui
private void nogui(java.lang.String[] args)
- Parameters:
args
-
loadScript
private boolean loadScript(java.lang.String root,
java.lang.String fileName)
- Parameters:
root
- fileName
-
- Returns:
- boolean
loadReplay
private boolean loadReplay(java.lang.String root,
java.lang.String fileName)
- Parameters:
root
- fileName
-
- Returns:
- boolean
gameHasHuman
private boolean gameHasHuman()
- Returns:
- returns whether a human is loaded or not.
writeResults
private void writeResults()
- writes the game results to result.log
update
protected void update(D_GameInfo gInfo,
C_Human[] humanInstances)
- set the gameInfo and updates the graphic
- Parameters:
gInfo
- the game info that should be used. its only a reference-copyhumanInstances
- 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 tolerance_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. if max_thinking_ms
doesnt fit , min_cycle_ms is set to max_thinking_ms.
Default is 100, must be >= 1
- set tolerance_ms, tolerance_ms is a tollerance time to give the player more ms than
is actually allowed to calculate. this should prevent "hard" decisions if player are not
guilty for an interruption of its thinking prozess.
default is 0, must be >= 0
- set analyse_ms, At the frist thinking phasis, this time is added to the normal
tolerance_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
- set memkill, if 1, a player needs more memory than allowed, he will be kicked.
Default is 1; must be 1 or 0
- set timekill, if 1, a player needs more time than allowed, he will be kicked.
Default is 1; must be 1 or 0
- set player_controlling, if set to 0, the whole player thread context is skipped.
so the player will run in the main thread. there is no controll at all, the player becomes
a hard part of the program. Default is 1; must be 1 or 0.
- set record, wether the game should be recorded or not. Default is 1; must be 1 or 0.
- set recordname, sets the name to which the record should be stored to.
to avoid overwriting existing replays and easier handling, the actual date and time will
be added to the name.
- set autogamespeed, wether the game speed should be adjusted automatically or not.
if set to 1, min_cycle_ms is set to 50 if a human player is in the filed, otherwise min_cycle_ms
is set to 0. if min_cycle_ms is changed, its atomatically swiched to 0.
Default is 1; must be 1 or 0.
- set game_end, regulates the behavior of the game after a play is finished.
0: game is just paused
1: game is is stoped
2: game is quited
Default is 0; must be 0, 1 or 2.
- 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.
- loaddummy, only for replays. don't use!
- delplayer number, delets the player with the given number.
its the index of the array that is given to M_GraphixEngineUI.
- 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!)
- loadscript script_name, loads a script, please avoid recursive calling of
scripts! The script that should be loaded needs to be placed in the 'scripts' folder
and needs the ending '.script' (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.
- print_playfield, prints the playfield into the monitor.
- print_parameter, prints the game parameter list into the monitor.
- replay replay_name, starts a replay with the given name. The replay
must be placed in the 'replays' folder and must have the ending '.sre'.
Do not try to modify replay files! There are no errorchecks!
- ejectreplay, if a replay was started, this command stops it, and
goes back to the normal game.
- 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
getVersion
public static int getVersion()
- Returns:
- Returns the version.