|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--java.lang.Thread
|
+--de.uni_paderborn.robots.data.Arena
The arena thread.
| Inner Class Summary | |
private class |
Arena.ExchangeOkThread
This thread ask a robot if the exchange proposal is ok. |
private class |
Arena.ExchangeProposalThread
This thread ask a robot for his exchange proposal. |
private class |
Arena.GetCommandThread
This thread ask a robot for his next command. |
private class |
Arena.RobotTimer
This class is the robot timer thread which controls the robot time. |
| Field Summary | |
private ArenaFrame |
arenaFrame
link to gui |
private Robot[] |
arenaRobotData
contains infos for all playing robots |
private boolean |
debug
true, if debugging is turned on |
private java.lang.String |
debugMessage
used for messageoutput in debugmode |
private int |
delay
delay in ms |
private java.lang.String |
disqMessage
used for gui disqualification messages |
private java.lang.String |
endGameMessage
used for gui showRanking messages |
private Robot[][] |
exchangePairs
contains exchange pairs for card exchange as RobotArray with two Elements |
private boolean |
exitEntered
true if a robot enters exitfield |
private Fields |
fields
reference to Fields object |
private boolean |
gameAborted
true, if game was aborted |
private boolean |
gameActive
true, if game is active (not paused) |
private boolean |
gameRunning
true, if game is running (between start/stop) |
private java.lang.String |
lastException
used to remember last exception |
private int |
noOfExchangePairs
number of computed exchaingePairs every round |
private int |
punishmentAmount
how much energy is decreased if robot runs against an item |
private int |
rechargeAmount
how much energy a well reloads per turn |
private java.util.Iterator |
robotFieldIterator
iterator for robotFields |
private int |
robotIdCounter
number of robots in the game |
private java.util.Iterator |
robotIterator
iterator for robots |
private Robot |
robotOnTheRun
actual robot |
private boolean |
robotReady
true, if robot has answered |
private boolean |
robotThrewException
true, if robot has thrown exception |
private boolean |
robotTimeElapsed
true, if robot time is elapsed |
private boolean[] |
robotTypes
registered robot types |
private boolean |
step
true, if next step is to be performed |
private java.io.StringWriter |
stringWriter
used for exception description |
private int |
turnNo
Number of actual turn |
private Robot[] |
winnerList
stores list of not disqualified robots, sorted regarding their points |
| Fields inherited from class java.lang.Thread |
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ |
| Constructor Summary | |
Arena(Fields fields)
constructor, creates a new arena from the given Fields object. |
|
Arena(java.io.File file)
constructor, creates new arena by loading one arena from the specified file. |
|
Arena(int width,
int height)
constructor, creates empty arena with specified width and height. |
|
| Method Summary | |
void |
abortGame()
Aborts the arena thread instantly!!! |
Robot |
addRobot(RobotFunctions toAdd,
java.lang.String name)
Adds a robot to the game. |
private int[] |
calculateWinner()
Calculates the winner of the game when finished. |
private void |
checkWaitDebug()
Waits if debug mode is active and step button is not pressed yet! |
private void |
checkWaitPause()
Waits if pause mode is active. |
private FieldData |
computeFieldData(Field dummy)
Converts group10 Field and ItemData to RobotArenaInterface datastructures. |
void |
continueGame()
Continues the game. |
private Card |
convertCard(CardData card,
Robot robot)
Converts CardData Object into Card Object, if Robot owns Card. |
private RobotData |
createRobotData(Robot nextInternBot)
Creates a new RobotData object which contains all necessary information for a robot thread to calculate the next command. |
private void |
exchangeManagement()
Performs the card exchange. |
private boolean |
executeCommand(AbstractRobotAction action,
Robot robot)
Excecutes robot command. |
private void |
finalTurn()
Runs a further turn if a robot entered the exit; necessary for the proxy object of group 14. |
int |
getActualTurnNo()
returns the turn No |
ArenaFrame |
getArenaFrame()
Gets ArenaCanvas for this arena. |
int |
getDelay()
Returns the delay. |
private boolean |
getExchangeOk(Robot robot,
CardData hisCard,
CardData otherCard)
This method asks the robot if he agrees to the exchange |
private CardData |
getExchangeProposal(Robot robot)
This method asks the robot for his exchange proposal |
Fields |
getFields()
Returns the internal Fields object (used by ArenaCanvas objects) |
private Field |
getFirstFreeSurroundingField(Field field)
Checks the fields surrounding field and returns the first empty field |
int |
getPunishmentAmount()
Gets the punishment amount. |
int |
getRechargeAmount()
Gets the recharge amount. |
private void |
initGame()
Initializes game. |
private void |
isaRobotActive()
Checks if at least one robot is active (not disqualified and has energy). |
boolean |
isDebuggingOn()
Returns if debug option is on or not. |
boolean |
isGameActive()
Returns if game is active or not. |
boolean |
isGameRunning()
Returns if game is running or not. |
void |
loadArena(java.io.File file)
Loads an arena from a local file into this class. |
private void |
makeExchangeList()
Computes all exchangePairs. |
private Robot[] |
mixRobots()
Creates new random list of robots. |
void |
nextStep()
Executes the next game step, if debugging is turned on. |
int |
numRobotFields()
Returns number of robot fields in the arena. |
int |
numRobots()
Returns number of robots in the arena. |
private void |
oneTurn()
Performs one round of the game: All robot-threads are asked for their next command which is executed immediately if valid. |
void |
pauseGame()
Pauses the game. |
boolean |
removeRobot(Robot toRemove,
boolean replaceByRobotField)
Removes a robot from the game. |
private void |
removeStartFields()
Replaces all RobotFields with empty fields. |
void |
robotDisqualified()
Signal that robot is disqualified |
private void |
robotHasThrownException()
Informs arena thread that robot has thrown an exception. |
private void |
robotIsReady()
Informs arena thread that robot is ready. |
void |
run()
This method controls most parts of the game. |
void |
saveArena(java.io.File file)
Saves an arena to a local file. |
void |
setArenaFrame(ArenaFrame arenaFrame)
Sets ArenaCanvas for this arena. |
void |
setDebugging(boolean debug)
Set the debug option on/off. |
void |
setDelay(int delay)
Sets the delay. |
private void |
setLastException(java.lang.Exception e)
This method sets the last Exception. |
void |
setPunishmentAmount(int punishmentAmount)
Sets the punishment amount. |
void |
setRechargeAmount(int rechargeAmount)
Sets the recharge amount. |
private void |
setRobotTimerIsElapsed()
Informs arena thread that robot timer elapsed. |
private void |
showRanking()
Calculates winner and calls Arenaframe method showRanking(). |
void |
startGame()
Starts the game. |
void |
stopGame()
Stops the game. |
private CardData |
toCardData(Card card)
Converts Card Object into CardData Object |
private void |
waitForRobot()
Waits until robot has answered resp. robot time is elapsed. |
| Methods inherited from class java.lang.Thread |
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
private Fields fields
private boolean gameRunning
private boolean gameActive
private boolean gameAborted
private boolean exitEntered
private boolean debug
private boolean step
private int robotIdCounter
private java.util.Iterator robotFieldIterator
private java.util.Iterator robotIterator
private ArenaFrame arenaFrame
private int delay
private int rechargeAmount
private int punishmentAmount
private int turnNo
private int noOfExchangePairs
private boolean[] robotTypes
private Robot[] arenaRobotData
private Robot[] winnerList
private Robot[][] exchangePairs
private boolean robotReady
private boolean robotTimeElapsed
private boolean robotThrewException
private java.lang.String disqMessage
private java.lang.String endGameMessage
private java.lang.String debugMessage
private java.io.StringWriter stringWriter
private java.lang.String lastException
private Robot robotOnTheRun
| Constructor Detail |
public Arena(int width,
int height)
width - width of arenaheight - height of arenapublic Arena(Fields fields)
fields - the Fields object
public Arena(java.io.File file)
throws java.io.IOException,
java.lang.ClassCastException,
java.lang.ClassNotFoundException
filename - name of file containing arena templatejava.io.IOException - if file cannot be readjava.lang.ClassCastException - if class cannot be type-castedjava.lang.ClassNotFoundException - if necessary class cannot be found| Method Detail |
public void loadArena(java.io.File file)
throws java.io.IOException,
java.lang.ClassCastException,
java.lang.ClassNotFoundException
file - a local filejava.io.IOException - if file cannot be readjava.lang.ClassCastException - if class cannot be type-castedjava.lang.ClassNotFoundException - if necessary class cannot be found
public void saveArena(java.io.File file)
throws java.io.IOException
file - a local filejava.io.IOException - if file cannot be writtenprivate void oneTurn()
private void finalTurn()
private void exchangeManagement()
private CardData getExchangeProposal(Robot robot)
robot - the robot to ask
private boolean getExchangeOk(Robot robot,
CardData hisCard,
CardData otherCard)
robot - the robot to askhisCard - the card he would give awayotherCard - the card he would become from the other robotpublic void run()
run in class java.lang.Threadprivate void removeStartFields()
private void checkWaitPause()
private void checkWaitDebug()
private void waitForRobot()
private Robot[] mixRobots()
private boolean executeCommand(AbstractRobotAction action,
Robot robot)
action - a AbstractAction object returned by robot threadrobot - the current robotprivate Field getFirstFreeSurroundingField(Field field)
field - which has to checked
private Card convertCard(CardData card,
Robot robot)
card - CardData Object to be convertedrobot - Robot whose cards have to be compared with cardprivate CardData toCardData(Card card)
card - Card Object to be convertedprivate RobotData createRobotData(Robot nextInternBot)
nextInternBot - robot for which RobotData should be createdprivate FieldData computeFieldData(Field dummy)
dummy - field to convert, including all referented objectsprivate void makeExchangeList()
private void initGame()
private void isaRobotActive()
private void showRanking()
private int[] calculateWinner()
public void startGame()
public void stopGame()
public void abortGame()
public void pauseGame()
public void continueGame()
public void robotDisqualified()
public boolean removeRobot(Robot toRemove,
boolean replaceByRobotField)
toRemove - reference to the robot, which should be removedreplaceByRobotField - true, if robot field should be placed instead, otherwise the field stays empty
public Robot addRobot(RobotFunctions toAdd,
java.lang.String name)
toAdd - reference to the robot which should be addedname - name of the new robotpublic void setDebugging(boolean debug)
debug - true, if debugging should be turned onpublic void nextStep()
public boolean isDebuggingOn()
public boolean isGameRunning()
public boolean isGameActive()
public int numRobots()
public int numRobotFields()
public Fields getFields()
public void setDelay(int delay)
delay - new delaypublic int getDelay()
public void setArenaFrame(ArenaFrame arenaFrame)
ArenaCanvas - ArenaCanvas for this arenapublic ArenaFrame getArenaFrame()
public void setRechargeAmount(int rechargeAmount)
rechargeAmount - the value of one well usagepublic int getRechargeAmount()
public void setPunishmentAmount(int punishmentAmount)
the - value energy is decreased by if robots runs against an itempublic int getPunishmentAmount()
public int getActualTurnNo()
private void robotIsReady()
private void setRobotTimerIsElapsed()
private void robotHasThrownException()
private void setLastException(java.lang.Exception e)
e - last exception occured
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||