cz.cuni.pogamut.Client
Class GameMap

java.lang.Object
  extended by cz.cuni.pogamut.Client.GameMap
All Implemented Interfaces:
Navigation, RcvMsgListener, java.util.EventListener

public class GameMap
extends java.lang.Object
implements RcvMsgListener, Navigation

GameMap provides simple navigation information e.g. nearest navigation point, path to specified object

it also integrates AStar algorithm and use it to answer request for get path. this option is valid only for paths to NavPoints and Items, paths to players are solved using Gamebot API


Field Summary
private  AgentBody body
          poiter to body to use things like getPath(), knownObjects, addListener etc.
protected  AgentMemory memory
          pointer to the memory - used by getPathAStar() and other memory related topics - like getPathToClosestMedKit etc.
private  Item nextItem
          next item bot has to go
private  int nextItemIndex
          next item index in itemsToRunAround
 PathManager pathManager
           
protected  java.util.logging.Logger platformLog
          logger for logging any messages for debugging etc.
(package private)  int tempCounter
           
 
Constructor Summary
GameMap(java.util.logging.Logger logger, AgentBody body, AgentMemory memory)
          END OF VARIABLES FOR runAroundItemsInTheMap
 
Method Summary
 boolean antiStuckCheck(Triple goal)
          check two things: 1) agent's velocity - size of vector greater than 50 UT units 2) agent is heading to the location - distance from the location is greater about 50 UT units than distance from object after adding agent's velocity vector to location vector - if this method fails - delete the edge in the graph for A*
 boolean atLocation(Triple location)
           
 boolean atLocation(Triple location, int epsilon)
           
 java.util.ArrayList<NavPoint> getNavPointsAStar(AStarResult result)
          auxiliary A* method
converts AStarResult to ArrayList of NavPoints which is then used as path in runAlongItemsInTheMap
 AStarResult getPathAStar(NavPoint toWhat)
          Returns path from your current position to the 'toWhat' or null if path doesn't exist.
 AStarResult getPathAStar(NavPoint toWhat, int maxNumOfIterations)
          Returns path from your current position to the 'toWhat' or null if path doesn't exist.
 java.util.ArrayList<NavPoint> getPathOfID(int ID)
          Method for obtaining the path returned by GB due to the GETPATH request sent through sendGetPath(navPoint, pathID).
 java.util.ArrayList<NavPoint> getPathToLocation(Triple location)
          obtain path to specified location keeps returning null until path is received don't forget to initialize it - initializeGetPath should be called prior this method
 void initializeGetPath()
          Deprecated.  
 java.util.ArrayList<Item> nearestHealth(int strength, int numberOfHealths)
          very basic method for getting healths of strenght greater or equal to strenght numberOfHealths specifies how many do you want for more complex and more efficient way of doing this use something else think about map preprocessing and more efficient methods of search through the space (than using AStar numerous times) note, it uses restricted AStar - restricted number of iterations, so it can find nothing!
 java.util.ArrayList<Item> nearestItems(MessageType type, int numberOfItems)
          very basic method for getting restricted number of closest items of specified type for more complex and more efficient way of doing this use something else think about map preprocessing and more efficient methods of search through the space (than using AStar numerous times) note, it uses restricted AStar - restricted number of iterations, so it can find nothing!
 NavPoint nearestNavPoint(Triple from)
          Finds nearest navPoint - presume that the agent doesn't see any, so it uses this unefficient method needs Triple from as a parameter
 NavPoint nearestNavPoint(Triple from, int minDistance)
          Finds nearest navPoint - presume that the agent doesn't see any, so it uses this unefficient method counts only those in bigger distance than specified needs Triple from as a parameter
 void receiveMessage(RcvMsgEvent e)
          add message to collected paths (adds)
