de.uni_paderborn.robots.robot.group10
Class MapItem

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

public class MapItem
extends java.lang.Object

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


Field Summary
protected  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.
protected  int bfsDistance
          Distance value for breadth first search or the dijsktra algorithm performed by Map for searching the shortest path to a map item.
protected  MapItem bfsPredecessor
          Predecessor of this item in breadth first search.
protected  short bfsState
          State of this item in the currently performed breadth first search.
static short BLOCKED_WORMHOLE
          This position contains a wormhole whose linked wormhole is probably blocked.
static short CARD
          This value marks whether a card was on that position when it was seen.
protected  Map.Coordinate coordinate
          The (x/y)-coordinate of the map item.
protected  int discoveredInRound
          Number of rounds in which this map item has been discovered by the mapping method.
static short EMPTY
          On this position there is nothing (sometimes it may be occupied by a robot).
protected  int examinedInRound
          Number of rounds in which this map item has been examined by the mapping method.
static short EXIT
          This position is the exit of the arena.
protected  int id
          The id of this field in the arena.
protected  Map map
          The Map this MapItem belongs to.
protected  MapItem north
          Link to the MapItem to the north of this MapItem.
protected  MapItem northEast
          Link to the MapItem to the north east of this MapItem.
protected  MapItem northWest
          Link to the MapItem to the north west of this MapItem.
static short NOT_VISITED
          This position has not been visited by the robot.
protected  boolean notPassable
          Explicitely declares this item as not passable, independantly from its type
static short RECHARGER
          There is an energy source (recharger) on this position.
static short ROBOT
          A robot has been found on this position.
protected  int robotCounter
          Number of visits, the robot saw another robot on this field.
static short SLEEPING_ROBOT
          A robot without energy has been found on this position.
protected  MapItem south
          Link to the MapItem to the south of this MapItem.
protected  MapItem southEast
          Link to the MapItem to the south east of this MapItem.
protected  MapItem southWest
          Link to the MapItem to the south west of this MapItem.
protected  short type
          The type of the map item.
static short UNUSED_WORMHOLE
          This position contains a wormhole that has not been explored yet.
static short WALL
          This position is occupied by a wall.
static short WORMHOLE
          There is a wormhole on this position, whose "other side" is already known.
protected  MapItem wormholeLink
          If this MapItem is a wormhole, this field points to the other side of the wormhole.
 
Constructor Summary
MapItem()
          Creates a new map item.
 
Method Summary
protected static boolean 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()
          Returns the addedToQueue value
 int getBfsDistance()
          Returns the value of bfsDistance.
 MapItem getBfsPredecessor()
          Returns the value of bfsPredecessor.
 short getBfsState()
          Returns the value of bfsState.
 Map.Coordinate getCoordinate()
          Returns this map item's coordinate.
 int getDirectionOfMapItem(MapItem mapItem)
          Returns the direction in which this map item is linked with the given map item.
 int getDiscoveredInRound()
          Returns the number of rounds in which this map item has been discovered by the mapping method.
 int getExaminedInRound()
          Returns the number of rounds in which this map item has been examined by the mapping method.
 int getId()
          Returns the id of this item
 Map getMap()
          Returns this MapItem's map
 MapItem getMapItemByDirection(int direction)
          Returns the MapItem situated in the specified direction of this MapItem
 MapItem getNorth()
          Returns the MapItem to the north of this MapItem
 MapItem getNorthEast()
          Returns the MapItem to the north east of this MapItem
 MapItem getNorthWest()
          Returns the MapItem to the north west of this MapItem
 boolean getNotPassable()
          Returns whether this item is passable.
 int getPredecessorDirection()
          Returns the direction of the link from the predecessor in the path to this map item.
 int getRobotCounter()
          returns the robotCounter
 MapItem getSouth()
          Returns the MapItem to the south of this MapItem
 MapItem getSouthEast()
          Returns the MapItem to the south east of this MapItem
 MapItem getSouthWest()
          Returns the MapItem to the south west of this MapItem
 short getType()
          Returns this item's type.
 MapItem getWormholeLink()
          Returns the wormhole link of this map item
 void insertMapItemByDirection(int direction, MapItem mapItem)
          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 removeYourself()
          Removes the MapItem from the map's MapItem graph.
 void setAddedToQueue(int addedToQueue)
          Sets the addedToQueue value
 void setBfsDistance(int bfsDistance)
          Sets the value of bfsDistance.
 void setBfsPredecessor(MapItem bfsPredecessor)
          Sets the value of bfsPredecessor.
 void setBfsState(short bfsState)
          Sets the value of bfsState.
 void setBfsStateDistancePredecessor(short bfsState, int bfsDistance, MapItem bfsPredecessor)
          Combined version of setBfsState(), setBfsDistance() and setBfsPredecessor().
 void setCoordinate(Map.Coordinate coordinate)
          Sets this map item's coordinate.
 void setDiscoveredInRound(int discoveredInRound)
          Sets the number of rounds in which this map item has been discovered by the mapping method.
 void setExaminedInRound(int examinedInRound)
          Sets the number of rounds in which this map item has been (re)examined by the mapping method.
 void setId(int id)
          Sets this item's id
 boolean setMap(Map value)
          Sets this MapItem's map.
 void setMapItemByDirection(int direction, MapItem mapItem)
          Sets the MapItem situated in the specified direction of this MapItem
 boolean setNorth(MapItem value)
          Sets the to north link of this MapItem to the specified MapItem.
 boolean setNorthEast(MapItem value)
          Sets the to north east link of this MapItem to the specified MapItem.
 boolean setNorthWest(MapItem value)
          Sets the to north west link of this MapItem to the specified MapItem.
 void setNotPassable(boolean notPassable)
          Sets whether this item is passable.
 void setRobotCounter(int value)
          increments the robotCounter
 boolean setSouth(MapItem value)
          Sets the to south link of this MapItem to the specified MapItem.
 boolean setSouthEast(MapItem value)
          Sets the to south east link of this MapItem to the specified MapItem.
 boolean setSouthWest(MapItem value)
          Sets the to south west link of this MapItem to the specified MapItem.
 void setType(short type)
          Sets this item's type.
 boolean setWormholeLink(MapItem value)
          Sets the wormhole link of this map item
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

