jfreerails.controller
Class BuildTrackExplorer

java.lang.Object
  extended by jfreerails.controller.BuildTrackExplorer
All Implemented Interfaces:
GraphExplorer

public class BuildTrackExplorer
extends java.lang.Object
implements GraphExplorer

GraphExplorer that explorers possible track placements, the ints it returns are encoded PositionOnTrack objects.

Author:
Luke

Field Summary
private  boolean beforeFirst
           
private  BuildTrackStrategy buildTrackStrategy
           
(package private)  PositionOnTrack currentBranch
           
private  PositionOnTrack currentPosition
           
private  int directionInt
           
private  FreerailsPrincipal principle
           
private  ImPoint target
           
private static TrackConfiguration TILE_CENTER
           
private  boolean usingExistingTrack
           
private  ReadOnlyWorld world
           
 
Constructor Summary
BuildTrackExplorer(ReadOnlyWorld w, FreerailsPrincipal principle)
           
BuildTrackExplorer(ReadOnlyWorld w, FreerailsPrincipal principle, ImPoint start, ImPoint target)
           
 
Method Summary
private  boolean canBuildTrack()
           Tests whether we can build track in the direction specified by m_direction.
private  TrackRule getAppropriateTrackRule(int x, int y)
           
 int getEdgeCost()
          Calculates a cost figure incorporating the distance and the cost of any new track.
 int getH()
           
 int getPosition()
          Return the current edge.
 int getVertexConnectedByEdge()
          Returns the vertex that is connected to the current vertex by the current edge.
 boolean hasNextEdge()
           
 void moveForward()
          Moves this GraphExplorer from the current vertex to the vertex that is connected to the current vertex by the current edge.
 void nextEdge()
          Sets the current edge to the current vertex's next edge.
 void setBuildTrackStrategy(BuildTrackStrategy trackStrategy)
           
 void setPosition(int vertex)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TILE_CENTER

private static final TrackConfiguration TILE_CENTER

beforeFirst

private boolean beforeFirst

currentBranch

final PositionOnTrack currentBranch

currentPosition

private final PositionOnTrack currentPosition

directionInt

private int directionInt

target

private final ImPoint target

buildTrackStrategy

private BuildTrackStrategy buildTrackStrategy

usingExistingTrack

private boolean usingExistingTrack

world

private final ReadOnlyWorld world

principle

private final FreerailsPrincipal principle
Constructor Detail

BuildTrackExplorer

public BuildTrackExplorer(ReadOnlyWorld w,
                          FreerailsPrincipal principle)

BuildTrackExplorer

public BuildTrackExplorer(ReadOnlyWorld w,
                          FreerailsPrincipal principle,
                          ImPoint start,
                          ImPoint target)
Method Detail

canBuildTrack

private boolean canBuildTrack()

Tests whether we can build track in the direction specified by m_direction.

If we enter a tile from a given direction, the tiles we can build track to depend on the following. (1) The terrain type of the surrounding tiles - track can only be built on certain terrain types. (2) The direction we entered the current tile from. (3) Any existing track on the current tile - limits possible track configurations. (4) The terrain type of the current tile - terrain type determines which track types and hence which track configurations can be built.


getAppropriateTrackRule

private TrackRule getAppropriateTrackRule(int x,
                                          int y)

getEdgeCost

public int getEdgeCost()
Calculates a cost figure incorporating the distance and the cost of any new track.

Specified by:
getEdgeCost in interface GraphExplorer

getH

public int getH()
Specified by:
getH in interface GraphExplorer

getPosition

public int getPosition()
Description copied from interface: GraphExplorer
Return the current edge.

Specified by:
getPosition in interface GraphExplorer

getVertexConnectedByEdge

public int getVertexConnectedByEdge()
Description copied from interface: GraphExplorer
Returns the vertex that is connected to the current vertex by the current edge.

Specified by:
getVertexConnectedByEdge in interface GraphExplorer

hasNextEdge

public boolean hasNextEdge()
Specified by:
hasNextEdge in interface GraphExplorer

moveForward

public void moveForward()
Description copied from interface: GraphExplorer
Moves this GraphExplorer from the current vertex to the vertex that is connected to the current vertex by the current edge.

Specified by:
moveForward in interface GraphExplorer

nextEdge

public void nextEdge()
Description copied from interface: GraphExplorer
Sets the current edge to the current vertex's next edge. Throws a NoSuchElementException if the vertex does not have another edge.

Specified by:
nextEdge in interface GraphExplorer

setPosition

public void setPosition(int vertex)
Specified by:
setPosition in interface GraphExplorer

setBuildTrackStrategy

public void setBuildTrackStrategy(BuildTrackStrategy trackStrategy)