public abstract class AI
extends java.lang.Object
Board
and the
current state of the game. Any concrete instances of this must be
state-less as the may be used by multiple Player
s.
AIController
Modifier and Type | Field and Description |
---|---|
private AIController
|
api
The AIController
that this AI will use to
query the state of the game.
|
private java.util.concurrent.Callable<AIOperation>
|
attack
The
Callable
which invokes the processAttack(AIController) .
|
private java.util.function.Function<AIOperation,java.lang.Boolean>
|
completeAttack
The
Function
that is called when attack
is completed.
|
private java.util.function.Function<AIOperation,java.lang.Boolean>
|
completeFortify
The
Function
that is called when fortify
is completed.
|
private java.util.function.Function<AIOperation,java.lang.Boolean>
|
completeReinforce
The
Function
that is called when reinforce
is completed.
|
private
java.util.concurrent.ExecutorService |
executor
The
Executor
that performs the AI operations.
|
private java.util.concurrent.Callable<AIOperation>
|
fortify
The
Callable
which invokes the processFortify(AIController) .
|
private java.util.concurrent.Future<AIOperation>
|
future
The result of the AI operation on
another thread. |
static int |
MAX_SPEED
The minimum number of milliseconds between each action of
this AI .
|
java.lang.String |
name
The name of this AI .
|
private java.util.concurrent.Callable<AIOperation>
|
reinforce
The
Callable
which invokes the processReinforce(AIController) .
|
private int |
speed
The number of milliseconds between each action of this AI .
|
static AI
|
USER
The AI for a user
controlled player.
|
private int |
wait
The number of milliseconds that this AI
will wait before performing another operation.
|
Modifier | Constructor and Description |
---|---|
private |
AI()
Constructs the USER .
|
|
AI(java.lang.String name,
int defaultSpeed, AIController api)
Constructs a new AI .
|
Modifier and Type | Method and Description |
---|---|
boolean |
attack(int delta)
Performs the attack operations of this AI .
|
boolean |
fortify(int delta)
Performs the fortify operations of this AI .
|
int |
getSpeed()
Retrieves the speed of this AI .
|
private boolean |
performOperation(java.util.concurrent.Callable<AIOperation> operation,
java.util.function.Function<AIOperation,java.lang.Boolean> onComplete)
Performs the specified
Callable
operation and stored the result in future .
|
protected abstract AIOperation
|
processAttack(AIController api)
Perform the attack operation using the specified AIController .
|
protected abstract AIOperation
|
processFortify(AIController api)
Perform the fortify operation using the specified AIController .
|
protected abstract AIOperation
|
processReinforce(AIController api)
Perform the reinforce operation using the specified AIController .
|
boolean |
reinforce(int delta)
Performs the reinforce operations of this AI .
|
void |
setSpeed(int speed)
Set the number of milliseconds between each action of this AI .
|
public static final AI USER
public static final int MAX_SPEED
AI
.
public final java.lang.String name
AI
.
private final AIController api
AIController
that this AI
will use to
query the state of the game.
private final java.util.concurrent.Callable<AIOperation> reinforce
Callable
which invokes the processReinforce(AIController)
.
private final java.util.function.Function<AIOperation,java.lang.Boolean> completeReinforce
Function
that is called when reinforce
is completed.
private final java.util.concurrent.Callable<AIOperation> attack
Callable
which invokes the processAttack(AIController)
.
private final java.util.function.Function<AIOperation,java.lang.Boolean> completeAttack
Function
that is called when attack
is completed.
private final java.util.concurrent.Callable<AIOperation> fortify
Callable
which invokes the processFortify(AIController)
.
private final java.util.function.Function<AIOperation,java.lang.Boolean> completeFortify
Function
that is called when fortify
is completed.
private final java.util.concurrent.ExecutorService executor
Executor
that performs the AI
operations.
private int wait
AI
will wait before performing another operation.
private int speed
private java.util.concurrent.Future<AIOperation> future
public AI(java.lang.String name, int defaultSpeed, AIController api)
AI
.
name
- The name of this AI
.
defaultSpeed
- The number of milliseconds between each action of this AI
.
If this is zero or lower then the then the AI
will perform its actions at the frame rate of the display.
api
- The AIController
that this AI
will use to
query the state of the game.
private AI()
USER
.
public final boolean reinforce(int delta)
AI
.
delta
- The time (in milliseconds) that has elapsed since the last
time this method was called.
AI
wishes to
perform another operation or not.
public final boolean attack(int delta)
AI
.
delta
- The time (in milliseconds) that has elapsed since the last
time this method was called.
AI
wishes to
perform another operation or not.
public final boolean fortify(int delta)
AI
.
delta
- The time (in milliseconds) that has elapsed since the last
time this method was called.
AI
wishes to
perform another operation or not.
public final void setSpeed(int speed)
AI
.
speed
- The new speed of the AI
.
protected abstract AIOperation processReinforce(AIController api)
AIController
.
This operation should be specific to the specialised instance
of the AI
.Country
ONCE.
AIController
.
Country
must be owned by the current Player
which can be retrieved using AIController.getCurrentPlayer()
.
Country
by adding one Country
to AIOperation.select
that is returned.
AIOperation.processAgain
,
which is whether or not this AI
wishes to perform another operation or not. If not the AIController
api
- AIController
AIOperation
for
this AI
's reinforce.
protected abstract AIOperation processAttack(AIController api)
AIController
.
This operation should be specific to the specialised instance
of the AI
.Country
ONCE.
AIController
.
Country
should have more than a one unit army.
Country
that is selected must be owned by the current Player
.
Country
should be a neighbour of the primary Country
and owned by another Player
.
Country
by adding it first to AIOperation.select
that is returned.
Country
by adding it second to AIOperation.select
that is returned.
AIOperation.processAgain
,
which is whether or not this AI
wishes to perform another operation or not. If not the AIController
Country
s
are selected matters. The primary Country
MUST
be selected first. api
- AIController
AIOperation
for
this AI
's attack.
protected abstract AIOperation processFortify(AIController api)
AIController
.
This operation should be specific to the specialised instance
of the AI
.Country
ONCE.
AIController
.
Country
must have more than a one unit army.
Country
s
must be owned by the same Player
.
Country
must have a valid path between is and the primary Country
.
Use AIController.isPathBetween(Country,
Country)
to check this.
Country
by adding it first to AIOperation.select
that is returned.
Country
by adding it second to AIOperation.select
that is returned.
AIOperation.processAgain
,
which is whether or not this AI
wishes to perform another operation or not. If not the AIController
Country
s
are selected matters. The primary Country
MUST
be selected first. api
- AIController
AIOperation
for
this AI
's fortify.
private boolean performOperation(java.util.concurrent.Callable<AIOperation> operation, java.util.function.Function<AIOperation,java.lang.Boolean> onComplete)
Callable
operation and stored the result in future
.
When future
Future.isDone()
this method will perform the specified
Function
.
operation
- The
Callable
that contains the AIs calculations.
onComplete
- The
Function
that will be performed when the operation is completed.
AI
wishes to
perform another operation or not.