TerrainMap Class Reference

A class representing the world, start and end points, and visited squares. More...

List of all members.

Public Types

enum  MovementType { Chess, Euclidean, Manhattan }
 Enumeration of possible Movement Types. More...

Public Member Functions

 TerrainMap (final int width, final int height, final TerrainGenerator terraGen, final MovementType moveType, final boolean chaotic)
 Creates a new map and forces the random number seed.
Point getStartPoint ()
 Returns the start point of the path.
Point getEndPoint ()
 Returns the end point of the path.
boolean validTile (final int x, final int y)
 Checks whether a tile is in the map.
boolean validTile (final Point pt)
 Checks whether a tile is in the map.
int getTile (final int x, final int y)
 Gets the value of a tile.
int getTile (final Point pt)
 Gets the value of a tile.
boolean isAdjacent (final Point p1, final Point p2)
 Determines if points are adjacent.
boolean isDiagonal (final Point p1, final Point p2)
 Determines if two points are one diagonal away from each other.
Point[] getNeighbors (final Point pt)
 Gets an array of legal transitions.
double getCost (final Point p1, final Point p2)
 Returns the cost to move from one point to another.
int getWidth ()
 Returns the width of the map.
int getHeight ()
 Returns the height of the map.
double findPath (final AIModule module)
 Entry point to pathfinding.
int getNumVisited ()
 Returns the number of squares that have been visited so far.
BufferedImage createImage ()
 Returns a graphical representation of the generated path.
BufferedImage createContourImage ()
 Returns a graphical representation of the contour map.

Private Member Functions

double verifyPath (final List< Point > path)
 Confirms that a given path is legal and returns its cost.
BufferedImage toBufferedImage ()
 Creates a gray-scale BufferedImage representing the map.
void toBoard (final BufferedImage im)
 Sets the terrain values based off of a gray-scale BufferedImage.
void runChaos ()
 Modify the terrain a little bit.
void down ()
 Aquires the semaphore.
void up ()
 Release the semaphore.

Private Attributes

final MovementType moveType
final byte[][] Board
 The world, represented as an array of values from 0 - 255 (inclusive).
final int[][] Uncovered
 An array keeping track of which tiles have been visited.
ArrayList< Point > path
 After computing a path from the start to the end, that path is stored here.
final int Width
 Width of the world.
final int Height
 Height of the world.
final Point StartPoint
 Start point of your journey.
final Point EndPoint
 End point of your journey.
int uncoveredCounter
 Timestamp of the last uncovered point.
final boolean chaotic
 Determines whether or not the map changes over time.
final Semaphore sem = new Semaphore(1, true)
 Blocks functions during map chaotisism.
final Timer timer = new Timer()
 Activates map chaotisism at scheduled times.
final TimerTask task
 Task for timer to activate.

Static Private Attributes

static final double SQRT_2 = Math.sqrt(2.0)
 Constant square root of two.


Detailed Description

A class representing the world, start and end points, and visited squares.

TerrainMap encapsulates the world information, the start and end points of your journey, and maintains a set of all visited points in the world. You will need to familiarize yourself with this class's methods in order to write your AI solution.

The world is represented as a two-dimensional grid of tiles, where each tile has a height between 0 and 255. You can move from any tile to any adjacent tile, including diagonals. The cost to traverse from one tile to another is equal to exp(|h1 - h0|), where exp is the exponential function and h1 and h0 are the heights of the source and destination tiles. Thus walking from one square to another square of equal height costs 1, while walking from one square to another square one square lower or higher would cost about 2.71828182845945... :-)

The TerrainMap's getTile function both returns the value of the specified tile and records that the tile was revealed. Part of your grade on this assignment will be based on how many different tiles you reveal, so your solution should try to minimize tile visits. On the plus side, though, many good search algorithms automatically have this property.

Author:
Leonid Shamis

Definition at line 30 of file TerrainMap.java.


Member Enumeration Documentation

Enumeration of possible Movement Types.

Enumerator:
Chess 
Euclidean 
Manhattan 

Definition at line 36 of file TerrainMap.java.


Constructor & Destructor Documentation

