src/robots/Gardener.java
public static boolean tryBuildRobot(Direction dir, RobotType robotType, float degreeOffset, int checksPerSide)
			throws GameActionException {
		// First, try intended direction
		if (rc.canBuildRobot(robotType, dir)) {
			rc.buildRobot(robotType, dir);
			return true;
		}

		// Now try a bunch of similar angles
		int currentCheck = 1;

		while (currentCheck <= checksPerSide) {
			// Try the offset of the left side
			if (rc.canBuildRobot(robotType, dir.rotateLeftDegrees(degreeOffset * currentCheck))) {
				rc.buildRobot(robotType, dir.rotateLeftDegrees(degreeOffset * currentCheck));
				return true;
			}
			// Try the offset on the right side
			if (rc.canBuildRobot(robotType, dir.rotateRightDegrees(degreeOffset * currentCheck))) {
				rc.buildRobot(robotType, dir.rotateRightDegrees(degreeOffset * currentCheck));
				return true;
			}
			// No gardener hired, try slightly further
			currentCheck++;
		}

		// A gardener was never hired, so return false.
		return false;
	}
/**
	 * Try to build a Robot in Direction dir, while avoiding small obstacles.
	 * 
	 * @param dir
	 *            Intended Direction
	 * @param RobotType
	 *            the Type of the Robot
	 * @param degreeOffset
	 *            offset if first direction is impossible
	 * @param checksPerSide
	 *            Amount of checks on each side
	 * @return true if a Gardener was hired false otherwise
	 * @throws GameActionException
	 */
Try to build a Robot in Direction dir, while avoiding small obstacles.


Try to build a Robot in Direction dir while avoiding small obstacles .
public static boolean tryBuildRobot(Direction dir, RobotType robotType, float degreeOffset, int checksPerSide)
			throws GameActionException {
		if (rc.canBuildRobot(robotType, dir)) {
			rc.buildRobot(robotType, dir);
			return true;
		}
		int currentCheck = 1;
		while (currentCheck <= checksPerSide) {
			if (rc.canBuildRobot(robotType, dir.rotateLeftDegrees(degreeOffset * currentCheck))) {
				rc.buildRobot(robotType, dir.rotateLeftDegrees(degreeOffset * currentCheck));
				return true;
			}
			if (rc.canBuildRobot(robotType, dir.rotateRightDegrees(degreeOffset * currentCheck))) {
				rc.buildRobot(robotType, dir.rotateRightDegrees(degreeOffset * currentCheck));
				return true;
			}
			currentCheck++;
		}
		return false;
	}
public static boolean tryBuildRobot ( Direction dir , RobotType robotType , float degreeOffset , int checksPerSide ) throws GameActionException { if ( rc . canBuildRobot ( robotType , dir ) ) { rc . buildRobot ( robotType , dir ) ; return true ; } int currentCheck = 1 ; while ( currentCheck <= checksPerSide ) { if ( rc . canBuildRobot ( robotType , dir . rotateLeftDegrees ( degreeOffset * currentCheck ) ) ) { rc . buildRobot ( robotType , dir . rotateLeftDegrees ( degreeOffset * currentCheck ) ) ; return true ; } if ( rc . canBuildRobot ( robotType , dir . rotateRightDegrees ( degreeOffset * currentCheck ) ) ) { rc . buildRobot ( robotType , dir . rotateRightDegrees ( degreeOffset * currentCheck ) ) ; return true ; } currentCheck ++ ; } return false ; }
Try to build a Robot in Direction dir, while avoiding small obstacles.
Try to build a Robot in Direction dir while avoiding small obstacles .
// First, try intended direction // Now try a bunch of similar angles // Try the offset of the left side // Try the offset on the right side // No gardener hired, try slightly further // A gardener was never hired, so return false.