Astraeus Player's Guide

Analyzing Ships

WRITING HELPER METHODS

Making Tools For Yourself


Using Your Superclass


MyTeamUnit - GET NEAREST ENEMY GATHERER

Finding Enemy Gatherers


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



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

MyTeamPlayer - AVERAGE ENEMY MAX SPEED

Finding Average Speed


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.