de.uni_paderborn.robots.robot.group9
Class MapItem

java.lang.Object
  |
  +--de.uni_paderborn.robots.robot.group9.MapItem

public class MapItem
extends java.lang.Object

Equivalent of one arena field in the robot's own map. Linked in four directions and also by a MapTree in class Map.


Field Summary
private  int addedToQueue
          The Dijkstra algorithm needs to keep track when this map item has been added to its priority queue.
static short BFS_FINISHED
          Value for bfsState.
static short BFS_UNKNOWN
          Value for bfsState.
static short BFS_VISITED
          Value for bfsState.
private  int bfsDistance
          Distance value for breadth first search or dijsktra performed by Map for searching the shortest path to a map item
private  MapItem bfsPredecessor
          Predecessor of this item in breadth first search.
private  short bfsState
          State of this item in the currently performed breadth first search.
static short BLOCKED_TELEPORT
          This position contains a teleport whose linked teleport is probably blocked.
static short CARD
          This value marks wheter a card was on that position when it was seen
private  Map.Coordinate coordinate
          Stores a xy coordinate of the map item.
private  int discoveredInRound
          Number of round in which this field/map item has been discovered by the mapping method.
private  MapItem east
          The MapItem to the east of this MapItem is linked here.
0..1 horizontal 0..1 MapItem -------------------------- MapItem east west
static short EMPTY
          On this position there is nothing (sometimes it may be occupied by a robot)
private  int examinedInRound
          Number of round in which this field/map item has been examined by the mapping method.
static short EXIT
          This position is the exit of the arena
private  int id
          For storing the field id of the arena fields
private  java.lang.Class itemClass
          If this MapItem is an UNKNOWN_REACTABLE, the Class object of the MapItem is stored here, in order to be able to keep track of the reactable classes that cause damage to a robot
private  Map map
          The Map this MapItem belongs to.
 
/\ 0..1 items Map < >--------------------- MapItem \/ map
private  MapItem north
          The MapItem to the north of this MapItem is linked here.
0..1 vertical 0..1 MapItem ------------------------ MapItem north south
static short NOT_VISITED
          This position has not been visited by the robot.
private  boolean notPassable
          This field allows to explicitely declare this position as not passable, independantly from its type
static short ROBOT
          A robot has been found on this position.
static short SLEEPING_ROBOT
          A robot without energy has been found on this position.
private  MapItem south
          The MapItem to the south of this MapItem is linked here.
0..1 vertical 0..1 MapItem ------------------------ MapItem south north
static short TELEPORT
          There is a teleporter on this position, whose "other side" is already known.
private  MapItem teleportLink
          If this MapItem is a teleport, this field points to the other side of the teleport.
private  short type
          For storing the type of the map item
static short UNKNOWN_ITEM
          There is some other unknown item on this position (not a reactable)
static short UNKNOWN_REACTABLE
          There is an unknown reactable on this position
static short UNKNOWN_REACTABLE_BAD
          This position contains an unknown reactable that is known to cause damage.
static short UNKNOWN_REACTABLE_USED
          This position contains an unknown reactable that has been already used.
static short UNUSED_TELEPORT
          This position contains a teleport that has not been explored, yet.
static short WALL
          This position is occupied by a wall
static short WELL
          There is an energy source (well) on this position
private  MapItem west
          The MapItem to the west of this MapItem is linked here.
0..1 horizontal 0..1 MapItem -------------------------- MapItem west east
 
Constructor Summary
MapItem()
          Creates a new map item and sets the id to -1 and type to NOT_VISITED
 
Method Summary
private static void fixItemLinks(int direction, MapItem item, MapItem relativeItem)
          Checks that item and relativeItem, which are supposed to be neighbours, are correctly linked in the specified direction.
 int getAddedToQueue()
          gets the addedToQueue value
 int getBfsDistance()
          Gets bfsDistance.
 MapItem getBfsPredecessor()
          Gets bfsPredecessor
 short getBfsState()
          Gets bfsState
 Map.Coordinate getCoordinate()
          Get this map item's coordinate
