Astraeus Player's Guide

Analyzing Ships

WRITING HELPER METHODS

Making Tools For Yourself


  • Your team will want to engage in all sorts of complex behavior. For example...

    • Changing a unit's design based on the weapons or defenses your enemy fleet uses

    • Seeking out a specific type of unit to attack

    • Focusing your attacks on the lowest health enemy nearby

Using Your Superclass


  • In general you'll want to put these helper methods in either the MyTeamPlayer or MyTeamUnit class

    • If it's something that deals with unit production or overall strategy ---> Player class

    • If it's something that deals with position or a single unit --> Unit class

MyTeamUnit - GET NEAREST ENEMY GATHERER

Finding Enemy Gatherers


  • You can't just ask if a Unit is a Gatherer - your enemies might have totally different classes than you have! Instead, we'll need to infer what a unit is based on their attributes.

  • In addition, we want to find the nearest gatherer. This means we'll need to loop through the list of enemy units and do some comparisons.

public Unit getNearestEnemyGatherer()

{

// Initialize variables

ArrayList<Unit> enemies = getEnemies();

Unit nearestGatherer = null;

float nearestDistance = Float.MAX_VALUE;


// Loop through all your enemies

for(Unit e : enemies)

{

// Check if it is a worker *and* compare your distance to the record

if(e.hasWeapon(Collector.class) && getDistance(e) <= nearestDistance)

{

nearestGatherer = e;

nearestDistance = getDistance(e);

}

}

return nearestGatherer;

}

Similar Methods

  • You'll often want to write methods that must find the lowest, highest, nearest, or farthest Unit meeting some criteria. They'll follow a similar pattern to this one!



Finding the nearest enemy gatherer to raid them is a start to a raiding strategy, but you'll likely need to consider things like...

  • How protected the gatherer is

  • How close it is to the base ship

  • How I can safely get to that position

  • When I need to run away from danger

MyTeamPlayer - AVERAGE ENEMY MAX SPEED

Finding Average Speed


  • By finding the enemy maximum speed we can make guesses about their strategy, or at least the enemy's dodge chance. This could affect things like how we position units or encourage us to equip high accuracy weapons.

public int getAverageEnemyMaxSpeed()

{

// Initialize variables

ArrayList<Unit> enemies = getEnemies();

float totalSpeed = 0;

float numEnemies = enemies.size();


// Loop through all your enemies

for(Unit e : enemies)

{
// If the unit is a base ship, skip this step.

if(e instanceof BaseShip)

{

continue;

}

// This converts the unit's speed to the 0-100ish scale

float curSpeed = e.getMaxSpeed() / Values.SPEED;


// Add it to the total speed

totalSpeed += curSpeed;

}


int averageSpeed = (int) (totalSpeed / numEnemies);


return averageSpeed;

}

Accessing Player Methods From Unit Class


Since this method is defined in MyTeamPlayer, you can call it in Player easily. Don't forget that you can call from your Unit classes! Simply reference the player


public void design()

{

if(getPlayer().getAverageEnemyMaxSpeed() > 50)
{

// do stuff

}

}



Fast units might use strategies like running past your fleet to attack gatherers or your base.

Slow units tend to be stronger and might require heavier weapons to be defeated.