TerrainMap.TerrainMap ( final int  width,
final int  height,
final TerrainGenerator  terraGen,
final MovementType  moveType,
final boolean  chaotic 
)

Creates a new map and forces the random number seed.

Create a new random TerrainMap using the given dimensions, roughness and the specified random number seed. These parameters are adjustable at the command line; see Main.main for more information.

It is strongly recommended that you test your code using fixed seeds to make it easier to smoke out latent bugs.

Parameters:
width The width of the map to create.
height The height of the map to create.
terraGen The generator used to create the terrain.
moveType The type of movement that will be allowed for this terrain.
chaotic Should the terrain erupt.
See also:
Main

Definition at line 102 of file TerrainMap.java.


Member Function Documentation

BufferedImage TerrainMap.createContourImage (  ) 

Returns a graphical representation of the contour map.

After calling findPath, you may call this function to retrieve a graphical version of the contour map.

Returns:
A graphical representation of the map.
Exceptions:
IllegalStateException If findPath hasn't completed successfully.

Definition at line 454 of file TerrainMap.java.

BufferedImage TerrainMap.createImage (  ) 

Returns a graphical representation of the generated path.

After calling findPath, you may call this function to retrieve a graphical version of the map.

Returns:
A graphical representation of the map.
Exceptions:
IllegalStateException If findPath hasn't completed successfully.

Definition at line 399 of file TerrainMap.java.

void TerrainMap.down (  )  [private]

Aquires the semaphore.

Definition at line 527 of file TerrainMap.java.

double TerrainMap.findPath ( final AIModule  module  ) 

Entry point to pathfinding.

Given an AI module, has the module compute the path from the start location to the end location, then stores the path for later use. The function also returns the cost of the generated path.

Parameters:
module The AI module to use to compute the path.
Returns:
The cost of the path.

Definition at line 315 of file TerrainMap.java.

double TerrainMap.getCost ( final Point  p1,
final Point  p2 
)

Returns the cost to move from one point to another.

The cost to move from one tile to another is exp(|h1 - h0|), where exp is the exponential function and h1 and h0 are the heights of the tiles. This function will mark both of the points as visited.

Parameters:
p1 The first point.
p2 The second point.
Returns:
The cost to move from the first point to the second point.

Definition at line 282 of file TerrainMap.java.

Point TerrainMap.getEndPoint (  ) 

Returns the end point of the path.

Returns:
The path's end point.

Definition at line 139 of file TerrainMap.java.

int TerrainMap.getHeight (  ) 

Returns the height of the map.

Definition at line 301 of file TerrainMap.java.

Point [] TerrainMap.getNeighbors ( final Point  pt  ) 

Gets an array of legal transitions.

Given a point, returns a list of all neighboring positions.

Parameters:
pt The active point.
Returns:
A list of all neighboring positions.

Definition at line 255 of file TerrainMap.java.

int TerrainMap.getNumVisited (  ) 

Returns the number of squares that have been visited so far.

Definition at line 374 of file TerrainMap.java.

Point TerrainMap.getStartPoint (  ) 

Returns the start point of the path.

Returns:
The path's start point.

Definition at line 130 of file TerrainMap.java.

int TerrainMap.getTile ( final Point  pt  ) 

Gets the value of a tile.

Given a point, returns the value of the tile at that position. This function also marks that location as visited. Part of your grade on this assignment will be determined by how many tiles your solution visits.

Parameters:
pt The point to look up.
Returns:
The value of the tile at that location.

Definition at line 207 of file TerrainMap.java.

int TerrainMap.getTile ( final int  x,
final int  y 
)

Gets the value of a tile.

Given an X and Y coordinate, returns the value of the tile at that position. This function also marks that location as visited. Part of your grade on this assignment will be determined by how many tiles your solution visits.

Parameters:
x The X coordinate.
y The Y coordinate.
Returns:
The value of the tile at that location.

Definition at line 181 of file TerrainMap.java.

int TerrainMap.getWidth (  ) 

Returns the width of the map.

Definition at line 295 of file TerrainMap.java.

boolean TerrainMap.isAdjacent ( final Point  p1,
final Point  p2 
)

Determines if points are adjacent.

Given two points, returns whether or not those points are adjacent.