(package private)  int getDirectionOfMapItem(MapItem mapItem)
          Gets the direction in which this map item is linked with the given map item.
 int getDiscoveredInRound()
          Read access method for discoveredInRound.
 MapItem getEast()
          Gets the MapItem in the east of this MapItem
 int getExaminedInRound()
          Returns the number of round in which this field/map item has been examined by the mapping method.
 int getId()
          Returns the id of this item
 java.lang.Class getItemClass()
          Read access method for itemClass.
 Map getMap()
          Gets this MapItem's map
 MapItem getMapItemByDirection(int direction)
          Method similar to getNorth(), getSouth(), getWest(), getEast().
 MapItem getNorth()
          Gets the MapItem in the north of this MapItem
 int getPredecessorDirection()
          Gets the direction the path predecessor is linked to this MapItem
 MapItem getSouth()
          Gets the MapItem in the south of this MapItem
 MapItem getTeleportLink()
          Gets the teleportLink
 short getType()
          Gets this item's type.
 MapItem getWest()
          Gets the MapItem in the west of this MapItem
 void insertMapItemByDirection(int direction, MapItem mapItem)
          Does the same as setMapItemByDirection, but also sets the links of the new map item in all other directions to the correct values.
 boolean isPassable(int gameRound, int flags)
          Checks whether this map item can be passed.
 void removeYou()
          Removes the MapItem from the Map's MapItem graph.
 void setAddedToQueue(int addedToQueue)
          sets the addedToQueue value
 void setBfsDistance(int bfsDistance)
          Sets bfsDistance.
 void setBfsPredecessor(MapItem bfsPredecessor)
          Sets bfsPredecessor
 void setBfsState(short bfsState)
          Sets bfsState.
 void setBfsStateDistancePredecessor(short bfsState, int bfsDistance, MapItem bfsPredecessor)
          Comined version of setBfsState(), setBfsDistance() and setBfsPredecessor().
 void setCoordinate(Map.Coordinate coordinate)
          Set this map item's coordinate
 boolean setEast(MapItem value)
          Sets the to east link of this MapItem to the specified MapItem.
 void setExaminedInRound(int examinedInRound)
          Set the examinedInRound value.
 void setId(int id)
          Sets this item's id
 void setItemClass(java.lang.Class itemClass)
          Write access method for itemClass.
 boolean setMap(Map value)
          Sets this MapItem's map.
 void setMapItemByDirection(int direction, MapItem mapItem)
          Method similar to setNorth(), setSouth(), setWest(), setEast().
 boolean setNorth(MapItem value)
          Sets the to north link of this MapItem to the specified MapItem.
 void setNotPassable(boolean notPassable)
          Write access method for notPassable.
 boolean setSouth(MapItem value)
          Sets the to south link of this MapItem to the specified MapItem.
 void setTeleportLink(MapItem teleportLink)
          Sets the teleportLink
 void setType(short type)
          Sets this item's type.
 boolean setWest(MapItem value)
          Sets the to west link of this MapItem to the specified MapItem.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

coordinate

private Map.Coordinate coordinate
Stores a xy coordinate of the map item. This may change during arena exploration.

north

private MapItem north
The MapItem to the north of this MapItem is linked here.
          0..1   vertical   0..1 
 MapItem ------------------------ MapItem
          north            south 
 

south

private MapItem south
The MapItem to the south of this MapItem is linked here.
          0..1   vertical   0..1 
 MapItem ------------------------ MapItem
          south            north 
 

west

private MapItem west
The MapItem to the west of this MapItem is linked here.
          0..1   horizontal   0..1 
 MapItem -------------------------- MapItem
          west                east 
 

east

private MapItem east
The MapItem to the east of this MapItem is linked here.
          0..1   horizontal   0..1 
 MapItem -------------------------- MapItem
          east                west 
 

