mstar
Class MudMap

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.Vector
                    |
                    +--mstar.MudMap

public class MudMap
extends java.util.Vector
implements java.io.Serializable

A class that implements a general map for storing information about each room in the collaborative environment, and a set of methods for searching for rooms, and objects in the map. In addition there are a set of methods for reading and writing the maps to disk in both Java object format and psuedo-MAAS-Neotek format.

See Also:
Serialized Form

Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
MudMap()
          Create an empty MUD map.
MudMap(Room room)
          Create a MUD map and add the specified room.
 
Method Summary
 void add(Room room)
          Adds a room to the map and writes the map back to disk.
 void clearRoomsVisited()
          Clears the visited flag in each of the rooms in the map.
 void clearVisitedExits()
          Clears the visited exits field of each room in the map.
 void fastAdd(Room room)
          Adds a room to the map but does not write the maps to disk.
 java.util.Vector findObject(java.lang.String object)
          Finds all of the rooms in the map that contain object.
 java.util.Stack findPath(int start, int destination)
          Given two room identifiers return a Stack that has a set of directions to go from one room to the other.
 java.util.Stack findPath(Room start, Room destination)
          Given two rooms return a Stack that has a set of directions to go from one room to the other.
 java.util.Stack findPathToRoom(int start, int destination)
          Given two room identifiers return a Stack that has a set of directions to go from one room to the other.
 java.util.Stack findPathToRoom(Room start, Room destination)
          Given two rooms return a Stack that has a set of directions to go from one room to the other.
 Room getCurrentRoom()
          Gets the robot's current room in the MUD.
 Room getHome()
          Gets the room that is the robot's home or default room in the collaborative environment.
 int getId()
          Returns the room identifier for the next room.
 java.lang.String getMapFilename()
          Gets the output filename for the map.
 Room getPreviousRoom()
          Gets the last room that the robot was in.
 Room getRoom(int id)
          Given the id of a room in the map locate and return that room.
 Room getRoom(Room r)
          Given a room find the same room in the map.
 Room getRoom(java.lang.String name)
          Locate a room in the map with the given name.
 Room getRoomWithUnexploredExits()
          Starting from the beginning of the map, locate a room that has unexplored exits.
 Room getRoomWithUnexploredExits(int after)
          Starting from the id greater than after, locate a room that has unexplored exits.
static MudMap loadMap()
          Loads the MUD map from disk.
 java.lang.String makeDirections(int start, java.util.Stack s)
          This routine runs through the stack backwards and creates a set of human readable directions that the bot is following to go to the destination.
 void readMap()
          Deprecated.  
 boolean roomExists(int id)
          Determines if a room in the map exists with the given id.
 boolean roomExists(Room theRoom)
          Determines if a room in the map exists given another room.
 boolean roomExists(java.lang.String name)
          Determines if a room in the map exists with the given name.
 void setCurrentRoom(Room currentRoom)
          Sets the robot's current room in the MUD.
 void setFallbackExits(java.lang.String[] exits)
          Sets the list of fallback exits to use.
 void setHome(Room home)
          Sets the room that is the robot's home or default room in the collaborative environment.
 void setMapFilename(java.lang.String mapFilename)
          Set the output filename for the map.
 void setPreviousRoom(Room previousRoom)
          Sets the last room that the robot was in.
 void setUseFallbackExits(boolean t)
          Sets whether or not to use fallback exits.
 void setUsePossibleExits(boolean t)
          Sets whether or not to use possible exits.
 java.lang.String toString()
          Returns a string representation of the map.
 void WriteMap()
          Writes the map out in pseudo-MAAS-Neotek format.
 void WriteMapAsObjects()
          Writes the map out to disk as a set of Java objects.
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MudMap

public MudMap()
Create an empty MUD map.

MudMap

public MudMap(Room room)
Create a MUD map and add the specified room.
Parameters:
room - the room to be added to the MUD map.
Method Detail

getId

public int getId()
Returns the room identifier for the next room.
Returns:
the integer identifier for the next room to be added.

setCurrentRoom

public void setCurrentRoom(Room currentRoom)
Sets the robot's current room in the MUD.
Parameters:
currentRoom - the room that is the robot's current position in the MUD.

getCurrentRoom

public Room getCurrentRoom()
Gets the robot's current room in the MUD.
Returns:
the room that is the robot's current position in the MUD.

setPreviousRoom

public void setPreviousRoom(Room previousRoom)
Sets the last room that the robot was in.
Parameters:
previousRoom - the room that the robot was in before the current room.

getPreviousRoom

public Room getPreviousRoom()
Gets the last room that the robot was in.
Returns:
the room that the robot was in before the current room.

setHome

public void setHome(Room home)
Sets the room that is the robot's home or default room in the collaborative environment.
Parameters:
home - the room that is the robot's home or default room in the collaborative environment.

getHome

public Room getHome()
Gets the room that is the robot's home or default room in the collaborative environment.
Returns:
the room that is the robot's home or default room in the collaborative environment.

setUseFallbackExits

public void setUseFallbackExits(boolean t)
Sets whether or not to use fallback exits. Fallback exits are used by the robot when mapping the collaborative environment to help it locate exits that are not in the obvious exit list.
Parameters:
t - if true use fallback exits to locate exits. If false do not use the fallback exit list.