FIFO fashion adds at the beginning removes from the end
 void restartMap()
          method which restarts game map instance - restart necessary variables
 boolean runAlongPath()
          method to follow smoothly desired path - list of navigation points obtained from game map can handle movers - wait on it until top and leave note that movers in the way are in this fashion: - LiftExit -> LiftCenter -> LiftExit so as agent is supposed to go up when he is supposed to go to LiftCenter (therefore is around first LiftExit) he waits for mover to be about his level and then goes on it, wait to level with second LiftExit and move on
 void runAroundItemsInTheMap(java.util.List<? extends Item> itemsToRunAround, boolean AStar)
          run around items in the map is a complex method which covers behavior which runs around the map according to specified list of items, it works in the following fashion: 1) nextItem == null => shuffle itemsToRunAround, choose first one 2) path == null => obtain path 3) run along the path 4) if the run along fails or if bot reaches the item, switch to next on
 boolean safeRunToLocation(Triple location)
          safely navigates agent to the location of choosen item (could be anywhere). moreover you can set the distance at which agent will stop when reaching last point of the path (by setting GameMapSettings.lastNavigationPointOfPathPrecision) it should be I think at least 5 as I think it is not guaranteed that bots moves precisely.
 void sendGetPathToLocation(int ID, Triple toWhat)
          This method sends GETPATH query to GameBots - you have to provide PathID under which the path will be returned by GB and stored in GameMap instance.
 void sendGetPathToNavPoint(NavPoint toWhat)
          This method sends GETPATH query to GameBots - you have to provide PathID under which the path will be returned by GB and stored in GameMap instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

platformLog

protected java.util.logging.Logger platformLog
logger for logging any messages for debugging etc.


body

private AgentBody body
poiter to body to use things like getPath(), knownObjects, addListener etc.


memory

protected AgentMemory memory
pointer to the memory - used by getPathAStar() and other memory related topics - like getPathToClosestMedKit etc.


nextItem

private Item nextItem
next item bot has to go


nextItemIndex

private int nextItemIndex
next item index in itemsToRunAround


pathManager

public PathManager pathManager

tempCounter

int tempCounter
Constructor Detail

GameMap

public GameMap(java.util.logging.Logger logger,
               AgentBody body,
               AgentMemory memory)
END OF VARIABLES FOR runAroundItemsInTheMap

Method Detail

nearestHealth

public java.util.ArrayList<Item> nearestHealth(int strength,
                                               int numberOfHealths)
very basic method for getting healths of strenght greater or equal to strenght numberOfHealths specifies how many do you want

for more complex and more efficient way of doing this use something else think about map preprocessing and more efficient methods of search through the space (than using AStar numerous times)

note, it uses restricted AStar - restricted number of iterations, so it can find nothing!

Specified by:
nearestHealth in interface Navigation
Returns:
list of healths ordered according to distance from the player (using built-in AStar to figure that out)

nearestItems

public java.util.ArrayList<Item> nearestItems(MessageType type,
                                              int numberOfItems)
very basic method for getting restricted number of closest items of specified type

for more complex and more efficient way of doing this use something else think about map preprocessing and more efficient methods of search through the space (than using AStar numerous times)

note, it uses restricted AStar - restricted number of iterations, so it can find nothing!

Specified by:
nearestItems in interface Navigation
Returns:
list of healths ordered according to distance from the player (using built-in AStar to figure that out)

nearestNavPoint

public NavPoint nearestNavPoint(Triple from)
Finds nearest navPoint - presume that the agent doesn't see any, so it uses this unefficient method

needs Triple from as a parameter

Specified by:
nearestNavPoint in interface Navigation
Parameters:
from - - most often agent location
Returns:
NavPoint - nearest NavPoint

nearestNavPoint

public NavPoint nearestNavPoint(Triple from,
                                int minDistance)
Finds nearest navPoint - presume that the agent doesn't see any, so it uses this unefficient method

counts only those in bigger distance than specified

needs Triple from as a parameter

Specified by:
nearestNavPoint in interface Navigation
Parameters:
from - - usualy agent location
Returns:
NavPoint - nearest NavPoint

atLocation

public boolean atLocation(Triple location)
Parameters:
location - - location bot is heading to, comparing to
Returns:
true if bot is about 10 unreal units from the provided location

atLocation

public boolean atLocation(Triple location,
                          int epsilon)
Parameters:
location - - location bot is heading to, comparing to
epsilon - - a distance in UT units from which bot starts to be at the location
Returns:
true if bot is about "epsilon" unreal units from the provided location

sendGetPathToNavPoint

public void sendGetPathToNavPoint(NavPoint toWhat)
This method sends GETPATH query to GameBots - you have to provide PathID under which the path will be returned by GB and stored in GameMap instance.
Use getPathOfID(pathID) for retrieval.

Specified by:
sendGetPathToNavPoint in interface Navigation
Parameters:
toWhat - - target (NavPoint) of the request