teleportLink

private MapItem teleportLink
If this MapItem is a teleport, this field points to the other side of the teleport.

itemClass

private java.lang.Class itemClass
If this MapItem is an UNKNOWN_REACTABLE, the Class object of the MapItem is stored here, in order to be able to keep track of the reactable classes that cause damage to a robot

map

private Map map
The Map this MapItem belongs to.
 
      /\  0..1   items     
 Map <  >--------------------- MapItem
      \/  map             
 

id

private int id
For storing the field id of the arena fields

addedToQueue

private int addedToQueue
The Dijkstra algorithm needs to keep track when this map item has been added to its priority queue. This is done with this field.

EMPTY

public static final short EMPTY
On this position there is nothing (sometimes it may be occupied by a robot)

TELEPORT

public static final short TELEPORT
There is a teleporter on this position, whose "other side" is already known.

WELL

public static final short WELL
There is an energy source (well) on this position

EXIT

public static final short EXIT
This position is the exit of the arena

WALL

public static final short WALL
This position is occupied by a wall

CARD

public static final short CARD
This value marks wheter a card was on that position when it was seen

ROBOT

public static final short ROBOT
A robot has been found on this position. To find out when the robot has been found (because it propably moves away from this position), use getExaminedInRound(). Obviously, the map item this robot sits on is not marked with ROBOT, but with EMPTY.

SLEEPING_ROBOT

public static final short SLEEPING_ROBOT
A robot without energy has been found on this position. Thus, this robot is treated as permanent obstacle. Furthermore, this is one card exchange partner who cannot move away. ;)

UNKNOWN_REACTABLE

public static final short UNKNOWN_REACTABLE
There is an unknown reactable on this position

UNKNOWN_ITEM

public static final short UNKNOWN_ITEM
There is some other unknown item on this position (not a reactable)

NOT_VISITED

public static final short NOT_VISITED
This position has not been visited by the robot. The Id is also unknown. MapItems with this type are only created for positions that directly surround the known positions.

UNUSED_TELEPORT

public static final short UNUSED_TELEPORT
This position contains a teleport that has not been explored, yet.

BLOCKED_TELEPORT

public static final short BLOCKED_TELEPORT
This position contains a teleport whose linked teleport is probably blocked.

UNKNOWN_REACTABLE_BAD

public static final short UNKNOWN_REACTABLE_BAD
This position contains an unknown reactable that is known to cause damage.

UNKNOWN_REACTABLE_USED

public static final short UNKNOWN_REACTABLE_USED
This position contains an unknown reactable that has been already used.

type

private short type
For storing the type of the map item

notPassable

private boolean notPassable
This field allows to explicitely declare this position as not passable, independantly from its type

examinedInRound

private int examinedInRound
Number of round in which this field/map item has been examined by the mapping method. Will be updated when this map item is reexamined.

discoveredInRound

private int discoveredInRound
Number of round in which this field/map item has been discovered by the mapping method.

bfsDistance

private int bfsDistance
Distance value for breadth first search or dijsktra performed by Map for searching the shortest path to a map item

BFS_UNKNOWN

public static final short BFS_UNKNOWN
Value for bfsState. MapItem has not been found yet by breadth first search (white vertex). Used by breadth first search performed by Map for searching the shortest path to a map item. Nobody else should need or use it.

BFS_VISITED

public static final short BFS_VISITED
Value for bfsState. MapItem has been discovered by breadth first search (grey vertex).

BFS_FINISHED

public static final short BFS_FINISHED
Value for bfsState. MapItem has been finished by breadth first search (black vertex).

bfsState

private short bfsState
State of this item in the currently performed breadth first search. Can be one of BFS_UNKNOWN, BFS_VISITED and BFS_FINISHED. Used by breadth first search performed by Map for searching the shortest path to a map item. Nobody else should need or use it.

bfsPredecessor

