Search in sources :

Example 11 with Beacon

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();
}
Also used : Asteroid(spacesettlers.objects.Asteroid) Position(spacesettlers.utilities.Position) Beacon(spacesettlers.objects.Beacon) AbstractAction(spacesettlers.actions.AbstractAction) DoNothingAction(spacesettlers.actions.DoNothingAction) Base(spacesettlers.objects.Base) MoveToObjectAction(spacesettlers.actions.MoveToObjectAction)

Example 12 with Beacon

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;
}
Also used : Beacon(spacesettlers.objects.Beacon)

Example 13 with Beacon

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;
}
Also used : Beacon(spacesettlers.objects.Beacon)

Example 14 with Beacon

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;
}
Also used : Beacon(spacesettlers.objects.Beacon)

Example 15 with Beacon

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;
}
Also used : Beacon(spacesettlers.objects.Beacon)

Aggregations

Beacon (spacesettlers.objects.Beacon)19 Base (spacesettlers.objects.Base)10 Position (spacesettlers.utilities.Position)10 Asteroid (spacesettlers.objects.Asteroid)9 AbstractAction (spacesettlers.actions.AbstractAction)8 DoNothingAction (spacesettlers.actions.DoNothingAction)8 MoveToObjectAction (spacesettlers.actions.MoveToObjectAction)8 Ship (spacesettlers.objects.Ship)7 AiCore (spacesettlers.objects.AiCore)3 AbstractObject (spacesettlers.objects.AbstractObject)2 Flag (spacesettlers.objects.Flag)2 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 Team (spacesettlers.clients.Team)1 TeamClient (spacesettlers.clients.TeamClient)1 ResourcePile (spacesettlers.objects.resources.ResourcePile)1 Vector2D (spacesettlers.utilities.Vector2D)1