sendGetPathToLocation

public void sendGetPathToLocation(int ID,
                                  Triple toWhat)
This method sends GETPATH query to GameBots - you have to provide PathID under which the path will be returned by GB and stored in GameMap instance.
Use getPathOfID(pathID) for retrieval.

Specified by:
sendGetPathToLocation in interface Navigation
Parameters:
ID - - id which is ment to be returned with query, toWhat - location (triple)

getPathOfID

public java.util.ArrayList<NavPoint> getPathOfID(int ID)
Method for obtaining the path returned by GB due to the GETPATH request sent through sendGetPath(navPoint, pathID).
Note that it takes some time to resolve the GETPATH query.

Specified by:
getPathOfID in interface Navigation
Parameters:
ID -
Returns:
Path or null if ID does not exists

getPathAStar

public AStarResult getPathAStar(NavPoint toWhat,
                                int maxNumOfIterations)
Returns path from your current position to the 'toWhat' or null if path doesn't exist.

Specified by:
getPathAStar in interface Navigation
Returns:
Collection of instances of NavPoint

getNavPointsAStar

public java.util.ArrayList<NavPoint> getNavPointsAStar(AStarResult result)
auxiliary A* method
converts AStarResult to ArrayList of NavPoints which is then used as path in runAlongItemsInTheMap

Specified by:
getNavPointsAStar in interface Navigation
Parameters:
result - - AStarResult
Returns:
list of navigation points which define path to object

getPathAStar

public AStarResult getPathAStar(NavPoint toWhat)
Returns path from your current position to the 'toWhat' or null if path doesn't exist.

Specified by:
getPathAStar in interface Navigation
Returns:
Collection of instances of NavPoint

receiveMessage

public void receiveMessage(RcvMsgEvent e)
add message to collected paths (adds)
FIFO fashion

Specified by:
receiveMessage in interface RcvMsgListener

initializeGetPath

public void initializeGetPath()
Deprecated. 


getPathToLocation

public java.util.ArrayList<NavPoint> getPathToLocation(Triple location)
obtain path to specified location keeps returning null until path is received don't forget to initialize it - initializeGetPath should be called prior this method

Parameters:
location -
Returns:
null if it has not received path from Gamebots yet, path if it does

runAlongPath

public boolean runAlongPath()
method to follow smoothly desired path - list of navigation points obtained from game map can handle movers - wait on it until top and leave note that movers in the way are in this fashion: - LiftExit -> LiftCenter -> LiftExit so as agent is supposed to go up when he is supposed to go to LiftCenter (therefore is around first LiftExit) he waits for mover to be about his level and then goes on it, wait to level with second LiftExit and move on

Specified by:
runAlongPath in interface Navigation
Returns:
boolean value - true if there are no problems, false if agent reaches the end or is unable to reach next navPoint

runAroundItemsInTheMap

public void runAroundItemsInTheMap(java.util.List<? extends Item> itemsToRunAround,
                                   boolean AStar)
run around items in the map is a complex method which covers behavior which runs around the map according to specified list of items, it works in the following fashion:

Specified by:
runAroundItemsInTheMap in interface Navigation
Parameters:
itemsToRunAround - - array of items - like all weapons in the map
AStar - - switch = to use or not to use built-in AStar - both work about the same

restartMap

public void restartMap()
method which restarts game map instance - restart necessary variables


antiStuckCheck

public boolean antiStuckCheck(Triple goal)
check two things: 1) agent's velocity - size of vector greater than 50 UT units 2) agent is heading to the location - distance from the location is greater about 50 UT units than distance from object after adding agent's velocity vector to location vector - if this method fails - delete the edge in the graph for A*

Parameters:
goal - - target location
Returns:
false if agent is not stucked (running and not heading to something too high)

safeRunToLocation

public boolean safeRunToLocation(Triple location)
safely navigates agent to the location of choosen item (could be anywhere). moreover you can set the distance at which agent will stop when reaching last point of the path (by setting GameMapSettings.lastNavigationPointOfPathPrecision) it should be I think at least 5 as I think it is not guaranteed that bots moves precisely.
Note that it may have problems when running to something really close to agent, like when you order him to run to something just on his side (lets say relatively 2 meters from him)

Specified by:
safeRunToLocation in interface Navigation
Parameters:
location - - location to run to
Returns:
false if there is some problem on the path - check platform log for more details