Search in sources :

Example 6 with AbstractObject

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

the class PacifistFlagCollectorTeamClient method findHealthiestShipNearFlag.

/**
 * Finds the ship with the highest health and nearest the flag
 *
 * @param space
 * @param actionableObjects
 * @return
 */
private Ship findHealthiestShipNearFlag(Toroidal2DPhysics space, Set<AbstractActionableObject> actionableObjects) {
    double minDistance = Double.MAX_VALUE;
    double maxHealth = Double.MIN_VALUE;
    int minHealth = 2000;
    Ship bestShip = null;
    // first find the enemy flag
    Flag enemyFlag = getEnemyFlag(space);
    // if no ships meet that criteria, return null
    for (AbstractObject actionable : actionableObjects) {
        if (actionable instanceof Ship) {
            Ship ship = (Ship) actionable;
            double dist = space.findShortestDistance(ship.getPosition(), enemyFlag.getPosition());
            if (dist < minDistance && ship.getEnergy() > minHealth) {
                if (ship.getEnergy() > maxHealth) {
                    minDistance = dist;
                    maxHealth = ship.getEnergy();
                    bestShip = ship;
                }
            }
        }
    }
    return bestShip;
}
Also used : AbstractObject(spacesettlers.objects.AbstractObject) Ship(spacesettlers.objects.Ship) Flag(spacesettlers.objects.Flag)

Example 7 with AbstractObject

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

the class PacifistFlagCollectorTeamClient method getMovementStart.

/**
 * Assigns ships to asteroids and beacons, as described above
 */
public Map<UUID, AbstractAction> getMovementStart(Toroidal2DPhysics space, Set<AbstractActionableObject> actionableObjects) {
    HashMap<UUID, AbstractAction> actions = new HashMap<UUID, AbstractAction>();
    Ship flagShip;
    // get the flag carrier, if we have one
    flagShip = getFlagCarrier(space, actionableObjects);
    // we don't have a ship carrying a flag, so find the best choice (if it exists)
    if (flagShip == null) {
        flagShip = findHealthiestShipNearFlag(space, actionableObjects);
    }
    // resources (as long as it isn't the flagShip)
    for (AbstractObject actionable : actionableObjects) {
        if (actionable instanceof Ship) {
            Ship ship = (Ship) actionable;
            AbstractAction action;
            if (flagShip != null && ship.equals(flagShip)) {
                if (flagShip.isCarryingFlag()) {
                    // System.out.println("We have a flag carrier!");
                    Base base = findNearestBase(space, ship);
                    // System.out.println("Flag ship before computing action: " + flagShip);
                    action = new MoveToObjectAction(space, ship.getPosition(), base);
                    // System.out.println("Aiming for base with action " + action);
                    aimingForBase.put(ship.getId(), true);
                // System.out.println("Flag ship after computing action: " + flagShip);
                } else {
                    Flag enemyFlag = getEnemyFlag(space);
                    action = new MoveToObjectAction(space, ship.getPosition(), enemyFlag, enemyFlag.getPosition().getTranslationalVelocity());
                }
            } else {
                action = getAsteroidCollectorAction(space, ship);
            }
            // save the action for this ship
            actions.put(ship.getId(), action);
        } else {
            // bases do nothing
            actions.put(actionable.getId(), new DoNothingAction());
        }
    }
    return actions;
}
Also used : HashMap(java.util.HashMap) AbstractObject(spacesettlers.objects.AbstractObject) Ship(spacesettlers.objects.Ship) UUID(java.util.UUID) AbstractAction(spacesettlers.actions.AbstractAction) Flag(spacesettlers.objects.Flag) DoNothingAction(spacesettlers.actions.DoNothingAction) Base(spacesettlers.objects.Base) MoveToObjectAction(spacesettlers.actions.MoveToObjectAction)

Example 8 with AbstractObject

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

the class RandomTeamClient method getMovementStart.

