Skip to content

Instantly share code, notes, and snippets.

@taptapdan
Created December 26, 2015 19:32
Show Gist options
  • Select an option

  • Save taptapdan/27e3e2a38fca0e0c8e22 to your computer and use it in GitHub Desktop.

Select an option

Save taptapdan/27e3e2a38fca0e0c8e22 to your computer and use it in GitHub Desktop.
CodeCombat: Boulder Woods Solution
// Use isPathClear to move around the randomly positioned boulders.
// Automatic pathfinding doesn't work in Boulder Woods.
loop {
var angle = Math.PI / 2 - Math.PI / 16;
while (angle >= -Math.PI / 2) {
var targetX = this.pos.x + 5 * Math.cos(angle);
var targetY = this.pos.y + 5 * Math.sin(angle);
// Use isPathClear between your current pos and the target.
targetPos = { x: targetX, y: targetY };
// If the path is clear, move to the target.
if (this.isPathClear(this.pos, targetPos) ) {
this.move(targetPos);
// Otherwise, sweep the angle clockwise a bit.
} else {
angle -= Math.PI / 16;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment