private int findFreeStartingPosition(Heat heat, int recommendedStartingPosition) { int pos = -1; //Try the recommended Position if (heat.isPositionFree(recommendedStartingPosition)) { pos = recommendedStartingPosition; } else { int posStep = 1; //Check all position above and below the recommended starting position, prefere position further back while (pos == -1) { int tmpPosLow = recommendedStartingPosition - posStep; int tmpPosHigh = recommendedStartingPosition + posStep; if (tmpPosLow <= 0) { tmpPosLow = 1; } if (tmpPosHigh > _heatSize) { tmpPosHigh = _heatSize; } if (heat.isPositionFree(tmpPosHigh)) { pos = tmpPosHigh; } else if (heat.isPositionFree(tmpPosLow)) { pos = tmpPosLow; } else { //Increase step size on grid posStep++; } } } return(pos); }