src/gamemechanics/Util.java
public static boolean moveTo(MapLocation goalLocation) throws GameActionException {
		if (rc.hasMoved() || rc.getLocation().equals(goalLocation))
			return false;

		if (path == null) {
			path = new MapLocation[PATH_LENGTH];
			for (int i = 0; i < PATH_LENGTH; i++) {
				path[i] = new MapLocation(1000, 1000);
			}
		}

		Direction dir = rc.getLocation().directionTo(goalLocation);
		float speed = rc.getType().strideRadius;
		float minDistance = speed * speed;

		for (int i = 0; i <= NUM_CHECKS; i++) {
			// 0, Pi and left rotations
			MapLocation locationAfterMove = rc.getLocation().add(dir.rotateLeftRads(i * directionAngle), speed);

			if (checkMove(locationAfterMove, minDistance)) {
				return true;
			}

			if (i == 0 || i == NUM_CHECKS)
				continue;

			// right rotations
			locationAfterMove = rc.getLocation().add(dir.rotateRightRads(i * directionAngle), speed);

			if (checkMove(locationAfterMove, minDistance)) {
				return true;
			}

		}

		// escape move
		if (rc.canMove(path[lastPointer])) {
			if (!backtrack) {
				lastBeforeBacktrack = lastPointer;
				backtrack = true;
			}
			rc.move(path[lastPointer]);
			lastPointer = (lastPointer - 1 + PATH_LENGTH) % PATH_LENGTH;
			return true;
		}

		return false;
	}
/**
	 * 
	 * This is my implementation of the slug Pathing algorithm. I use a Array as
	 * a ring to store the path the robot walked and added backtracking. That
	 * means if the robot gets stuck it follows its own path back, until it's
	 * not stuck anymore. TODO 1.) Add a Lookahead so that the robot dosen't
	 * need to go the path witch he will backtrack anyways. 2.) Check if the
	 * Robot has left a certain area in x Turns. Maybe with a second slug
	 * algorithm witch has a separate list with fewer points but a lot bigger
	 * radius.
	 * 
	 * @param goalLocation
	 * @return
	 * @throws GameActionException
	 */
This is my implementation of the slug Pathing algorithm. I use a Array as
a ring to store the path the robot walked and added backtracking. That
means if the robot gets stuck it follows its own path back, until it's
not stuck anymore. TODO 1.) Add a Lookahead so that the robot dosen't
need to go the path witch he will backtrack anyways. 2.) Check if the
Robot has left a certain area in x Turns. Maybe with a second slug
algorithm witch has a separate list with fewer points but a lot bigger
radius.

@param goalLocation
@return
@throws GameActionException
This is my implementation of the slug Pathing algorithm . I use a Array as a ring to store the path the robot walked and added backtracking . That means if the robot gets stuck it follows its own path back until it ' s not stuck anymore . TODO 1 . ) Add a Lookahead so that the robot dosen ' t need to go the path witch he will backtrack anyways . 2 . ) Check if the Robot has left a certain area in x Turns . Maybe with a second slug algorithm witch has a separate list with fewer points but a lot bigger radius . @param goalLocation @return @throws GameActionException
public static boolean moveTo(MapLocation goalLocation) throws GameActionException {
		if (rc.hasMoved() || rc.getLocation().equals(goalLocation))
			return false;
		if (path == null) {
			path = new MapLocation[PATH_LENGTH];
			for (int i = 0; i < PATH_LENGTH; i++) {
				path[i] = new MapLocation(1000, 1000);
			}
		}
		Direction dir = rc.getLocation().directionTo(goalLocation);
		float speed = rc.getType().strideRadius;
		float minDistance = speed * speed;
		for (int i = 0; i <= NUM_CHECKS; i++) {
			MapLocation locationAfterMove = rc.getLocation().add(dir.rotateLeftRads(i * directionAngle), speed);
			if (checkMove(locationAfterMove, minDistance)) {
				return true;
			}
			if (i == 0 || i == NUM_CHECKS)
				continue;
			locationAfterMove = rc.getLocation().add(dir.rotateRightRads(i * directionAngle), speed);
			if (checkMove(locationAfterMove, minDistance)) {
				return true;
			}
		}
		if (rc.canMove(path[lastPointer])) {
			if (!backtrack) {
				lastBeforeBacktrack = lastPointer;
				backtrack = true;
			}
			rc.move(path[lastPointer]);
			lastPointer = (lastPointer - 1 + PATH_LENGTH) % PATH_LENGTH;
			return true;
		}
		return false;
	}
public static boolean moveTo ( MapLocation goalLocation ) throws GameActionException { if ( rc . hasMoved ( ) || rc . getLocation ( ) . equals ( goalLocation ) ) return false ; if ( path == null ) { path = new MapLocation [ PATH_LENGTH ] ; for ( int i = 0 ; i < PATH_LENGTH ; i ++ ) { path [ i ] = new MapLocation ( 1000 , 1000 ) ; } } Direction dir = rc . getLocation ( ) . directionTo ( goalLocation ) ; float speed = rc . getType ( ) . strideRadius ; float minDistance = speed * speed ; for ( int i = 0 ; i <= NUM_CHECKS ; i ++ ) { MapLocation locationAfterMove = rc . getLocation ( ) . add ( dir . rotateLeftRads ( i * directionAngle ) , speed ) ; if ( checkMove ( locationAfterMove , minDistance ) ) { return true ; } if ( i == 0 || i == NUM_CHECKS ) continue ; locationAfterMove = rc . getLocation ( ) . add ( dir . rotateRightRads ( i * directionAngle ) , speed ) ; if ( checkMove ( locationAfterMove , minDistance ) ) { return true ; } } if ( rc . canMove ( path [ lastPointer ] ) ) { if ( ! backtrack ) { lastBeforeBacktrack = lastPointer ; backtrack = true ; } rc . move ( path [ lastPointer ] ) ; lastPointer = ( lastPointer - 1 + PATH_LENGTH ) % PATH_LENGTH ; return true ; } return false ; }
This is my implementation of the slug Pathing algorithm.
This is my implementation of the slug Pathing algorithm .
// 0, Pi and left rotations // right rotations // escape move