Menu

ENG - Technical documentation - Library functions

Joe

Table of Contents

6 Library functions

The library functions offer additional helping methods.

CardUtil
Offers methods for playing cards like shuffling a pack of cards (Card array) and adding or removing cards to/from the pack.

DiceUtil
Offers methods for rolling the dice.

DiceMove
Implements a move that holds already information about the current dice value.

PlayerCardMap
With this class it is possible to manage cards (Card array) for players. The class offers methods for transforming into XML and back and into a character string for the network communication and back.

PlayerUtil
Some helping methods for working with the players.

ScoreUtil
Offers methods to divide scores and create rankings.

6.2 Graphical functions

ImageUtil
Offers some methods for working with images.

PartUtil
Holds several methods for drawing game material or selecting it on the game field. But also methods for getting the active materials or to multiply single game material.

SimpleStatusBar
A simple status bar that shows the active player and some default messages (status.roundfinished, status.gamefinished).

6.3 Debug games

It is possible to record a game and debug it afterward move by move. For that the GameState has to implement the loading and saving methods (load and save) correct and also needs to implement the methods for translating moves to network strings and back (toNetworkStringMove and fromNetworkStringMove).

To know when a game state has to be saved during logging and has to be loaded during debugging the option record has to be set for the game state in the File for the game configurations. Possible values are game, round and turn and has to be set to that time when the game state is changed by random (e.g. mixing cards).

To activate debugging on a new game the option recordgame has to be activated, e.g by selecting the respective menu item (<item id="settings.recordgame" option="recordgame" type="checkbox"/>). The initial game state is saved in the file recordgame.<gameextension>, the moves are stored in recordmoves.log and all the further gamestates are stored in recordstates.log. When a new game is recorded, the old files are overwritten. To debug a file the recordgame-file has to be loaded.

6.4 Miscellaneous functions

AfiAlgorithms
Offers default methods for implementing an intelligent computer player. At the moment only the Alpha-Beta-Pruning is implemented. The following classes are necessary for it:

  • AiEvaluator: generates possible moves and evaluates the game state.
  • AiMoveInformation: Abstract class for a move information that must be extended by the moves used with the algorithm.
  • AiAnalyzer: is used to gather information about the determination of a computer move. This information can be written into an XML file and visualized with the external program AI Analyzer for tjger games.

Note that the game state (GameState) is cloned for the algorithm and the methods of the AiEvaluator access this virtual game state but other classes like the GameEngine use always the real game state. That is important for methods like isValidMove(...) of the game rules (GameRules) which is called by the algorithm und should therefore use only the given game state and the given move but not information of the GameEngine.

ArrayUtil
Offers some methods to transform lists or arrays into type afflicted arrays. The given lists must consist of objects of the correct type!

ConstantValue
Defines some constant values for tjger. Many of them are only used internal.

GameConfigurationException
Is thrown if the File for the game configurations has errors and the application cannot start.

NetworkUtil
Offers some methods for transforming several arrays or important classes into character strings for the network communication (and back again).

ShortestPathFinder, ShortestPath, ShortestPathMethods
Helping methods to use a default algorithm for calculating a shortest path. Therefore it is necessary to implement the interface ShortestPathMethods or to extend the existing class AbstractShortestPathMethods that already returns some default values.

TimeAction
This class helps to execute a method that shall need a minimum time. This can be used e.g. for computer players that they need longer for thinking and do not perform their move too fast. This class is also used by the GameEngine for starting new rounds or turns delayed. As a TimeAction is a new thread the usage can lead to an inconsistent state e.g. if the game is cancelled. To prevent this every TimeActions is registered to the GameEngine by addTimeAction(...) automatically at the beginning and removed by removeTimeAction(...). Usage:

TimeAction.run(new TimeAction(waitTime) {
  public void doAction() {
    // start the action
  }
  public void afterAction() {
    // delay action
  }
});

XmlUtil
Several methods for converting arrays or important classes into XML nodes and load them again from such a node. Can be used for saving and loading the game state.


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.