@Override
public Map<UUID, AbstractAction> getMovementStart(Toroidal2DPhysics space, Set<AbstractActionableObject> actionableObjects) {
    HashMap<UUID, AbstractAction> randomActions = new HashMap<UUID, AbstractAction>();
    for (AbstractObject actionable : actionableObjects) {
        if (actionable instanceof Ship) {
            Ship ship = (Ship) actionable;
            AbstractAction current = ship.getCurrentAction();
            // if we finished, make a new spot in space to aim for
            if (current == null || current.isMovementFinished(space)) {
                Position currentPosition = ship.getPosition();
                Position newGoal = space.getRandomFreeLocationInRegion(random, Ship.SHIP_RADIUS, (int) currentPosition.getX(), (int) currentPosition.getY(), RANDOM_MOVE_RADIUS);
                MoveAction newAction = null;
                newAction = new MoveAction(space, currentPosition, newGoal);
                // System.out.println("Ship is at " + currentPosition + " and goal is " + newGoal);
                SpacewarGraphics graphic = new CircleGraphics(1, getTeamColor(), newGoal);
                graphics.add(graphic);
                // Vector2D shortVec = space.findShortestDistanceVector(currentPosition, newGoal);
                // LineShadow lineShadow = new LineShadow(currentPosition, newGoal, shortVec);
                // newShadows.add(lineShadow);
                randomActions.put(ship.getId(), newAction);
            } else {
                randomActions.put(ship.getId(), ship.getCurrentAction());
            }
        } else {
            // it is a base and random doesn't do anything to bases
            randomActions.put(actionable.getId(), new DoNothingAction());
        }
    }
    return randomActions;
}
Also used : MoveAction(spacesettlers.actions.MoveAction) SpacewarGraphics(spacesettlers.graphics.SpacewarGraphics) HashMap(java.util.HashMap) Position(spacesettlers.utilities.Position) AbstractObject(spacesettlers.objects.AbstractObject) CircleGraphics(spacesettlers.graphics.CircleGraphics) Ship(spacesettlers.objects.Ship) UUID(java.util.UUID) AbstractAction(spacesettlers.actions.AbstractAction) DoNothingAction(spacesettlers.actions.DoNothingAction)

Example 9 with AbstractObject

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

the class ExampleGAClient method getMovementStart.

@Override
public Map<UUID, AbstractAction> getMovementStart(Toroidal2DPhysics space, Set<AbstractActionableObject> actionableObjects) {
    // make a hash map of actions to return
    HashMap<UUID, AbstractAction> actions = new HashMap<UUID, AbstractAction>();
    // this agent choses only between doNothing and moveToNearestAsteroid)
    for (AbstractObject actionable : actionableObjects) {
        if (actionable instanceof Ship) {
            Ship ship = (Ship) actionable;
            AbstractAction action;
            if (ship.getCurrentAction() == null || ship.getCurrentAction().isMovementFinished(space)) {
                ExampleGAState currentState = new ExampleGAState(space, ship);
                action = currentPolicy.getCurrentAction(space, ship, currentState, random);
            // System.out.println("New random action is " + action);
            } else {
                action = ship.getCurrentAction();
            }
            actions.put(ship.getId(), action);
        } else {
            // it is a base.  Heuristically decide when to use the shield (TODO)
            actions.put(actionable.getId(), new DoNothingAction());
        }
    }
    // System.out.println("actions are " + actions);
    return actions;
}
Also used : HashMap(java.util.HashMap) AbstractObject(spacesettlers.objects.AbstractObject) Ship(spacesettlers.objects.Ship) UUID(java.util.UUID) AbstractAction(spacesettlers.actions.AbstractAction) DoNothingAction(spacesettlers.actions.DoNothingAction)

Example 10 with AbstractObject

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

the class Toroidal2DPhysics method deepClone.

/**
 * Clones all the objects in space (used for security so the teams can't manipulate other ships)
 * +
 * @return
 */
public Toroidal2DPhysics deepClone() {
    Toroidal2DPhysics newSpace = new Toroidal2DPhysics(this);
    for (AbstractObject swObject : allObjects) {
        AbstractObject newObject = swObject.deepClone();
        newSpace.addObject(newObject);
    }
    return newSpace;
}
Also used : AbstractObject(spacesettlers.objects.AbstractObject)

Aggregations

AbstractObject (spacesettlers.objects.AbstractObject)20 Ship (spacesettlers.objects.Ship)15 UUID (java.util.UUID)12 AbstractAction (spacesettlers.actions.AbstractAction)12 DoNothingAction (spacesettlers.actions.DoNothingAction)12 HashMap (java.util.HashMap)11 Position (spacesettlers.utilities.Position)6 Flag (spacesettlers.objects.Flag)5 MoveToObjectAction (spacesettlers.actions.MoveToObjectAction)4 Base (spacesettlers.objects.Base)4 Vector2D (spacesettlers.utilities.Vector2D)3 LinkedHashSet (java.util.LinkedHashSet)2 MoveAction (spacesettlers.actions.MoveAction)2 Team (spacesettlers.clients.Team)2 SpacewarGraphics (spacesettlers.graphics.SpacewarGraphics)2 AbstractActionableObject (spacesettlers.objects.AbstractActionableObject)2 AiCore (spacesettlers.objects.AiCore)2 Asteroid (spacesettlers.objects.Asteroid)2 Beacon (spacesettlers.objects.Beacon)2 Graphics2D (java.awt.Graphics2D)1