use of spacesettlers.actions.MoveToObjectAction 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;
}
use of spacesettlers.actions.MoveToObjectAction in project spacesettlers by amymcgovern.
the class PacifistFlagCollectorTeamClient 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) {
asteroidToShipMap.put(asteroid.getId(), ship);
newAction = new MoveToObjectAction(space, currentPosition, asteroid, asteroid.getPosition().getTranslationalVelocity());
}
return newAction;
}
return ship.getCurrentAction();
}
use of spacesettlers.actions.MoveToObjectAction 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;
}
use of spacesettlers.actions.MoveToObjectAction 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();
}
use of spacesettlers.actions.MoveToObjectAction 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();
}
}
Aggregations