Search in sources :

Example 16 with Beacon

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

the class AggressiveHeuristicAsteroidCollectorTeamClient 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);
        goingForCore.put(ship.getId(), 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);
        goingForCore.put(ship.getId(), 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);
        goingForCore.put(ship.getId(), 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);
        aimingForBase.put(ship.getId(), false);
        goingForCore.put(ship.getId(), true);
        return newAction;
    }
    // otherwise aim for the asteroid
    if (current == null || current.isMovementFinished(space)) {
        aimingForBase.put(ship.getId(), false);
        goingForCore.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, asteroid.getPosition().getTranslationalVelocity());
        }
        return newAction;
    } else {
        return ship.getCurrentAction();
    }
}
Also used : Asteroid(spacesettlers.objects.Asteroid) Position(spacesettlers.utilities.Position) AiCore(spacesettlers.objects.AiCore) Beacon(spacesettlers.objects.Beacon) AbstractAction(spacesettlers.actions.AbstractAction) DoNothingAction(spacesettlers.actions.DoNothingAction) Base(spacesettlers.objects.Base) MoveToObjectAction(spacesettlers.actions.MoveToObjectAction)

Example 17 with Beacon

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

the class AggressiveHeuristicAsteroidCollectorTeamClient method getWeaponShipAction.

/**
 * Gets the action for the weapons based ship
 * @param space
 * @param ship
 * @return
 */
private AbstractAction getWeaponShipAction(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);
        goingForCore.put(ship.getId(), 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);
        goingForCore.put(ship.getId(), 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;
        goingForCore.put(ship.getId(), false);
        aimingForBase.put(ship.getId(), 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);
        goingForCore.put(ship.getId(), true);
        aimingForBase.put(ship.getId(), false);
        return newAction;
    }
    // otherwise aim for the nearest enemy ship
    if (current == null || current.isMovementFinished(space)) {
        aimingForBase.put(ship.getId(), false);
        goingForCore.put(ship.getId(), false);
        Ship enemy = pickNearestEnemyShip(space, ship);
        AbstractAction newAction = null;
        if (enemy == null) {
            // there is no enemy 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 {
            newAction = new MoveToObjectAction(space, currentPosition, enemy, enemy.getPosition().getTranslationalVelocity());
        }
        return newAction;
    } else {
        return ship.getCurrentAction();
    }
}
Also used : 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 18 with Beacon

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

the class Toroidal2DPhysics method respawnDeadObjects.

/**
 * Respawns any dead objects in new random locations.  Ships
 * have a delay before they can respawn.
 */
public void respawnDeadObjects(Random random, double asteroidMaxVelocity) {
    for (AbstractObject object : allObjects) {
        if (!object.isAlive() && object.canRespawn()) {
            Position newPosition = null;
            // flags should re-spawn at a randomly chosen starting location
            if (object instanceof Flag) {
                Flag flag = (Flag) object;
                newPosition = flag.getNewStartingPosition(random);
                // ensure their starting location is free (to handle the thought bug the class
                // introduced of putting a ship or a base where the flag should spawn)
                newPosition = getRandomFreeLocationInRegion(random, flag.getRadius() * 2, (int) newPosition.getX(), (int) newPosition.getY(), 75);
            } else {
                // note this is time 2 in order to ensure objects don't spawn touching (and just to get
                // them a bit farther apart
                newPosition = getRandomFreeLocation(random, object.getRadius() * 2);
            }
            object.setPosition(newPosition);
            object.setAlive(true);
            object.setDrawable(true);
            // reset the UUID if it is a asteroid or beacon
            if (object instanceof Asteroid || object instanceof Beacon) {
                object.resetId();
            }
            // make moveable asteroids move again when they respawn
            if (object.isMoveable() && !(object instanceof Flag)) {
                Vector2D randomMotion = Vector2D.getRandom(random, asteroidMaxVelocity);
                object.getPosition().setTranslationalVelocity(randomMotion);
            }
        }
    }
}
Also used : Asteroid(spacesettlers.objects.Asteroid) Vector2D(spacesettlers.utilities.Vector2D) Position(spacesettlers.utilities.Position) AbstractObject(spacesettlers.objects.AbstractObject) Beacon(spacesettlers.objects.Beacon) Flag(spacesettlers.objects.Flag)

Example 19 with Beacon

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

the class ObjectInfoPanel method updateData.

/**
 * Update the GUI for this step using the simulator data as needed
 * @param simulator
 */
public void updateData(SpaceSettlersSimulator simulator) {
    // do not update if there is no selected object
    if (this.selectedObject == null) {
        return;
    }
    String name = "";
    if (selectedObject.getClass() == Asteroid.class) {
        Asteroid asteroid = (Asteroid) selectedObject;
        if (asteroid.isMineable()) {
            name = "Mineable asteroid";
        } else {
            name = "Non-mineable asteroid";
        }
    } else if (selectedObject.getClass() == Base.class) {
        Base base = (Base) selectedObject;
        name = "Base for " + base.getTeamName();
    } else if (selectedObject.getClass() == Ship.class) {
        Ship ship = (Ship) selectedObject;
        name = "Ship for " + ship.getTeamName();
    } else if (selectedObject.getClass() == Beacon.class) {
        Beacon beacon = (Beacon) selectedObject;
        name = "Beacon";
    }
    objectName.setText(name);
    innerPanel.updateData(simulator);
    resourcesPanel.updateData(selectedObject);
}
Also used : Asteroid(spacesettlers.objects.Asteroid) Beacon(spacesettlers.objects.Beacon) Ship(spacesettlers.objects.Ship) Base(spacesettlers.objects.Base)

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