EMPTY

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

WORMHOLE

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

RECHARGER

public static final short RECHARGER
There is an energy source (recharger) 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 whether 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 then 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.

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_WORMHOLE

public static final short UNUSED_WORMHOLE
This position contains a wormhole that has not been explored yet.

BLOCKED_WORMHOLE

public static final short BLOCKED_WORMHOLE
This position contains a wormhole whose linked wormhole is probably blocked.

BFS_UNKNOWN

public static final short BFS_UNKNOWN
Value for bfsState. Indicates that the map item has not yet been found by breadth first search (white vertex).

BFS_VISITED

public static final short BFS_VISITED
Value for bfsState. Indicates that the map item has been discovered by breadth first search (grey vertex).

BFS_FINISHED

public static final short BFS_FINISHED
Value for bfsState. Indicates that the map item has been finished by breadth first search (black vertex).

id

protected int id
The id of this field in the arena.

type

protected short type
The type of the map item.

coordinate

protected Map.Coordinate coordinate
The (x/y)-coordinate of the map item. This may change during arena exploration.

map

protected Map map
The Map this MapItem belongs to.

north

protected MapItem north
Link to the MapItem to the north of this MapItem.

northEast

protected MapItem northEast
Link to the MapItem to the north east of this MapItem.

southEast

protected MapItem southEast
Link to the MapItem to the south east of this MapItem.

south

protected MapItem south
Link to the MapItem to the south of this MapItem.

southWest

protected MapItem southWest
Link to the MapItem to the south west of this MapItem.

northWest

protected MapItem northWest
Link to the MapItem to the north west of this MapItem.

wormholeLink

protected MapItem wormholeLink
If this MapItem is a wormhole, this field points to the other side of the wormhole.

notPassable

protected boolean notPassable
Explicitely declares this item as not passable, independantly from its type

discoveredInRound

protected int discoveredInRound
Number of rounds in which this map item has been discovered by the mapping method.

examinedInRound

protected int examinedInRound
Number of rounds in which this map item has been examined by the mapping method. This value will be updated when this map item is reexamined.

robotCounter

protected int robotCounter
Number of visits, the robot saw another robot on this field. This value will be incremented when this map item is reexamined.

addedToQueue

protected 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.

bfsDistance

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

bfsState

protected short bfsState
State of this item in the currently performed breadth first search. Can be one of BFS_UNKNOWN, BFS_VISITED and BFS_FINISHED.

bfsPredecessor

protected MapItem bfsPredecessor
Predecessor of this item in breadth first search.
Constructor Detail

MapItem

public MapItem()
Creates a new map item. Its id is set to -1, its type is set to NOT_VISITED. The item is assumed to be passable. The values for discoveredInRound and examinedInRound are both set to -1.
Method Detail

getId

public int getId()
Returns the id of this item

setId

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

getRobotCounter

public int getRobotCounter()
returns the robotCounter

setRobotCounter

public void setRobotCounter(int value)
increments the robotCounter

getType

public short getType()
Returns this item's type.

setType

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

getCoordinate

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

setCoordinate

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

getMap

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

setMap

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

getNorth

public MapItem getNorth()
Returns the MapItem to the north of this MapItem
Returns:
the MapItem north of this MapItem or null if there is no link (that means that part of the area is unknown)

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
Returns:
true if the link has changed

getNorthEast

public MapItem getNorthEast()
Returns the MapItem to the north east of this MapItem
Returns:
the MapItem north east of this MapItem or null if there is no link (that means that part of the area is unknown)

setNorthEast

public boolean setNorthEast(MapItem value)
Sets the to north 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 north east link
Returns:
true if the link has changed

getSouthEast

public MapItem getSouthEast()
Returns the MapItem to the south east of this MapItem
Returns:
the MapItem south east of this MapItem or null if there is no link (that means that part of the area is unknown)