Parameters:
p1 The first point.
p2 The second point.
Returns:
Whether the points are adjacent.

Definition at line 220 of file TerrainMap.java.

boolean TerrainMap.isDiagonal ( final Point  p1,
final Point  p2 
)

Determines if two points are one diagonal away from each other.

Given two points, returns whether or not those points are diagonal.

Parameters:
p1 The first point.
p2 The second point.
Returns:
Whether the points are diagonal.

Definition at line 238 of file TerrainMap.java.

void TerrainMap.runChaos (  )  [private]

Modify the terrain a little bit.

Definition at line 513 of file TerrainMap.java.

void TerrainMap.toBoard ( final BufferedImage  im  )  [private]

Sets the terrain values based off of a gray-scale BufferedImage.

Definition at line 497 of file TerrainMap.java.

BufferedImage TerrainMap.toBufferedImage (  )  [private]

Creates a gray-scale BufferedImage representing the map.

Definition at line 480 of file TerrainMap.java.

void TerrainMap.up (  )  [private]

Release the semaphore.

Definition at line 540 of file TerrainMap.java.

boolean TerrainMap.validTile ( final Point  pt  ) 

Checks whether a tile is in the map.

Given a point representing a coordinate, returns whether that point is contained in the map.

Parameters:
pt The point in question.
Returns:
Whether that point is in the map.

Definition at line 166 of file TerrainMap.java.

boolean TerrainMap.validTile ( final int  x,
final int  y 
)

Checks whether a tile is in the map.

Given an X and Y coordinate, returns whether or not that point is contained in the map.

Parameters:
x The X coordinate.
y The Y coordinate.
Returns:
Whether the point (x, y) is in the map.

Definition at line 153 of file TerrainMap.java.

double TerrainMap.verifyPath ( final List< Point >  path  )  [private]

Confirms that a given path is legal and returns its cost.

Given a path generated by an AI module, confirms that the path correctly navigates from the start point to the end point. Returns the cost of that path.

Parameters:
path The generated path.
Returns:
The cost to take the path.

Definition at line 333 of file TerrainMap.java.


Member Data Documentation

final byte [][] TerrainMap.Board [private]

The world, represented as an array of values from 0 - 255 (inclusive).

Definition at line 44 of file TerrainMap.java.

final boolean TerrainMap.chaotic [private]

Determines whether or not the map changes over time.

Definition at line 68 of file TerrainMap.java.

final Point TerrainMap.EndPoint [private]

End point of your journey.

Definition at line 62 of file TerrainMap.java.

final int TerrainMap.Height [private]

Height of the world.

Definition at line 56 of file TerrainMap.java.

Definition at line 41 of file TerrainMap.java.

ArrayList<Point> TerrainMap.path [private]

After computing a path from the start to the end, that path is stored here.

Definition at line 50 of file TerrainMap.java.

final Semaphore TerrainMap.sem = new Semaphore(1, true) [private]

Blocks functions during map chaotisism.

Definition at line 71 of file TerrainMap.java.

final double TerrainMap.SQRT_2 = Math.sqrt(2.0) [static, private]

Constant square root of two.

Definition at line 33 of file TerrainMap.java.

final Point TerrainMap.StartPoint [private]

Start point of your journey.

Definition at line 59 of file TerrainMap.java.

final TimerTask TerrainMap.task [private]

Initial value:

 new TimerTask()
    {
        @Override
        public void run()
        {
            runChaos();
        }
    }
Task for timer to activate.

Definition at line 77 of file TerrainMap.java.

final Timer TerrainMap.timer = new Timer() [private]

Activates map chaotisism at scheduled times.

Definition at line 74 of file TerrainMap.java.

final int [][] TerrainMap.Uncovered [private]

An array keeping track of which tiles have been visited.

Definition at line 47 of file TerrainMap.java.

Timestamp of the last uncovered point.

Definition at line 65 of file TerrainMap.java.

final int TerrainMap.Width [private]

Width of the world.

Definition at line 53 of file TerrainMap.java.


The documentation for this class was generated from the following file:

Generated on Tue Apr 14 13:50:26 2009 for Path Finder by  doxygen 1.5.8