|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--de.uni_paderborn.robots.robot.group9.Map
Automatically creates a map of the arena while the robot walks through it.
| Inner Class Summary | |
class |
Map.Coordinate
Stores x and y coordinates, area information (used when robot uses a teleport). |
private class |
Map.DijDistanceComparator
Class that implements an order for MapItems based on their BfsDistance. |
class |
Map.ShortestPath
Class for storing paths created by findShortestPath |
| Field Summary | |
static int |
ALREADY_THERE
Error code returned by getPathError(). |
private int |
areaCounter
Count the number of newly found areas |
private boolean |
areasJoined
Is set to true exactly in the round, in which two different areas could be joined because a position had been found that is common to both areas. |
private java.util.HashSet |
badReactableClasses
Stores the Class objects of all reactables that cause harm to a robot. |
private MapItem |
cachedCurrentMapItem
For caching the map item the robot currently sits on. |
private MapItem |
cachedMapItemInFront
For caching the map item the robot currenty looks at. |
static int |
CARD_BLOCKS
Error code returned by getPathError(). |
(package private) static int |
DONT_USE_RECENT_CARDS
Flag for findShortestPath(): During searching the path do not go over cards the robot has found during the last 10 rounds. |
static int |
ENERGY_TOLERANCE
The robot won't try to go paths that are not within getEnergy() - ENERGY_TOLERANCE |
private boolean |
energyKnown
Is set to true when robot finds an energy source (well) |
private int |
energyPreUnknownReactable
Records the energy of a robot directly before the robot tries the effect of an unknown reactable |
private boolean |
exitKnown
Is set to true when robot finds the exit |
private int |
gameRound
Stores the number of the game round currently in progress. |
private int |
horizontalCycleSize
Stores the size of a horizontal cycle in the arena. |
static int |
INVALID
Error code returned by getPathError() This path does not is not valid any more |
private java.util.Hashtable |
itemCoordinateTable
Datastructure to keep all map items quickly accessible by their coordinate |
private java.util.TreeMap |
itemTreeMap
Datastructure to keep all map items quickly accessible by their id |
static int |
MAX_DISTANCE_EXCEEDED
Error code returned by getPathError(). |
static int |
NOT_FOUND
Error code returned by getPathError(). |
static int |
OKAY
Error code returned by getPathError(). |
private int |
pathError
If any of the methods dealing with shortest paths fails, it sets this value to an error code explaing the reason of the failure. |
private int |
postTeleportUsageState
For internal use of postTeleportUsage(). |
static int |
PROGRAM_BUG
Error code returned by getPathError(). |
private java.util.Random |
rand
Random number generator used by the shortest path methods. |
private LAR |
robot
The robot that uses this map |
static int |
ROBOT_BLOCKS
Error code returned by getPathError(). |
private int |
sawKnownFields
For keeping statistics, how many fields have been sawn more than once, and thus redundantly. |
private int |
sizeOfPortablePreUnknownReactable
Records the size of the robot's portable directly before the robot tries the effect of an unknwon reactable |
static int |
SLEEPING_ROBOT_BLOCKS
Error code returned by getPathError(). |
private int |
stepsToWell
The distance to the next well estimated by isWellGettingFar() |
(package private) static int |
STOP_IN_FRONT_OF_ITEM
Flag for findShortestPath(): Does not go directly onto field which contains the item, but stops in front of it, when the robot looks at it. |
static int |
TELEPORT_WAS_BLOCKED
Error code returned by getPathError(): The used teleporter was blocked. |
private boolean |
teleporterKnown
Is set to true when robot finds a teleporter |
static int |
UNEXPECTED_OBSTACLE
Error code returned by getPathError(): There was an unexpected obstacle in the calculated way. |
private boolean |
unknownReactableKnown
Is set to true when robot finds an unknown reactable |
static int |
UNUSED_TELEPORTS
Error code returned by getPathError(): There are no unknown fields, but unused teleports |
(package private) static int |
USE_NOT_VISITED
Flag for findShortestPath(): Also used fields marked as NOT_VISITED during the search. |
private MapItem |
usedTeleport
usesTeleport() stores here the teleport to be used. |
private MapItem |
usedUnknownReactable
The MapItem of the unknown reactable that the robot is about to use is stored here. |
private int |
verticalCycleSize
Stores the size of a vertical cycle in the arena. |
static int |
VIA_WELL
Error code returned by getPathError(). |
private int |
whenCheck
This value determines how often the shortest path to the well is actually calculated by isWellGettingFar() and not estimated. |
| Constructor Summary | |
Map()
Creates and initializes a new map object |
|
| Method Summary | |
private int |
addAdjacentItemsToQueue(MapItem mapItem,
int predecessorDirection,
MapItemMatcher mapItemMatcher,
java.util.TreeSet queue,
int addedToQueue)
Adds add items linked to the given mapItem to the priority queue of the dijstra algorithm. |
void |
addMapItem(MapItem mapItem)
Add a MapItem to the internal lists. |
private void |
checkCyclicArena(MapItem mapItemHere,
MapItem mapItemInFront)
Checks whether the MapItem the robot sits on and the MapItem the robot looks at indicates a cyclic arena. |
MapItem |
findMapItemByCoordinate(Map.Coordinate coordinate)
Searches all known map items for the map item with the given coordinate |
MapItem |
findMapItemById(int id)
Searches all known map items for the map item with the given id |
Map.ShortestPath |
findShortestPath(MapItemMatcher mapItemMatcher,
int maxDistance,
int flags)
Tries to find a shortest path that is at most maxDistance steps long to a map item that can be specified using the mapItemMatcher. |
MapItem |
getCurrentMapItem()
Returns the map item the robot currently sits on. |
int |
getGameRound()
Get the number of the game round currently in progress. |
int |
getHorizontalCycleSize()
Read access method for horizontalCycleSize |
MapItem |
getMapItemBehind()
Returns the map item behind of the robot (relative to robot's direction). |
MapItem |
getMapItemInFront()
Returns the map item the robot currently looks at. |
MapItem |
getMapItemLeft()
Returns the map item to the left of the robot (relative to robot's direction). |
MapItem |
getMapItemRight()
Returns the map item to the right of the robot (relative to robot's direction). |
int |
getPathError()
If any of the methods dealing with shortest paths fails, this method can be used to obtain an error code explaing the reason of the failure. |
LAR |
getRobot()
Get the robot that uses this map. |
int |
getVerticalCycleSize()
Read access method for verticalCycleSize |
boolean |
isBadReactableClass(java.lang.Class itemClass)
Checks using "empiric data" stored in badReactableClasses whether this reactable class is known to cause harm to a robot |
boolean |
isEnergyKnown()
Checks whether the robot has already found an energy source (well) during the arena exploration. |
boolean |
isExitKnown()
Checks whether the robot has already found the exit during the arena exploration. |
boolean |
isTeleporterKnown()
Checks whether the robot has already found a teleporter during the arena exploration. |
boolean |
isUnknownReactableKnown()
Checks whether the robot has already found a reactable that is not a telporter, card, well or exit during the arena exploration. |
boolean |
isWellGettingFar()
isWellGettingFar() tells the robot in a fast way, whether the next well is dangerously too far away. |
private void |
joinAreas(MapItem mapItemHere,
MapItem mapItemInFront)
joinAreas() is called when the trackPosition() Method finds two neigbour fields which belong to different mapping areas. |
private void |
joinMapItemLinks(MapItem mapItem,
MapItem mapItemRemove)
Joins two MapItems into one. |
static int |
oppositeDirection(int direction)
Rotates a given direction value as defined in Robot.java by 180 degrees Thus, north would become south. |
private java.util.LinkedList |
performDij(MapItemMatcher mapItemMatcher,
MapItem startMapItem,
int maxDistance,
int flags)
Searches for the nearest map item that matches with the specified search criteria. |
AbstractAction |
postTeleportUsage()
This method tells the map that the robot has just passed a teleport. |
void |
postUnknownReactableUsage()
Checks whether the reactable that was just used by the robot has caused any damage. |
boolean |
preTeleportUsage()
This method tells the map that the robot is about to use a teleport. |
void |
preUnknownReactableUsage()
Records the energy and the portable-size of the robot when the robot is about to use an unknown reactable. |
void |
printMap()
Debug code: Prints an ASCII version of the map to the terminal |
void |
removeMapItem(MapItem mapItem)
Removes a given MapItem from the internal lists. |
static int |
rotateDirectionLeft(int direction)
Rotates a given direction value as defined in Robot.java by 90 degrees to the left. |
static int |
rotateDirectionRight(int direction)
Rotates a given direction value as defined in Robot.java by 90 degrees to the right. |
void |
setHorizontalCycleSize(int horizontalCycleSize)
Write access method for horizontalCycleSize |
void |
setRobot(LAR robot)
Set the robot that uses this map. |
void |
setVerticalCycleSize(int verticalCycleSize)
Write access method for verticalCycleSize |
void |
setWhenCheck(int whenCheck)
Write access method for attribute whenCheck |
boolean |
teleportHasBeenUsed()
Determines using map internal data whether the robot has used a teleporter in the previous round. |
void |
trackPosition()
Creates the map of the arena. |
Map.ShortestPath |
unknownFields()
Checks whether there are still unknown fields in the arena. |
private void |
updateSurroundingMapItems(MapItem mapItem,
int notThisDirection)
Checks the neighbour MapItems of the specified one. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
private LAR robot
private int sawKnownFields
private int gameRound
private boolean exitKnown
private boolean energyKnown
private boolean teleporterKnown
private boolean unknownReactableKnown
private int verticalCycleSize
private int horizontalCycleSize
private MapItem cachedCurrentMapItem
private MapItem cachedMapItemInFront
private java.util.TreeMap itemTreeMap
private java.util.Hashtable itemCoordinateTable
private boolean areasJoined
private int areaCounter
private int pathError
public static final int OKAY
public static final int NOT_FOUND
public static final int MAX_DISTANCE_EXCEEDED
public static final int ROBOT_BLOCKS
public static final int SLEEPING_ROBOT_BLOCKS
public static final int CARD_BLOCKS
public static final int ALREADY_THERE
public static final int INVALID
public static final int VIA_WELL
public static final int UNUSED_TELEPORTS
public static final int UNEXPECTED_OBSTACLE
public static final int TELEPORT_WAS_BLOCKED
public static final int PROGRAM_BUG
private java.util.Random rand
static final int STOP_IN_FRONT_OF_ITEM
static final int USE_NOT_VISITED
static final int DONT_USE_RECENT_CARDS
private MapItem usedTeleport
private int postTeleportUsageState
private int energyPreUnknownReactable
private int sizeOfPortablePreUnknownReactable
private MapItem usedUnknownReactable
private java.util.HashSet badReactableClasses
private int stepsToWell
private int whenCheck
public static final int ENERGY_TOLERANCE
| Constructor Detail |
public Map()
| Method Detail |
public void setRobot(LAR robot)
robot - the robot that uses this mappublic LAR getRobot()
public int getGameRound()
public boolean isExitKnown()
public boolean isEnergyKnown()
public boolean isTeleporterKnown()
public boolean isUnknownReactableKnown()
public int getVerticalCycleSize()
public void setVerticalCycleSize(int verticalCycleSize)
verticalCycleSize - the new valuepublic int getHorizontalCycleSize()
public void setHorizontalCycleSize(int horizontalCycleSize)
horizontalCycleSize - the new valuepublic MapItem getCurrentMapItem()
public MapItem getMapItemInFront()
public MapItem getMapItemLeft()
public MapItem getMapItemRight()
public MapItem getMapItemBehind()
public MapItem findMapItemById(int id)
id - the id to search forpublic MapItem findMapItemByCoordinate(Map.Coordinate coordinate)
coordinate - the coordinate to search forpublic void addMapItem(MapItem mapItem)
removeMapItem(),
modify the value and then call addMapItem() again.
The map item is not added to this Map's graph!mapItem - The mapItem to be addedpublic void removeMapItem(MapItem mapItem)
mapItem - The mapItem to be removed.public static int rotateDirectionLeft(int direction)
direction - direction to be rotatedpublic static int rotateDirectionRight(int direction)
direction - direction to be rotatedpublic static int oppositeDirection(int direction)
direction - direction to be rotated
private void updateSurroundingMapItems(MapItem mapItem,
int notThisDirection)
mapItem - The MapItem to be surrounded.notThisDirection - The link in the specified direction will not be changed.
private void joinMapItemLinks(MapItem mapItem,
MapItem mapItemRemove)
mapItem - a MapItem to join. This MapItem will stay (in joined state) in the Map graphmapItemRemove - the oter MapItem to join. This MapItem will be after the joining removed from the Map graph
private void joinAreas(MapItem mapItemHere,
MapItem mapItemInFront)
mapItemHere - the MapItem the robot sits onmapItemInFront - the MapItem the robot looks at, should be in another area than mapItemHere.
private void checkCyclicArena(MapItem mapItemHere,
MapItem mapItemInFront)
mapItemHere - the MapItem the robot sits onmapItemInFront - the MapItem the robot looks at.public void trackPosition()
public void printMap()
public int getPathError()
private int addAdjacentItemsToQueue(MapItem mapItem,
int predecessorDirection,
MapItemMatcher mapItemMatcher,
java.util.TreeSet queue,
int addedToQueue)
mapItem - the MapItems linked to this MapItem will be added to the queue.predecessorDirection - the direction the predecessor of the specified
MapItem is linked with the specified MapItem. That is, the direction the
robot has when it sits on mapItem. This value is used for calculating the
weight of the links: The link to the item the robot looks at gets the weight 1 (for
one MoveAction), all others get the weight 2 (for one RotateAction and one MoveAction).mapItemMatcher - the mapItemMatcher used for this search.queue - the priority queue used by this search. The adjacent items will be added to this queue.addedToQueue - this value is increased whenever a MapItem has been added to the queue
in order to give the queue a total ordering. The new value of addedToQueue will be returned
by this method.
private java.util.LinkedList performDij(MapItemMatcher mapItemMatcher,
MapItem startMapItem,
int maxDistance,
int flags)
mapItemMatcher - instance of an implementation of a MapItemMatcher.
Used to determine what map items are actually wanted.startMapItem - the map item the search starts atmaxDistance - if the search exceeds this distance without being successful, the search will be stopped
public Map.ShortestPath findShortestPath(MapItemMatcher mapItemMatcher,
int maxDistance,
int flags)
mapItemMatcher - instance of an implementation of a MapItemMatcher.
Used to determine what map items are actually wanted.maxDistance - paths that are returned by this method will not exceed this distance.public Map.ShortestPath unknownFields()
public boolean preTeleportUsage()
public AbstractAction postTeleportUsage()
public boolean teleportHasBeenUsed()
public void preUnknownReactableUsage()
public boolean isBadReactableClass(java.lang.Class itemClass)
itemClass - The Class object of an unknown reactablepublic void postUnknownReactableUsage()
public void setWhenCheck(int whenCheck)
whenCheck - the new value for whenCheckpublic boolean isWellGettingFar()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||