toroidwars.engine
Class Engine

java.lang.Object
  extended by toroidwars.engine.Engine
All Implemented Interfaces:
java.lang.Runnable

public final class Engine
extends java.lang.Object
implements java.lang.Runnable

Author:
Kent McClymont, Maximillian Dupenois and Maximillian Dupenois

Field Summary
protected  Player neutralPlayer
          The neutral player
protected  Player[] players
          List of players
protected  World world
          Country holder
 
Constructor Summary
Engine(EngineUpdateAPI engineApi)
          Constructor.
 
Method Summary
 void changeGameSetting(java.lang.String key, java.lang.String value)
          Attempts to change the game settings Possible keys are:

game.changeGameSettings

game.turnsPerPlayer

game.turnTimePause

game.initialUnitsPerPlayer

game.maxTurnTime

play.numberOfStrikes
play.useSimpleAttack
play.countriesPerPlayer
play.neutralCountriesPerPlayer
play.maxNumberOfUnitsInCountry
play.maxNumberOfUnitsToTransfer
play.maxNumberOfUnitsToAttack
play.maxNumberOfUnitsToDefend
play.allowUnfriendlyTransfer

 AttackResult computeAttack(Country country, Direction direction, int numberOfUnits)
          Computes an attack result fot a country
 void computeBuild(Country country)
          Works out a build action for a country
 int computeScout(Country country, Direction direction)
          Computes the result for scouting from a particular country
 TransferResult computeTransfer(Country country, Direction direction, int numberOfUnits)
          Computes a transfer turn for a country
static BasePlayer createPlayer(java.lang.Class<? extends BasePlayer> playerClass)
          Calls the constructor for the passed player
 void disqualifyPlayer(Player player, java.lang.String reason)
          Removes a player from the game by giving his countries to the neutral player
 void exit()
          Only method allowed to exit the jvm
 Player getNeutralPlayer()
          Gets the games neutral player
 Player[] getPlayers()
          Gets the player list
 int getTurnLimit()
          Returns the total number of turns
 World getWorld()
          Returns the world (holds the countries)
 void initialiseGame(Player[] players, int turnLimit)
          Sets the game up
 boolean isGameInitialised()
          Returns whether or not the game is initialised
static java.lang.Class<? extends BasePlayer> LoadPlayerClass(java.lang.String location, java.lang.String classPath)
          Load a player class from a jar given the jar location and the player class name, the player class must override BasePlayer
 java.util.HashMap<Player,java.lang.Integer> play()
          Actual play method
 void run()
          Method that runs the game
 void stop()
          Stops the current playing game
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

world

protected World world
Country holder


players

protected Player[] players
List of players


neutralPlayer

protected Player neutralPlayer
The neutral player

Constructor Detail

Engine

public Engine(EngineUpdateAPI engineApi)
       throws GameNotInitialisedException
Constructor. Only one instance of the Engine can be run at any time.

Parameters:
engineApi - the api to be notified for various bit of engine information
Throws:
GameNotInitialisedException - Thrown if there is already an existing engine instance,
Method Detail

exit

public void exit()
Only method allowed to exit the jvm


initialiseGame

public void initialiseGame(Player[] players,
                           int turnLimit)
Sets the game up

Parameters:
players - The players which will be taking part
turnLimit - the total number of turns

getNeutralPlayer

public Player getNeutralPlayer()
Gets the games neutral player

Returns:
The neutral player

getPlayers

public Player[] getPlayers()
Gets the player list

Returns:
the list of all the players for this game (except the neutral player)

getWorld

public World getWorld()
Returns the world (holds the countries)

Returns:
the world

run

public void run()
Method that runs the game

Specified by:
run in interface java.lang.Runnable

stop

public void stop()
Stops the current playing game


getTurnLimit

public int getTurnLimit()
Returns the total number of turns

Returns:
the number of turns

play

public java.util.HashMap<Player,java.lang.Integer> play()
                                                 throws java.lang.Exception
Actual play method

Returns:
Winning players matched to country count
Throws:
java.lang.Exception - for passing to to the engineAPI

disqualifyPlayer

public void disqualifyPlayer(Player player,
                             java.lang.String reason)