private MapItem bfsPredecessor
Predecessor of this item in breadth first search. Used by breadth first search performed by Map for searching the shortest path to a map item. Nobody else should need or use it.
Constructor Detail

MapItem

public MapItem()
Creates a new map item and sets the id to -1 and type to NOT_VISITED
Method Detail

setCoordinate

public void setCoordinate(Map.Coordinate coordinate)
Set this map item's coordinate
Parameters:
coordinate - the new coordinate of this map item

getCoordinate

public Map.Coordinate getCoordinate()
Get this map item's coordinate
Returns:
this map item's coordinate

setNorth

public boolean setNorth(MapItem value)
Sets the to north link of this MapItem to the specified MapItem. This method does not take care of any other changes in the map that may become neccessary by this change.
Parameters:
value - the new north link

getNorth

public MapItem getNorth()
Gets the MapItem in the north of this MapItem
Returns:
the MapItem in the north of this MapItem

setSouth

public boolean setSouth(MapItem value)
Sets the to south link of this MapItem to the specified MapItem. This method does not take care of any other changes in the map that may become neccessary by this change.
Parameters:
value - the new south link

getSouth

public MapItem getSouth()
Gets the MapItem in the south of this MapItem
Returns:
the MapItem in the south of this MapItem

setWest

public boolean setWest(MapItem value)
Sets the to west link of this MapItem to the specified MapItem. This method does not take care of any other changes in the map that may become neccessary by this change.
Parameters:
value - the new west link

getWest

public MapItem getWest()
Gets the MapItem in the west of this MapItem
Returns:
the MapItem in the west of this MapItem

setEast

public boolean setEast(MapItem value)
Sets the to east link of this MapItem to the specified MapItem. This method does not take care of any other changes in the map that may become neccessary by this change.
Parameters:
value - the new east link

getEast

public MapItem getEast()
Gets the MapItem in the east of this MapItem
Returns:
the MapItem in the east of this MapItem

removeYou

public void removeYou()
Removes the MapItem from the Map's MapItem graph. This method does not the MapItem from the other lists of the map.

getMapItemByDirection

public MapItem getMapItemByDirection(int direction)
Method similar to getNorth(), getSouth(), getWest(), getEast(). The difference: The direction can be specified as int, using the direction definitions in class Robot.

Parameters:
direction - direction as defined in Robot.java

setMapItemByDirection

public void setMapItemByDirection(int direction,
                                  MapItem mapItem)
Method similar to setNorth(), setSouth(), setWest(), setEast(). The difference: The direction can be specified as int, using the direction definitions in class Robot.

Parameters:
direction - direction as defined in Robot.java
MapItem - MapItem to which this item will be linked in specified direction

setTeleportLink

public void setTeleportLink(MapItem teleportLink)
Sets the teleportLink
Parameters:
teleportLink - the new teleport link

getTeleportLink

public MapItem getTeleportLink()
Gets the teleportLink
Returns:
the teleportLink

getItemClass

public java.lang.Class getItemClass()
Read access method for itemClass.
Returns:
the value of itemClass

setItemClass

public void setItemClass(java.lang.Class itemClass)
Write access method for itemClass.
Parameters:
itemClass - the new value of itemClass

fixItemLinks

private static void fixItemLinks(int direction,
                                 MapItem item,
                                 MapItem relativeItem)
Checks that item and relativeItem, which are supposed to be neighbours, are correctly linked in the specified direction. Direction is relative to item. For example, if direction is north, this method checks, that item.north points to relativeItem and that relativeItem.south points to item.

Parameters:
direction - direction relative to item how relativeItem is positioned
item - neighbour of relativeItem. relativeItem is in the specified direction of item.
relativeItem - neighbour of item

insertMapItemByDirection

public void insertMapItemByDirection(int direction,
                                     MapItem mapItem)
