byte trackLayout = world.getTile(currentPosition.x,
byte trackLayout = 0; try { trackLayout = world.getTile(currentPosition.x,
    public TrainPath findPath(Point start, Point target) {	/* "Stupidity" filter... */	if (start.equals(target))	    return new TrainPath(new IntLine[0]);	startDirection = CompassPoints.NORTH;	startTrackLayout = world.getTile(start.x,		start.y).getTrackConfiguration();	currentPath = new LinkedList();	bestPath = new LinkedList();	bestCost = Integer.MAX_VALUE;	do {	    startDirection = CompassPoints.rotateClockwise(startDirection);	    currentPath.clear();	    currentPath.add(new IntLine(start.x /			TrackTile.DELTAS_PER_TILE, start.y /			TrackTile.DELTAS_PER_TILE,			startTrackLayout,			CompassPoints.getLength(startDirection) / 2));	    PathElement currentElement = (PathElement) currentPath.getFirst();	    Point currentPosition = new Point(currentElement.x,		    currentElement.y);	    Point oldPosition = new Point();	    do {		/* move to next tile along current direction */		oldPosition.x = currentPosition.x;		oldPosition.y = currentPosition.y;		advanceOneTile(currentPosition, currentElement.direction);		/* is this tile already explored ? */		if (exploredTiles.contains(currentPosition)) {		    /* go back to old tile */		    currentPosition.x = oldPosition.x;		    currentPosition.y = oldPosition.y;		    nextElement(currentPosition);		    continue;		}		/* have we doubled back on ourselves ? */		Iterator i = currentPath.iterator();		boolean flag = false;		do {		    PathElement p = (PathElement) i.next();		    if (currentPosition.x == p.x &&			    currentPosition.y == p.y) {			currentPosition.x = oldPosition.x;			currentPosition.y = oldPosition.y;			flag = true;			break;		    }		} while (i.hasNext());		if (flag) {		    nextElement(currentPosition);		    continue;		}		/* add the current position to the current path */		byte trackLayout = world.getTile(currentPosition.x,			currentPosition.y).getTrackConfiguration();		byte initialDirection =		    CompassPoints.invert(currentElement.direction);		currentElement = new PathElement(currentPosition.x,			currentPosition.y, initialDirection, trackLayout, 1);		currentPath.add(currentElement);		/* have we reached the target ? */		if (currentPosition.equals(target)) {		    i = currentPath.iterator();		    int cost = 0;		    do {			cost += ((PathElement) i.next()).getCost();		    } while (i.hasNext());		    if (cost < bestCost) {			/* this is the new best route */			bestCost = cost;			bestPath.clear();		       	i = currentPath.iterator();			do {			    bestPath.add(new PathElement((PathElement)					i.next()));		       	} while (i.hasNext());		    }		}		nextElement(currentPosition);	    } while (currentPath.size() > 1);	} while (startDirection != CompassPoints.NORTH);	/* all possible paths have been explored */	if (bestPath.isEmpty())	    return new TrainPath(new IntLine[0]);	/* convert the ArrayList to a TrainPath. bestPath always contains the	 * target tile and the start tile */	Point oldp = new Point();	Point newp = new Point();	byte oldDirection;	PathElement p = (PathElement) bestPath.removeFirst();	LinkedList intLines = new LinkedList();	boolean firstP = true;	while (!bestPath.isEmpty()) {	    oldp.x = p.x;	    oldp.y = p.y;	    oldDirection = p.direction;	    while (p.direction == oldDirection) {		p = (PathElement) bestPath.removeFirst();		newp.x = p.x;		newp.y = p.y;	    }	    if (firstP) {		oldp.x = start.x;		oldp.y = start.y;		firstP = false;	    } else {		oldp = TrackTile.tileCoordsToDeltas(oldp);	    }	    newp = TrackTile.tileCoordsToDeltas(newp);	    IntLine l = new IntLine(oldp.x, oldp.y, newp.x, newp.y);	    intLines.add(l);	}	return new TrainPath((IntLine[]) intLines.toArray(new		    IntLine[intLines.size()]));    }