use of spacesettlers.objects.AbstractObject in project spacesettlers by amymcgovern.
the class AggressiveFlagCollectorTeamClient 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;
int numShips = 0;
// 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);
}
// count ships so we know if we can have a weapons ship
for (AbstractObject actionable : actionableObjects) {
if (actionable instanceof Ship) {
numShips++;
}
}
// resources (as long as it isn't the flagShip)
for (AbstractObject actionable : actionableObjects) {
if (actionable instanceof Ship) {
Ship ship = (Ship) actionable;
AbstractAction action = null;
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 {
// a ship to go get resources and help buy more ships/bases)
if (numShips >= 2) {
// see if we already have a hunting ship
if (huntingShip.isEmpty()) {
huntingShip.put(ship.getId(), true);
System.out.println("Creating a hunting ship");
// make one ship the hunter
action = getWeaponShipAction(space, ship);
} else {
// if this ship is the current hunter, have it keep hunting
if (huntingShip.containsKey(ship.getId())) {
// make one ship the hunter
action = getWeaponShipAction(space, ship);
// System.out.println("Getting action for hunter");
} else {
// extra ship but not the hunter (likely a 4th ship)
action = getAsteroidCollectorAction(space, ship);
}
}
} else {
// with 2 ships, we need to always collect resources so we can buy more ships for hunting
// and resources later
}
}
// 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.objects.AbstractObject in project spacesettlers by amymcgovern.
the class AggressiveFlagCollectorTeamClient 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;
}
use of spacesettlers.objects.AbstractObject in project spacesettlers by amymcgovern.
the class AggressiveHeuristicAsteroidCollectorSingletonTeamClient 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>();
// loop through each ship
for (AbstractObject actionable : actionableObjects) {
if (actionable instanceof Ship) {
Ship ship = (Ship) actionable;
// the first time we initialize, decide which ship is the asteroid collector
if (asteroidCollectorID == null) {
asteroidCollectorID = ship.getId();
}
AbstractAction action = getAggressiveAsteroidCollectorAction(space, ship);
actions.put(ship.getId(), action);
} else {
// it is a base. Heuristically decide when to use the shield (TODO)
actions.put(actionable.getId(), new DoNothingAction());
}
}
return actions;
}
use of spacesettlers.objects.AbstractObject in project spacesettlers by amymcgovern.
the class BeaconCollectorTeamClient 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();
// does the ship have a beacon it is aiming for?
if (current == null || current.isMovementFinished(space) || !shipToBeaconMap.containsKey(ship)) {
Position currentPosition = ship.getPosition();
Beacon beacon = pickNearestFreeBeacon(space, ship);
AbstractAction newAction = null;
if (beacon == null) {
// there is no beacon available so do nothing
newAction = new DoNothingAction();
} else {
beaconToShipMap.put(beacon, ship);
shipToBeaconMap.put(ship, beacon);
Position newGoal = beacon.getPosition();
newAction = new MoveToObjectAction(space, currentPosition, beacon);
}
actions.put(ship.getId(), newAction);
} else {
actions.put(ship.getId(), ship.getCurrentAction());
}
} else {
// it is a base and Beacon collector doesn't do anything to bases
actions.put(actionable.getId(), new DoNothingAction());
}
}
return actions;
}
use of spacesettlers.objects.AbstractObject 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;
}
Aggregations