Removes a player from the game by giving his countries to the neutral player

Parameters:
player - Player to disqualify
reason - Reason for disqualification

computeBuild

public void computeBuild(Country country)
                  throws CheatingException,
                         BuildActionException,
                         TurnTimedOutException
Works out a build action for a country

Parameters:
country - country on which to build
Throws:
CheatingException
BuildActionException
TurnTimedOutException

computeAttack

public AttackResult computeAttack(Country country,
                                  Direction direction,
                                  int numberOfUnits)
                           throws AttackActionException,
                                  CheatingException,
                                  TurnTimedOutException
Computes an attack result fot a country

Parameters:
country - Country doing the attacking
direction - Direction to attack in
numberOfUnits - Number of units to attack with
Returns:
the attack result
Throws:
AttackActionException
CheatingException
blindrisk.exceptions.AttackActionException - Thrown if your attack was illegal, (too few troops in your country etc...)
TurnTimedOutException
blindrisk.exceptions.CheatingException - Thrown if the country is not yours or if it's already had a turn taken on this go
blindrisk.exceptions.TurnTimedOutException - Thrown if this turn has timed out.

computeScout

public int computeScout(Country country,
                        Direction direction)
                 throws CheatingException,
                        ScoutActionException,
                        TurnTimedOutException
Computes the result for scouting from a particular country

Parameters:
country - Country to scout from
direction - Direction to scout in
Returns:
Number of troops found
Throws:
CheatingException
ScoutActionException
TurnTimedOutException
blindrisk.exceptions.TurnTimedOutException - Thrown if this turn has timed out.

computeTransfer

public TransferResult computeTransfer(Country country,
                                      Direction direction,
                                      int numberOfUnits)
                               throws CheatingException,
                                      TransferActionException,
                                      TurnTimedOutException
Computes a transfer turn for a country

Parameters:
country - Country transferring
direction - Direction tansferring to
numberOfUnits - Number of units to transfer
Returns:
The result from the transfer
Throws:
CheatingException
TransferActionException
blindrisk.exceptions.TransferActionException - thrown if your transfer was illegal (too few units to tranfer etc...)
TurnTimedOutException
blindrisk.exceptions.TurnTimedOutException - Thrown if this turn has timed out.

createPlayer

public static BasePlayer createPlayer(java.lang.Class<? extends BasePlayer> playerClass)
                               throws PlayerCreationException,
                                      IllegalExitException
Calls the constructor for the passed player

Parameters:
playerClass - The player class
Returns:
The instance of the player class
Throws:
PlayerCreationException
IllegalExitException

LoadPlayerClass

public static java.lang.Class<? extends BasePlayer> LoadPlayerClass(java.lang.String location,
                                                                    java.lang.String classPath)
                                                             throws PlayerLoadException
Load a player class from a jar given the jar location and the player class name, the player class must override BasePlayer

Parameters:
location - The location of the jar
classPath - The the canonical name of the player class
Returns:
The player class
Throws:
PlayerLoadException
blindrisk.exceptions.PlayerLoadException - Throw if the player could not be found.

changeGameSetting

public void changeGameSetting(java.lang.String key,
                              java.lang.String value)
                       throws GameSettingsCanNotBeChangedException,
                              InvalidGameSettingException
Attempts to change the game settings Possible keys are:

game.changeGameSettings

game.turnsPerPlayer

game.turnTimePause

game.initialUnitsPerPlayer

game.maxTurnTime

play.numberOfStrikes
play.useSimpleAttack
play.countriesPerPlayer
play.neutralCountriesPerPlayer
play.maxNumberOfUnitsInCountry
play.maxNumberOfUnitsToTransfer
play.maxNumberOfUnitsToAttack
play.maxNumberOfUnitsToDefend
play.allowUnfriendlyTransfer

Parameters:
key - The setting to change
value - String representation of value to change
Throws:
GameSettingsCanNotBeChangedException
blindrisk.exceptions.GameSettingsCanNotBeChangedException - Thrown if the game settings are set to being unchangeable
InvalidGameSettingException

isGameInitialised

public boolean isGameInitialised()
Returns whether or not the game is initialised

Returns:
whether or not the game is initialised