Skip to content

Instantly share code, notes, and snippets.

@sparr
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sparr/a882711c992a96aa4d4c to your computer and use it in GitHub Desktop.
Save sparr/a882711c992a96aa4d4c to your computer and use it in GitHub Desktop.
Attempt at avoiding certain death situations in codegolf.se koth dogfight
// has this plane hit a wall, or is it guaranteed to?
boolean dangerZone(Plane icarus) {
// outside the arena is instant death
if (!icarus.getPosition().isInArena(arenaSize)) {
return true;
}
// adjacent to a wall?
// directly facing the wall?
// death next turn
if (
icarus.getDirection().getMainDirections().length==1 &&
icarus.getDistanceFromWall(icarus.getDirection().getMainDirections()[0]) == 0
) {
// System.err.println("death case 1!");
return true;
}
// on an edge?
// 2d diagonal facing into that edge?
// death next turn
if (
icarus.getDirection().getMainDirections().length==2 &&
icarus.getDistanceFromWall(icarus.getDirection().getMainDirections()[0]) == 0 &&
icarus.getDistanceFromWall(icarus.getDirection().getMainDirections()[1]) == 0
) {
// System.err.println("death case 2!");
return true;
}
// near a corner?
// 3d diagonal facing into that corner?
// death in 1-2 turns
if (
icarus.getDirection().getMainDirections().length==3 &&
icarus.getDistanceFromWall(icarus.getDirection().getMainDirections()[0]) < 2 &&
icarus.getDistanceFromWall(icarus.getDirection().getMainDirections()[1]) < 2 &&
icarus.getDistanceFromWall(icarus.getDirection().getMainDirections()[2]) < 2
) {
// System.err.println("death case 3!");
return true;
}
// there's at least one way out of this position
return false;
}
ArrayList<Direction> potentialDirections_turn = new ArrayList<Direction>();
ArrayList<Direction> potentialDirections_drift = new ArrayList<Direction>();
for (Direction candidateDirection : myPlanes[i].getPossibleDirections()) {
Plane future = new Plane(arenaSize, 0, myPlanes[i].getDirection(), myPlanes[i].getPosition().add(candidateDirection.getAsPoint3D()));
if (!dangerZone(future)) {
potentialDirections_drift.add(candidateDirection);
}
future = new Plane(arenaSize, 0, candidateDirection, myPlanes[i].getPosition().add(candidateDirection.getAsPoint3D()));
if (!dangerZone(future)) {
potentialDirections_turn.add(candidateDirection);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment