Search in sources :

Example 16 with Asteroid

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

the class ResourcesPanel method updateData.

public void updateData(AbstractObject object) {
    ResourcePile avail = null;
    ResourcePile total = null;
    if (object.getClass() == Asteroid.class) {
        Asteroid asteroid = (Asteroid) object;
        avail = asteroid.getResources();
        total = avail;
    } else if (object.getClass() == Ship.class) {
        Ship ship = (Ship) object;
        avail = ship.getResources();
        total = avail;
    } else if (object.getClass() == Base.class) {
        Base base = (Base) object;
        avail = base.getResources();
        total = base.getResources();
    } else if (object.getClass() == Beacon.class) {
        Beacon beacon = (Beacon) object;
    }
    if (avail != null) {
        waterAvail.setText("" + avail.getResourceQuantity(ResourceTypes.WATER));
        fuelAvail.setText("" + avail.getResourceQuantity(ResourceTypes.FUEL));
        metalsAvail.setText("" + avail.getResourceQuantity(ResourceTypes.METALS));
        waterTotal.setText("" + total.getResourceQuantity(ResourceTypes.WATER));
        fuelTotal.setText("" + total.getResourceQuantity(ResourceTypes.FUEL));
        metalsTotal.setText("" + total.getResourceQuantity(ResourceTypes.METALS));
    } else {
        waterAvail.setText("0");
        fuelAvail.setText("0");
        metalsAvail.setText("0");
        waterTotal.setText("0");
        fuelTotal.setText("0");
        metalsTotal.setText("0");
    }
}
Also used : ResourcePile(spacesettlers.objects.resources.ResourcePile) Asteroid(spacesettlers.objects.Asteroid) Beacon(spacesettlers.objects.Beacon) Ship(spacesettlers.objects.Ship) Base(spacesettlers.objects.Base)

Example 17 with Asteroid

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

the class PacifistFlagCollectorTeamClient 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;
}
Also used : Asteroid(spacesettlers.objects.Asteroid)

Example 18 with Asteroid

use of spacesettlers.objects.Asteroid 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 19 with Asteroid

use of spacesettlers.objects.Asteroid 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 20 with Asteroid

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

the class ExampleGAState method updateState.

/**
 * Update the distance to the nearest mineable asteroid
 *
 * @param space
 * @param myShip
 */
public void updateState(Toroidal2DPhysics space, Ship myShip) {
    Set<Asteroid> asteroids = space.getAsteroids();
    distanceToNearestMineableAsteroid = Integer.MAX_VALUE;
    double distance;
    for (Asteroid asteroid : asteroids) {
        if (asteroid.isMineable()) {
            distance = space.findShortestDistance(myShip.getPosition(), asteroid.getPosition());
            if (distance < distanceToNearestMineableAsteroid) {
                distanceToNearestMineableAsteroid = distance;
                nearestMineableAsteroid = asteroid;
            }
        }
    }
}
Also used : Asteroid(spacesettlers.objects.Asteroid)

Aggregations

Asteroid (spacesettlers.objects.Asteroid)25 Position (spacesettlers.utilities.Position)14 Beacon (spacesettlers.objects.Beacon)9 Ship (spacesettlers.objects.Ship)9 Base (spacesettlers.objects.Base)8 Vector2D (spacesettlers.utilities.Vector2D)8 Test (org.junit.Test)6 AbstractAction (spacesettlers.actions.AbstractAction)6 DoNothingAction (spacesettlers.actions.DoNothingAction)6 MoveToObjectAction (spacesettlers.actions.MoveToObjectAction)5 Team (spacesettlers.clients.Team)2 AbstractObject (spacesettlers.objects.AbstractObject)2 AiCore (spacesettlers.objects.AiCore)2 Flag (spacesettlers.objects.Flag)2 ResourcePile (spacesettlers.objects.resources.ResourcePile)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1