Search in sources :

Example 1 with AiCore

use of spacesettlers.objects.AiCore in project spacesettlers by amymcgovern.

the class AggressiveHeuristicAsteroidCollectorSingletonTeamClient method pickNearestCore.

/**
 * Find the nearest core to this ship that falls within the specified minimum distance
 * @param space
 * @param ship
 * @return
 */
private AiCore pickNearestCore(Toroidal2DPhysics space, Ship ship, int minimumDistance) {
    Set<AiCore> cores = space.getCores();
    AiCore closestCore = null;
    double bestDistance = minimumDistance;
    for (AiCore core : cores) {
        double dist = space.findShortestDistance(ship.getPosition(), core.getPosition());
        if (dist < bestDistance) {
            bestDistance = dist;
            closestCore = core;
        }
    }
    return closestCore;
}
Also used : AiCore(spacesettlers.objects.AiCore)

Example 2 with AiCore

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

Example 3 with AiCore

use of spacesettlers.objects.AiCore in project spacesettlers by amymcgovern.

the class AggressiveHeuristicAsteroidCollectorTeamClient method pickNearestCore.

/**
 * Find the nearest core to this ship that falls within the specified minimum distance
 * @param space
 * @param ship
 * @return
 */
private AiCore pickNearestCore(Toroidal2DPhysics space, Ship ship, int minimumDistance) {
    Set<AiCore> cores = space.getCores();
    AiCore closestCore = null;
    double bestDistance = minimumDistance;
    for (AiCore core : cores) {
        double dist = space.findShortestDistance(ship.getPosition(), core.getPosition());
        if (dist < bestDistance) {
            bestDistance = dist;
            closestCore = core;
        }
    }
    return closestCore;
}
Also used : AiCore(spacesettlers.objects.AiCore)

Example 4 with AiCore

use of spacesettlers.objects.AiCore in project spacesettlers by amymcgovern.

the class CoreCollectorTeamClient method getMovementStart.

/**
 * Send each ship to a beacon
 */
public Map<UUID, AbstractAction> getMovementStart(Toroidal2DPhysics space, Set<AbstractActionableObject> actionableObjects) {
    HashMap<UUID, AbstractAction> actions = new HashMap<UUID, AbstractAction>();
    // loop through each ship
    for (AbstractObject actionable : actionableObjects) {
        if (actionable instanceof Ship) {
            Ship ship = (Ship) actionable;
            AbstractAction current = ship.getCurrentAction();
            // if the ship has a core, take it to base
            if (ship.getNumCores() > 0) {
                Base base = findNearestBase(space, ship);
                AbstractAction newAction = new MoveToObjectAction(space, ship.getPosition(), base);
                actions.put(ship.getId(), newAction);
            } else {
                // go find a core (or keep aiming for one if you already are)
                if (current == null || !shipToCoreMap.containsKey(ship)) {
                    Position currentPosition = ship.getPosition();
                    AiCore core = pickNearestFreeCore(space, ship);
                    AbstractAction newAction = null;
                    if (core == null) {
                        // there is no core available so do nothing
                        newAction = new DoNothingAction();
                    } else {
                        coreToShipMap.put(core, ship);
                        shipToCoreMap.put(ship, core);
                        Position newGoal = core.getPosition();
                        newAction = new MoveToObjectAction(space, currentPosition, core);
                    }
                    actions.put(ship.getId(), newAction);
                } else {
                    // update the goal location since cores move
                    UUID myCoreId = shipToCoreMap.get(ship).getId();
                    AiCore myCore = (AiCore) space.getObjectById(myCoreId);
                    Position currentPosition = ship.getPosition();
                    AbstractAction newAction = null;
                    newAction = new MoveToObjectAction(space, currentPosition, myCore);
                    actions.put(ship.getId(), newAction);
                }
            }
        } else {
            // it is a base and core collector doesn't do anything to bases
            actions.put(actionable.getId(), new DoNothingAction());
        }
    }
    return actions;
}
Also used : HashMap(java.util.HashMap) Position(spacesettlers.utilities.Position) AiCore(spacesettlers.objects.AiCore) AbstractObject(spacesettlers.objects.AbstractObject) Ship(spacesettlers.objects.Ship) UUID(java.util.UUID) AbstractAction(spacesettlers.actions.AbstractAction) DoNothingAction(spacesettlers.actions.DoNothingAction) Base(spacesettlers.objects.Base) MoveToObjectAction(spacesettlers.actions.MoveToObjectAction)

Example 5 with AiCore

use of spacesettlers.objects.AiCore in project spacesettlers by amymcgovern.

the class CoreCollectorTeamClient method getMovementEnd.

/**
 * Clean up data structure including core maps
 */
public void getMovementEnd(Toroidal2DPhysics space, Set<AbstractActionableObject> actionableObjects) {
    // new location)
    for (AiCore core : space.getCores()) {
        if (!core.isAlive()) {
            shipToCoreMap.remove(coreToShipMap.get(core));
            coreToShipMap.remove(core);
        }
    }
}
Also used : AiCore(spacesettlers.objects.AiCore)

Aggregations

AiCore (spacesettlers.objects.AiCore)11 Base (spacesettlers.objects.Base)7 Ship (spacesettlers.objects.Ship)6 AbstractAction (spacesettlers.actions.AbstractAction)5 DoNothingAction (spacesettlers.actions.DoNothingAction)5 Position (spacesettlers.utilities.Position)5 MoveToObjectAction (spacesettlers.actions.MoveToObjectAction)4 Beacon (spacesettlers.objects.Beacon)3 UUID (java.util.UUID)2 AbstractObject (spacesettlers.objects.AbstractObject)2 Asteroid (spacesettlers.objects.Asteroid)2 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 AbstractActionableObject (spacesettlers.objects.AbstractActionableObject)1 ResourcePile (spacesettlers.objects.resources.ResourcePile)1 EMP (spacesettlers.objects.weapons.EMP)1 Missile (spacesettlers.objects.weapons.Missile)1 Movement (spacesettlers.utilities.Movement)1