use of spacesettlers.objects.Asteroid in project spacesettlers by amymcgovern.
the class AggressiveFlagCollectorTeamClient 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) {
asteroidToShipMap.put(asteroid.getId(), ship);
newAction = new MoveToObjectAction(space, currentPosition, asteroid, asteroid.getPosition().getTranslationalVelocity());
}
return newAction;
}
return ship.getCurrentAction();
}
use of spacesettlers.objects.Asteroid in project spacesettlers by amymcgovern.
the class AggressiveFlagCollectorTeamClient method pickHighestValueNearestFreeAsteroid.
/**
* Returns the asteroid of highest value that isn't already being chased by this team
*
* @return
*/
private Asteroid pickHighestValueNearestFreeAsteroid(Toroidal2DPhysics space, Ship ship) {
Set<Asteroid> asteroids = space.getAsteroids();
int bestMoney = Integer.MIN_VALUE;
Asteroid bestAsteroid = null;
double minDistance = Double.MAX_VALUE;
for (Asteroid asteroid : asteroids) {
if (!asteroidToShipMap.containsKey(asteroid.getId())) {
if (asteroid.isMineable() && asteroid.getResources().getTotal() > bestMoney) {
double dist = space.findShortestDistance(asteroid.getPosition(), ship.getPosition());
if (dist < minDistance) {
bestMoney = asteroid.getResources().getTotal();
bestAsteroid = asteroid;
minDistance = dist;
}
}
}
}
// System.out.println("Best asteroid has " + bestMoney);
return bestAsteroid;
}
use of spacesettlers.objects.Asteroid in project spacesettlers by amymcgovern.
the class AggressiveHeuristicAsteroidCollectorSingletonTeamClient method getAggressiveAsteroidCollectorAction.
/**
* Gets the action for the asteroid collecting ship (while being aggressive towards the other ships)
* @param space
* @param ship
* @return
*/
private AbstractAction getAggressiveAsteroidCollectorAction(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);
shouldShoot = false;
return newAction;
}
// if the ship has enough resourcesAvailable, take it back to base
if (ship.getResources().getTotal() > 500 || ship.getNumCores() > 0) {
Base base = findNearestBase(space, ship);
AbstractAction newAction = new MoveToObjectAction(space, currentPosition, base);
aimingForBase.put(ship.getId(), true);
shouldShoot = false;
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);
shouldShoot = false;
}
// if there is a nearby core, go get it
AiCore nearbyCore = pickNearestCore(space, ship, 100);
if (nearbyCore != null) {
Position newGoal = nearbyCore.getPosition();
AbstractAction newAction = new MoveToObjectAction(space, currentPosition, nearbyCore);
return newAction;
}
// otherwise either for an asteroid or an enemy ship (depending on who is closer and what we need)
if (current == null || current.isMovementFinished(space)) {
aimingForBase.put(ship.getId(), false);
// see if there is an enemy ship nearby
Ship enemy = pickNearestEnemyShip(space, ship);
// find the highest valued nearby asteroid
Asteroid asteroid = pickHighestValueNearestFreeAsteroid(space, ship);
AbstractAction newAction = null;
// if there is no enemy nearby, go for an asteroid
if (enemy == null) {
if (asteroid != null) {
newAction = new MoveToObjectAction(space, currentPosition, asteroid, asteroid.getPosition().getTranslationalVelocity());
shouldShoot = false;
return newAction;
} else {
// no enemy and no asteroid, just skip this turn (shouldn't happen often)
shouldShoot = true;
newAction = new DoNothingAction();
return newAction;
}
}
// now decide which one to aim for
if (asteroid != null) {
double enemyDistance = space.findShortestDistance(ship.getPosition(), enemy.getPosition());
double asteroidDistance = space.findShortestDistance(ship.getPosition(), asteroid.getPosition());
// we are aggressive, so aim for enemies if they are nearby
if (enemyDistance < asteroidDistance) {
shouldShoot = true;
newAction = new MoveToObjectAction(space, currentPosition, enemy, enemy.getPosition().getTranslationalVelocity());
} else {
shouldShoot = false;
newAction = new MoveToObjectAction(space, currentPosition, asteroid, asteroid.getPosition().getTranslationalVelocity());
}
return newAction;
} else {
newAction = new MoveToObjectAction(space, currentPosition, enemy, enemy.getPosition().getTranslationalVelocity());
}
return newAction;
}
// return the current if new goals haven't formed
return ship.getCurrentAction();
}
use of spacesettlers.objects.Asteroid in project spacesettlers by amymcgovern.
the class AggressiveHeuristicAsteroidCollectorSingletonTeamClient method pickHighestValueNearestFreeAsteroid.
/**
* Returns the asteroid of highest value that isn't already being chased by this team
*
* @return
*/
private Asteroid pickHighestValueNearestFreeAsteroid(Toroidal2DPhysics space, Ship ship) {
Set<Asteroid> asteroids = space.getAsteroids();
int bestMoney = Integer.MIN_VALUE;
Asteroid bestAsteroid = null;
double minDistance = Double.MAX_VALUE;
for (Asteroid asteroid : asteroids) {
if (!asteroidToShipMap.containsKey(asteroid.getId())) {
if (asteroid.isMineable() && asteroid.getResources().getTotal() > bestMoney) {
double dist = space.findShortestDistance(asteroid.getPosition(), ship.getPosition());
if (dist < minDistance) {
bestMoney = asteroid.getResources().getTotal();
// System.out.println("Considering asteroid " + asteroid.getId() + " as a best one");
bestAsteroid = asteroid;
minDistance = dist;
}
}
}
}
// System.out.println("Best asteroid has " + bestMoney);
return bestAsteroid;
}
use of spacesettlers.objects.Asteroid in project spacesettlers by amymcgovern.
the class AggressiveHeuristicAsteroidCollectorTeamClient method pickHighestValueNearestFreeAsteroid.
/**
* Returns the asteroid of highest value that isn't already being chased by this team
*
* @return
*/
private Asteroid pickHighestValueNearestFreeAsteroid(Toroidal2DPhysics space, Ship ship) {
Set<Asteroid> asteroids = space.getAsteroids();
int bestMoney = Integer.MIN_VALUE;
Asteroid bestAsteroid = null;
double minDistance = Double.MAX_VALUE;
for (Asteroid asteroid : asteroids) {
if (!asteroidToShipMap.containsKey(asteroid.getId())) {
if (asteroid.isMineable() && asteroid.getResources().getTotal() > bestMoney) {
double dist = space.findShortestDistance(asteroid.getPosition(), ship.getPosition());
if (dist < minDistance) {
bestMoney = asteroid.getResources().getTotal();
// System.out.println("Considering asteroid " + asteroid.getId() + " as a best one");
bestAsteroid = asteroid;
minDistance = dist;
}
}
}
}
// System.out.println("Best asteroid has " + bestMoney);
return bestAsteroid;
}
Aggregations