public synchronized void move() { _determinesNextTile(); currentTile = _getMinEstimatedCostTile(); nextTile.remove(currentTile); pastTile.add(currentTile); System.out.println(currentTile.getX() + "," + currentTile.getY()); }
private synchronized FbMapTile _getMinEstimatedCostTile() { FbMapTile minEstimatedCostTile = null; for (FbMapTile tile : nextTile) { if (minEstimatedCostTile == null || (minEstimatedCostTile.getEstimatedCost() > tile.getEstimatedCost())) { minEstimatedCostTile = tile; } } return minEstimatedCostTile; }
private synchronized void __determinesNextTile(FbMapTile current, int nextX, int nextY) { try { FbMapTile tile = (current == null) ? originTile : mapTiles.get(current.getX() + nextX).get(current.getY() + nextY); if (!pastTile.contains(tile) && !nextTile.contains(tile)) { if (tile.getTileType().isWalkable()) { tile.setCost((current == null) ? 0 : (current.getCost() + 1)); tile.setEstimatedCost(_countEstimatedCost(tile, destinationTile)); nextTile.add(tile); } } } catch (Exception exception) { logp(exception.toString()); } }
private synchronized int _countEstimatedCost(FbMapTile origin, FbMapTile destination) { return Math.abs(parseInt(origin.getX()) - parseInt(destination.getX())) + Math.abs(parseInt(origin.getY()) - parseInt(destination.getY())); }