Does the same as setMapItemByDirection, but also sets the links of the new map item in all other directions to the correct values.
Parameters:
direction - direction as defined in Robot.java
MapItem - MapItem to which this item will be linked in specified direction

getDirectionOfMapItem

int getDirectionOfMapItem(MapItem mapItem)
Gets the direction in which this map item is linked with the given map item.
Parameters:
mapItem - the map item to find the direction for

setMap

public boolean setMap(Map value)
Sets this MapItem's map.
Parameters:
value - the new map.
Returns:
true if the map has changed.

getMap

public Map getMap()
Gets this MapItem's map
Returns:
the map this MapItem belongs to

setId

public void setId(int id)
Sets this item's id
Parameters:
id - the new id of this item

getId

public int getId()
Returns the id of this item

setAddedToQueue

public void setAddedToQueue(int addedToQueue)
sets the addedToQueue value
Parameters:
addedToQueue - the new addedToQueue value

getAddedToQueue

public int getAddedToQueue()
gets the addedToQueue value
Returns:
this MapItem's addedToQueue value

setType

public void setType(short type)
Sets this item's type. This can be one of
Parameters:
the - new type of the item

getType

public short getType()
Gets this item's type. This is one of


setNotPassable

public void setNotPassable(boolean notPassable)
Write access method for notPassable.
Parameters:
notPassable - new value for notPassable

isPassable

public boolean isPassable(int gameRound,
                          int flags)
Checks whether this map item can be passed. This is the case when its type is EMPTY or CARD (if a card is still on this position the robot can put it somewhere else). If this item is of type ROBOT, this method returns true only if the robot has been found at least two rounds before this round. This method does return false for all types if it has been explicitely marked as notPassable using setNotPassable(). This method does not return true for TELEPORTs. These have to be treated as a special case.
Parameters:
gameRound - the number of the current game round.

getExaminedInRound

public int getExaminedInRound()
Returns the number of round in which this field/map item has been examined by the mapping method. Will be updated when this map item is reexamined.

setExaminedInRound

public void setExaminedInRound(int examinedInRound)
Set the examinedInRound value.
Parameters:
examinedInRound - The round number in which this map item has been (re)examined

getDiscoveredInRound

public int getDiscoveredInRound()
Read access method for discoveredInRound.
Returns:
the value of discoveredInRound.

setBfsDistance

public void setBfsDistance(int bfsDistance)
Sets bfsDistance. Used by breadth first search or dijsktra performed by Map for searching the shortest path to a map item. Nobody else should need or use it.
Parameters:
bfsDistance - the new distance

getBfsDistance

public int getBfsDistance()
Gets bfsDistance. Used by breadth first search or dijsktra performed by Map for searching the shortest path to a map item. Nobody else should need or use it. -1 means infinite distance.

setBfsState

public void setBfsState(short bfsState)
Sets bfsState.
Parameters:
bfsState - the new bfsState. Can be one of BFS_UNKOWN, BFS_VISITED and BFS_FINISHED.

getBfsState

public short getBfsState()
Gets bfsState

setBfsPredecessor

public void setBfsPredecessor(MapItem bfsPredecessor)
Sets bfsPredecessor
Parameters:
bfsPredecessor - the predecessor of this map item in breadth first search

getBfsPredecessor

public MapItem getBfsPredecessor()
Gets bfsPredecessor

setBfsStateDistancePredecessor

public void setBfsStateDistancePredecessor(short bfsState,
                                           int bfsDistance,
                                           MapItem bfsPredecessor)
Comined version of setBfsState(), setBfsDistance() and setBfsPredecessor(). If you need to set these three values at the same time, this saves you two calls!
Parameters:
bfsState - new bfs state
bfsDistance - new bfs distance
bfsPredecessor - new bfs predecessor

getPredecessorDirection

public int getPredecessorDirection()
Gets the direction the path predecessor is linked to this MapItem
Returns:
A direction value as defined in Robot.java or -1 if Predecessor is for some reason not linked.