use of spacesettlers.objects.Beacon in project spacesettlers by amymcgovern.
the class PacifistHeuristicAsteroidCollectorTeamClient method getAsteroidCollectorAction.
/**
* Gets the action for the asteroid collecting ship
* @param space
* @param ship
* @return
*/
private AbstractAction getAsteroidCollectorAction(Toroidal2DPhysics space, Ship ship) {
AbstractAction current = ship.getCurrentAction();
Position currentPosition = ship.getPosition();
// aim for a beacon if there isn't enough energy
if (ship.getEnergy() < 2000) {
Beacon beacon = pickNearestBeacon(space, ship);
AbstractAction newAction = null;
// if there is no beacon, then just skip a turn
if (beacon == null) {
newAction = new DoNothingAction();
} else {
newAction = new MoveToObjectAction(space, currentPosition, beacon);
}
aimingForBase.put(ship.getId(), false);
return newAction;
}
// if the ship has enough resourcesAvailable, take it back to base
if (ship.getResources().getTotal() > 500) {
Base base = findNearestBase(space, ship);
AbstractAction newAction = new MoveToObjectAction(space, currentPosition, base);
aimingForBase.put(ship.getId(), true);
return newAction;
}
// did we bounce off the base?
if (ship.getResources().getTotal() == 0 && ship.getEnergy() > 2000 && aimingForBase.containsKey(ship.getId()) && aimingForBase.get(ship.getId())) {
current = null;
aimingForBase.put(ship.getId(), false);
}
// otherwise aim for the asteroid
if (current == null || current.isMovementFinished(space)) {
aimingForBase.put(ship.getId(), false);
Asteroid asteroid = pickHighestValueNearestFreeAsteroid(space, ship);
AbstractAction newAction = null;
/*if (asteroid == null) {
// there is no asteroid available so collect a beacon
Beacon beacon = pickNearestBeacon(space, ship);
// if there is no beacon, then just skip a turn
if (beacon == null) {
newAction = new DoNothingAction();
} else {
newAction = new MoveToObjectAction(space, currentPosition, beacon);
}
} else {
asteroidToShipMap.put(asteroid.getId(), ship);
newAction = new MoveToObjectAction(space, currentPosition, asteroid);
}*/
if (asteroid != null) {
asteroidToShipMap.put(asteroid.getId(), ship);
newAction = new MoveToObjectAction(space, currentPosition, asteroid, asteroid.getPosition().getTranslationalVelocity());
}
return newAction;
}
return ship.getCurrentAction();
}
use of spacesettlers.objects.Beacon in project spacesettlers by amymcgovern.
the class PacifistHeuristicAsteroidCollectorTeamClient method pickNearestBeacon.
/**
* Find the nearest beacon to this ship
* @param space
* @param ship
* @return
*/
private Beacon pickNearestBeacon(Toroidal2DPhysics space, Ship ship) {
// get the current beacons
Set<Beacon> beacons = space.getBeacons();
Beacon closestBeacon = null;
double bestDistance = Double.POSITIVE_INFINITY;
for (Beacon beacon : beacons) {
double dist = space.findShortestDistance(ship.getPosition(), beacon.getPosition());
if (dist < bestDistance) {
bestDistance = dist;
closestBeacon = beacon;
}
}
return closestBeacon;
}
use of spacesettlers.objects.Beacon in project spacesettlers by amymcgovern.
the class AggressiveFlagCollectorTeamClient method pickNearestBeacon.
/**
* Find the nearest beacon to this ship
* @param space
* @param ship
* @return
*/
private Beacon pickNearestBeacon(Toroidal2DPhysics space, Ship ship) {
// get the current beacons
Set<Beacon> beacons = space.getBeacons();
Beacon closestBeacon = null;
double bestDistance = Double.POSITIVE_INFINITY;
for (Beacon beacon : beacons) {
double dist = space.findShortestDistance(ship.getPosition(), beacon.getPosition());
if (dist < bestDistance) {
bestDistance = dist;
closestBeacon = beacon;
}
}
return closestBeacon;
}
use of spacesettlers.objects.Beacon in project spacesettlers by amymcgovern.
the class AggressiveHeuristicAsteroidCollectorSingletonTeamClient method pickNearestBeacon.
/**
* Find the nearest beacon to this ship
* @param space
* @param ship
* @return
*/
private Beacon pickNearestBeacon(Toroidal2DPhysics space, Ship ship) {
// get the current beacons
Set<Beacon> beacons = space.getBeacons();
Beacon closestBeacon = null;
double bestDistance = Double.POSITIVE_INFINITY;
for (Beacon beacon : beacons) {
double dist = space.findShortestDistance(ship.getPosition(), beacon.getPosition());
if (dist < bestDistance) {
bestDistance = dist;
closestBeacon = beacon;
}
}
return closestBeacon;
}
use of spacesettlers.objects.Beacon in project spacesettlers by amymcgovern.
the class AggressiveHeuristicAsteroidCollectorTeamClient method pickNearestBeacon.
/**
* Find the nearest beacon to this ship
* @param space
* @param ship
* @return
*/
private Beacon pickNearestBeacon(Toroidal2DPhysics space, Ship ship) {
// get the current beacons
Set<Beacon> beacons = space.getBeacons();
Beacon closestBeacon = null;
double bestDistance = Double.POSITIVE_INFINITY;
for (Beacon beacon : beacons) {
double dist = space.findShortestDistance(ship.getPosition(), beacon.getPosition());
if (dist < bestDistance) {
bestDistance = dist;
closestBeacon = beacon;
}
}
return closestBeacon;
}
Aggregations