cz.cuni.utils
Class TestBot

java.lang.Object
  extended by cz.cuni.pogamut.Client.Agent
      extended by cz.cuni.utils.TestBot
All Implemented Interfaces:
RcvMsgListener, Introspectable, java.lang.Runnable, java.util.EventListener

public class TestBot
extends Agent

PLAYGROUND for the platform testers :-) This bot contains a lot of code and isn't that stupid at all! This is the Hunter. It collects weapons in map, runs for medkits when it's health is low, trying to kill anybody from different team on sight. Well it's not clever as it doesn't trying to follow it's prey around the corner. And that is where you can step in and start to play with our platform!

derived from AdvancedBot

Plan / if-then rules organization:

  1. do you see enemy and possess better weapon? -> go to CHANGE_WEAPON (change to better weapon)
  2. do you see enemy? -> go to ENGAGE (start shooting / hunt the enemy / change weapon)
  3. are you shooting? -> go to STOP_SHOOTING (stop shooting, you've lost your target)
  4. are you being shot? -> go to HIT (turn around - try to find your enemy)
  5. are you walking? -> go to WALKING (check WAL)
  6. are you following enemy? -> go to PURSUE (run to enemy last position)
  7. do you see item? -> go to GRAB_ITEM (pick the most suitable item and run for it)
  8. are you hurt? -> go to MED_KITS (run around list of Health items - MedKits, HealthVials)
  9. have nothing to do? -> go to RUN_AROUND_ITEMS (randomize array of known items and run around those items using GET_PATH)
Each state you see here can be found in method - stateXXX.

It doesn't look hard, but it's not so simple - check out respective methods for those states and then think about how you could improve this Hunter.

Hunter is also counting it's deaths and frag for itself.


Field Summary
 int deaths
          how many times the hunter died
private  Player enemy
          the enemy we're fixed at.
 int frags
          how many bot the hunter killed
 int healthLevel
          how low the health level should be to start collecting healht
protected  Item choosenItem
          choosen item for the state seeItem
protected  java.util.ArrayList<Item> choosenMedKits
          choose med kits for the stateMedKit
private  java.util.ArrayList<Item> itemsToRunAround
          is used to store shuffled list of weapons bot runs around
private  boolean jumped
          walking mystic properties - prevent bot from continuous jumping - he will jump only once
private  Player lastEnemy
          last enemy which disappeared from agent's view
protected  int MAX_ATTEMPTS
          max attempts in reaching the item
protected  Item previousChoosenItem
          Stores last unreachable item - item that bot chose and was not able to go to.
 boolean shouldCollectHealth
          boolean switch to activate collect health
 boolean shouldCollectItems
          boolean switch to activate collect items
 boolean shouldEngage
          boolean switch to activate engage
 boolean shouldPursue
          boolean switch to activate pursue
 boolean shouldRearm
          boolean switch to activate rearm
 boolean useAStar
          use built-in A* algorithm or not use built-in A* algorithm?
protected  int walkingAttempts
          counter for attempts in reaching the item
 
Fields inherited from class cz.cuni.pogamut.Client.Agent
bindedParserType, body, flagLogicTemporalyStopped, gameBotConnection, gameMap, GARBAGE_COLLECTOR_FREQUENCY, instancesAlive, iterationEndListeners, log, logicFrequency, logicFrequencyChanged, memory, oldLogicFrequency, parserLogger, pauseHolders, platformLog, random, rawGBLog
 
Constructor Summary
TestBot()
           
 
Method Summary
protected  boolean canRunAlongMedKit()
          checks whether there are any medkit items around and if there are checks if the agent is not standing on the first one in the choosenMedKits (bot got stucked because nearestHealth returns Healths according to inventory spots not to the current situation, so the bot with low health got stucked on the inventory spot)
protected  void doLogic()
          Main method of the bot's brain - we're going to do some thinking about the situation we're in (how it's unfair to be the bot in the gloomy world of UT2004 :-).
protected  boolean hasBetterWeapon()
          has better weapon - this magic check goes through weapons in inventory and according to their characteristics decides which is the best - that means which effectiveDistance is lowest and which maximal distance is big enough to reach enemy.
private  Item chooseItem()
          Reasoning about what to do with seen item
the easiest way of handeling it will be just to take it every time, but what should we do when there are many of items laying in front of agent?
private  Weapon chooseWeapon()
          choose weapon according to the one he is currently holding has melee and see ranged => pick up ranged has ranged and see melee => pick up melee pick up first weapon he sees
static void main(java.lang.String[] Args)
           
protected  void postPrepareAgent()
          Prepares list of agent will run around.
protected  void prePrepareAgent()
          prepares agent logic to run - like initializing neural networks etc.
 void receiveMessage(RcvMsgEvent e)
          This is method from interface RcvMsgListener, every message that goes from GB2004 to Agent goes also through here.
private  boolean seeAnyReachableItemAndWantIt()
          sees reachable item and wants it
protected  void stateEngage()
          Fired when bot see any enemy.
protected  void stateGoAtLastEnemyPosition()
          State pursue is for pursuing enemy who was for example lost behind a corner.
protected  void stateHit()
          Fired when bot is damaged, it has those options: He has idea where to turn to from to DAM message He got no idea at all -> turns around
protected  void stateChangeToBetterWeapon()
          changes to better weapon that he posseses
protected  void stateMedKit()
          runs along healths of strenght at least 8 to recover health
protected  void stateRunAroundItems()
          call predefined function in GameMap - runAroundWeaponsInTheMap
protected  void stateSeeItem()
          run along the path to choosen item
protected  void stateStopShooting()
          Fired when bot loose enemy from his view
He just stops shooting and no more wastes his ammo
protected  void stateWalking()
          Fired when bot is moving, checks few accidents than can happen to him Wall collision Fell of the bot Bump to another actor of the game
 
Methods inherited from class cz.cuni.pogamut.Client.Agent
addIterationEndListener, bindLocalParser, bindRemoteParser, clearListeners, disconnect, finalize, getBindedParserType, getBody, getCommunicationState, getFlagLogicTemporalyStopped, getIntrospectableProxy, getLogger, getLogicThread, getMap, getMediator, getMemory, getMilisecToSleep, getName, getPlatformLog, getRawDataLog, initBody, initGameMap, initLogging, initMemory, isRunning, logicReady, pauseLogic, removeIterationEndListener, resumeLogic, run, sendMessageToGB, setFlagLogicTemporalyStopped, setLogicStartLatch, shutdownAgent, startAgent, startAgent, stopAgentSoft
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

choosenItem

protected Item choosenItem
choosen item for the state seeItem


choosenMedKits

protected java.util.ArrayList<Item> choosenMedKits
choose med kits for the stateMedKit


itemsToRunAround

private java.util.ArrayList<Item> itemsToRunAround
is used to store shuffled list of weapons bot runs around


lastEnemy

private Player lastEnemy
last enemy which disappeared from agent's view


enemy

private Player enemy
the enemy we're fixed at. If null no enemy is engaged.


MAX_ATTEMPTS

protected final int MAX_ATTEMPTS
max attempts in reaching the item

See Also:
Constant Field Values

previousChoosenItem

protected Item previousChoosenItem
Stores last unreachable item - item that bot chose and was not able to go to.
This setting should prevent bot from stucks.


walkingAttempts

protected int walkingAttempts
counter for attempts in reaching the item


jumped

private boolean jumped
walking mystic properties - prevent bot from continuous jumping - he will jump only once


useAStar

public boolean useAStar
use built-in A* algorithm or not use built-in A* algorithm? that is a question


shouldEngage

public boolean shouldEngage
boolean switch to activate engage


shouldPursue

public boolean shouldPursue
boolean switch to activate pursue


shouldRearm

public boolean shouldRearm
boolean switch to activate rearm


shouldCollectItems

public boolean shouldCollectItems
boolean switch to activate collect items


shouldCollectHealth

public boolean shouldCollectHealth
boolean switch to activate collect health


healthLevel

public int healthLevel
how low the health level should be to start collecting healht


frags

public int frags
how many bot the hunter killed


deaths

public int deaths
how many times the hunter died

Constructor Detail

TestBot

public TestBot()
Method Detail

prePrepareAgent

protected void prePrepareAgent()
Description copied from class: Agent
prepares agent logic to run - like initializing neural networks etc. not for establishing communication!

Overrides:
prePrepareAgent in class Agent

postPrepareAgent

protected void postPrepareAgent()
Prepares list of agent will run around.
He will run only around weapons and armors so he will be armored and armed soon

Overrides:
postPrepareAgent in class Agent

doLogic

protected void doLogic()
Main method of the bot's brain - we're going to do some thinking about the situation we're in (how it's unfair to be the bot in the gloomy world of UT2004 :-).

Check out the javadoc for this class - there you find a basic concept of this bot.

Overrides:
doLogic in class Agent

stateChangeToBetterWeapon

protected void stateChangeToBetterWeapon()
changes to better weapon that he posseses


hasBetterWeapon

protected boolean hasBetterWeapon()
has better weapon - this magic check goes through weapons in inventory and according to their characteristics decides which is the best - that means which effectiveDistance is lowest and which maximal distance is big enough to reach enemy.

Note!: Both effective and maximal distance are guessed and therefore could not work exactly


stateEngage

protected void stateEngage()
Fired when bot see any enemy.
  1. if have enemyID - checks whether the same enemy is visible, if not, drop him (and stop shooting)
  2. if doesn't have enemyID - pick one of the enemy for pursuing
  3. if not shooting at enemyID - start shooting
  4. if out of ammo - switch to another weapon
  5. if enemy is reachable - run to him
  6. if enemy is not reachable - stand still (kind a silly, right? :-)


stateStopShooting

protected void stateStopShooting()
Fired when bot loose enemy from his view
He just stops shooting and no more wastes his ammo


stateHit

protected void stateHit()
Fired when bot is damaged, it has those options:
  1. He has idea where to turn to from to DAM message
  2. He got no idea at all -> turns around


stateWalking

protected void stateWalking()
Fired when bot is moving, checks few accidents than can happen to him
  1. Wall collision
  2. Fell of the bot
  3. Bump to another actor of the game


stateGoAtLastEnemyPosition

protected void stateGoAtLastEnemyPosition()
State pursue is for pursuing enemy who was for example lost behind a corner. How it works?:
  1. initialize properties
  2. obtain path to the enemy
  3. follow the path - if it reaches the end - set lastEnemy to null - bot would have seen him before or lost him once for all


canRunAlongMedKit

protected boolean canRunAlongMedKit()
checks whether there are any medkit items around and if there are checks if the agent is not standing on the first one in the choosenMedKits

(bot got stucked because nearestHealth returns Healths according to inventory spots not to the current situation, so the bot with low health got stucked on the inventory spot)

Returns:
true if bot can run along med kits - initialize them before that

stateMedKit

protected void stateMedKit()
runs along healths of strenght at least 8 to recover health


chooseWeapon

private Weapon chooseWeapon()
choose weapon according to the one he is currently holding
  1. has melee and see ranged => pick up ranged
  2. has ranged and see melee => pick up melee
  3. pick up first weapon he sees

Returns:
the choosen one weapon

chooseItem

private Item chooseItem()
Reasoning about what to do with seen item
the easiest way of handeling it will be just to take it every time, but what should we do when there are many of items laying in front of agent?
  1. choose weapon - choose the type he is lacking (melee/ranged)
  2. choose armor
  3. choose health - if the health is bellow normal maximum
  4. choose ammo - if it is suitable for possessed weapons
  5. ignore the item


seeAnyReachableItemAndWantIt

private boolean seeAnyReachableItemAndWantIt()
sees reachable item and wants it

Returns:
true if there is an item which is useful for agent

stateSeeItem

protected void stateSeeItem()
run along the path to choosen item


stateRunAroundItems

protected void stateRunAroundItems()
call predefined function in GameMap - runAroundWeaponsInTheMap


receiveMessage

public void receiveMessage(RcvMsgEvent e)
This is method from interface RcvMsgListener, every message that goes from GB2004 to Agent goes also through here. We're using it to count the frags and deaths of the hunter.

Specified by:
receiveMessage in interface RcvMsgListener
Overrides:
receiveMessage in class Agent

main

public static void main(java.lang.String[] Args)
                 throws java.net.URISyntaxException,
                        java.lang.InterruptedException
Throws:
java.net.URISyntaxException
java.lang.InterruptedException