Scout movement algorithm

My coding of the AI to Rising Empires lies ahead of my posts here at the ‘Words from the Netherlords’. Yesterday I managed to get the first version of the settlement AI to function and I’m very satisfied with the result. The settlement AI consider its food situation and react by improving terrain, request better food technology of the strategic AI and in crisis it also build food buildings to quickly increase the food output. It also follows the directives of the Governor and construct new buildings (I’m very satisfied with the algorithm that decides what building that the settlement is to build).

Anyway, today I though I would continue with the scout AI and the algorithm that decides how the scouts will move. Often, when solving these kind of problems, I start by planning with pen and paper. It can look like this:

The blue square in the middle is the settlement. It can see four squares in each direction. A is scout armies and they can see three squares in each direction. The shaded area is sectors that borders unknown territory and the arrows show the alternatives each scout army has when deciding how to move. We also have a check that makes sure that two scouts don’t try to move to sectors that lies close to each other.

When the scout AI issue an order it actually issue a task. The task will specify a target sector for the army, but it’s up to the army to find the best route to the target sector. The Task class looks like this:

public static final int TASK_MOVE = 0;					// Armies + Fleets
public static final int TASK_MOVE_CHANGE_LEVEL = 1;			// Armies
public static final int TASK_CHANGE_LEVEL = 2;				// Armies

private Army army;
private Fleet fleet;
private SettlementAI settlementAI;

private int allowedCost;			// What is this order allowed to cost
private int task;
private Sector targetSector;
private int targetLevel;

// Constructor.
public Task(int task, Army army, Fleet fleet, SettlementAI settlementAI) {
	this.task = task; = army;
	this.fleet = fleet;
	this.settlementAI = settlementAI;
// End constructor

The Task class is used to store all instructions by the different AIs, like what troops that are to be built, which terrain sector that are to be improved and much more.