setUsePossibleExits

public void setUsePossibleExits(boolean t)
Sets whether or not to use possible exits. Possible exits are used by the robot when mapping the collaborative environment to help it locate exits that are not in the obvious exit list. A possible exit is derived by creating a set of uniterms from the room description.
Parameters:
t - if true use possible exits to locate exits. If false do not use the possible exit list.

setFallbackExits

public void setFallbackExits(java.lang.String[] exits)
Sets the list of fallback exits to use.
Parameters:
exits - a String array of exit names to use when fallback exits are enabled.

loadMap

public static MudMap loadMap()
Loads the MUD map from disk.

add

public void add(Room room)
Adds a room to the map and writes the map back to disk.
Parameters:
room - the room to add to the the map.

fastAdd

public void fastAdd(Room room)
Adds a room to the map but does not write the maps to disk.
Parameters:
room - the room to add to the map.

getRoom

public Room getRoom(Room r)
Given a room find the same room in the map.
Parameters:
r - the room to locate in the map.
Returns:
the room from the map or null if it doesn't exist.

getRoom

public Room getRoom(int id)
Given the id of a room in the map locate and return that room.
Parameters:
id - of the room to locate in the map.
Returns:
the room from the map or null if it doesn't exist.

getRoomWithUnexploredExits

public Room getRoomWithUnexploredExits()
Starting from the beginning of the map, locate a room that has unexplored exits.
Returns:
a room with unexplored exits, or null if all exits in all rooms have been explored.

getRoomWithUnexploredExits

public Room getRoomWithUnexploredExits(int after)
Starting from the id greater than after, locate a room that has unexplored exits.
Returns:
a room with unexplored exits, or null if all exits in all rooms have been explored.

getRoom

public Room getRoom(java.lang.String name)
Locate a room in the map with the given name.
Parameters:
name - the name of the room to locate.
Returns:
a room with the given name. If two rooms in the collaborative environment have identical names, only the first will be returned.

roomExists

public boolean roomExists(java.lang.String name)
Determines if a room in the map exists with the given name.
Parameters:
name - of the room to check for.
Returns:
true if the room exists false if it does not.

roomExists

public boolean roomExists(int id)
Determines if a room in the map exists with the given id.
Parameters:
id - of the room to check for.
Returns:
true if the room exists false if it does not.

roomExists

public boolean roomExists(Room theRoom)
Determines if a room in the map exists given another room.
Parameters:
theRoom - to check the map for.
Returns:
true if the room exists, false if it does not.

toString

public java.lang.String toString()
Returns a string representation of the map.
Overrides:
toString in class java.util.Vector
Returns:
a string representation of the map.

clearVisitedExits

public void clearVisitedExits()
Clears the visited exits field of each room in the map.

setMapFilename

public void setMapFilename(java.lang.String mapFilename)
Set the output filename for the map.

getMapFilename

public java.lang.String getMapFilename()
Gets the output filename for the map.

WriteMapAsObjects

public void WriteMapAsObjects()
Writes the map out to disk as a set of Java objects.

WriteMap

public void WriteMap()
Writes the map out in pseudo-MAAS-Neotek format.

clearRoomsVisited

public void clearRoomsVisited()
Clears the visited flag in each of the rooms in the map.

findPath

public java.util.Stack findPath(Room start,
                                Room destination)
Given two rooms return a Stack that has a set of directions to go from one room to the other.
Parameters:
start - the starting room
destination - the destination room
Returns:
a Stack with a set of directions for navigating between the two rooms or null if a path does not exist.

findPath

public java.util.Stack findPath(int start,
                                int destination)
Given two room identifiers return a Stack that has a set of directions to go from one room to the other.
Parameters:
start - the identifier of the starting room.
destination - the identifier of the destination room.
Returns:
a Stack with a set of directions for navigating between the two rooms or null if a path does not exist.

findPathToRoom

public java.util.Stack findPathToRoom(int start,
                                      int destination)
Given two room identifiers return a Stack that has a set of directions to go from one room to the other. If a path is not available between the two rooms try finding a path to the room by going home first.
Parameters:
start - the identifier of the starting room.
destination - the identifier of the destination room.
Returns:
a Stack with a set of directions for navigating between the two rooms or null if a path does not exist.

findPathToRoom

public java.util.Stack findPathToRoom(Room start,
                                      Room destination)
Given two rooms return a Stack that has a set of directions to go from one room to the other. If a path is not available between the two rooms try finding a path to the room by going home first.
Parameters:
start - the starting room
destination - the destination room
Returns:
a Stack with a set of directions for navigating between the two rooms or null if a path does not exist.

makeDirections

public java.lang.String makeDirections(int start,
                                       java.util.Stack s)
This routine runs through the stack backwards and creates a set of human readable directions that the bot is following to go to the destination.
Parameters:
start - the index of the room the bot is starting from.
s - the stack that has the directions

findObject

public java.util.Vector findObject(java.lang.String object)
Finds all of the rooms in the map that contain object.
Parameters:
object - a String representing the object in the MUD to be located.
Returns:
a Vector of all the rooms in the map that contain the object.

readMap

public void readMap()
Deprecated.