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. | |
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.
Definition at line 30 of file TerrainMap.java.
| 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.
| 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. |
Definition at line 102 of file TerrainMap.java.
| 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.
| 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.
| IllegalStateException | If findPath hasn't completed successfully. |
Definition at line 399 of file TerrainMap.java.
| void TerrainMap.down | ( | ) | [private] |
| 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.
| module | The AI module to use to compute 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.
| p1 | The first point. | |
| p2 | The second point. |
Definition at line 282 of file TerrainMap.java.
| Point TerrainMap.getEndPoint | ( | ) |
Returns the end point of the path.
Definition at line 139 of file TerrainMap.java.
| int TerrainMap.getHeight | ( | ) |
| Point [] TerrainMap.getNeighbors | ( | final Point | pt | ) |
Gets an array of legal transitions.
Given a point, returns a list of all neighboring positions.
| pt | The active point. |
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.
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.
| pt | The point to look up. |
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.
| x | The X coordinate. | |
| y | The Y coordinate. |
Definition at line 181 of file TerrainMap.java.
| int TerrainMap.getWidth | ( | ) |
| 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.
| p1 | The first point. | |
| p2 | The second point. |
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.
| p1 | The first point. | |
| p2 | The second point. |
Definition at line 238 of file TerrainMap.java.
| void TerrainMap.runChaos | ( | ) | [private] |
| 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] |
| 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.
| pt | The point in question. |
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.
| x | The X coordinate. | |
| y | The Y coordinate. |
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.
| path | The generated path. |
Definition at line 333 of file TerrainMap.java.
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] |
final Point TerrainMap.EndPoint [private] |
final int TerrainMap.Height [private] |
final MovementType TerrainMap.moveType [private] |
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] |
final double TerrainMap.SQRT_2 = Math.sqrt(2.0) [static, private] |
final Point TerrainMap.StartPoint [private] |
final TimerTask TerrainMap.task [private] |
Initial value:
new TimerTask() { @Override public void run() { runChaos(); } }
Definition at line 77 of file TerrainMap.java.
final Timer TerrainMap.timer = new Timer() [private] |
final int [][] TerrainMap.Uncovered [private] |
An array keeping track of which tiles have been visited.
Definition at line 47 of file TerrainMap.java.
int TerrainMap.uncoveredCounter [private] |
final int TerrainMap.Width [private] |
1.5.8