setSouthEast

public boolean setSouthEast(MapItem value)
Sets the to south 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 south east link
Returns:
true if the link has changed

getSouth

public MapItem getSouth()
Returns the MapItem to the south of this MapItem
Returns:
the MapItem south of this MapItem or null if there is no link (that means that part of the area is unknown)

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
Returns:
true if the link has changed

getSouthWest

public MapItem getSouthWest()
Returns the MapItem to the south west of this MapItem
Returns:
the MapItem south west of this MapItem or null if there is no link (that means that part of the area is unknown)

setSouthWest

public boolean setSouthWest(MapItem value)
Sets the to south 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 south west link
Returns:
true if the link has changed

getNorthWest

public MapItem getNorthWest()
Returns the MapItem to the north west of this MapItem
Returns:
the MapItem north west of this MapItem or null if there is no link (that means that part of the area is unknown)

setNorthWest

public boolean setNorthWest(MapItem value)
Sets the to north 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 north west link
Returns:
true if the link has changed

getWormholeLink

public MapItem getWormholeLink()
Returns the wormhole link of this map item
Returns:
the wormhole link

setWormholeLink

public boolean setWormholeLink(MapItem value)
Sets the wormhole link of this map item
Parameters:
value - link the new wormhole link
Returns:
true if the link has changed

getNotPassable

public boolean getNotPassable()
Returns whether this item is passable.
Returns:
true if this item is not passable

setNotPassable

public void setNotPassable(boolean notPassable)
Sets whether this item is passable.
Parameters:
notPassable - new value for notPassable

getDiscoveredInRound

public int getDiscoveredInRound()
Returns the number of rounds in which this map item has been discovered by the mapping method.

setDiscoveredInRound

public void setDiscoveredInRound(int discoveredInRound)
Sets the number of rounds in which this map item has been discovered by the mapping method.
Parameters:
discoveredInRound - the number of rounds in which this map item has been discovered

getExaminedInRound

public int getExaminedInRound()
Returns the number of rounds in which this map item has been examined by the mapping method.

setExaminedInRound

public void setExaminedInRound(int examinedInRound)
Sets the number of rounds in which this map item has been (re)examined by the mapping method.
Parameters:
examinedInRound - the number of rounds in which this map item has been (re)examined

getAddedToQueue

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

setAddedToQueue

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

getBfsDistance

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

setBfsDistance

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

getBfsState

public short getBfsState()
Returns the value of bfsState.
Returns:
the current value of bfsState of this map item

setBfsState

public void setBfsState(short bfsState)
Sets the value of bfsState. Used by breadth first search performed by Map for searching the shortest path to a map item. Nobody else should need or use it.
Parameters:
bfsState - the new value of bfsState

getBfsPredecessor

public MapItem getBfsPredecessor()
Returns the value of bfsPredecessor.

setBfsPredecessor

public void setBfsPredecessor(MapItem bfsPredecessor)
Sets the value of bfsPredecessor. Used by breadth first search performed by Map for searching the shortest path to a map item. Nobody else should need or use it.
Parameters:
bfsPredecessor - the predecessor of this map item in breadth first search

removeYourself

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

getMapItemByDirection

public MapItem getMapItemByDirection(int direction)
Returns the MapItem situated in the specified direction of this MapItem
Parameters:
direction - the direction in which to obtain the neighbouring field

setMapItemByDirection

public void setMapItemByDirection(int direction,
                                  MapItem mapItem)
Sets the MapItem situated in the specified direction of this MapItem
Parameters:
direction - the direction in which to set the neighbouring field
MapItem - the new MapItem to which this item is to be linked in specified direction

insertMapItemByDirection

public void insertMapItemByDirection(int direction,
                                     MapItem mapItem)
The same as setMapItemByDirection(), but also sets the links of the new map item in all other directions to the correct values.
Parameters:
direction - the direction in which to set the neighbouring field
MapItem - the new MapItem to which this item is to be linked in specified direction

getDirectionOfMapItem

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

fixItemLinks

protected static boolean 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 in which relativeItem is positioned relative to item
item - the item used as reference point
relativeItem - neighbouring item in the specified direction
Returns:
true if the link was ok

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 not passable using setNotPassable(). This method does not return true for wormholes. These have to be treated as a special case.
Parameters:
gameRound - the number of the current game round
Returns:
true if this map item is passble

setBfsStateDistancePredecessor

public void setBfsStateDistancePredecessor(short bfsState,
                                           int bfsDistance,
                                           MapItem bfsPredecessor)
Combined version of setBfsState(), setBfsDistance() and setBfsPredecessor().
Parameters:
bfsState - new value of bfsState
bfsDistance - new value of bfsDistance
bfsPredecessor - new value of bfsPredecessor

getPredecessorDirection

public int getPredecessorDirection()
Returns the direction of the link from the predecessor in the path to this map item.
Returns:
the direction of the link from the predecessor in the path to this map item or -1 if the predecessor is not linked for some reason