Commit 76360d1f authored by Rugeon's avatar Rugeon
Browse files

Rounded out two basic bots, one easy and one more challenging+ rapid fire

parent ce8f9ea5
......@@ -22,6 +22,10 @@ namespace Complete
return TrackBehaviour();
case 3:
return FunBehaviour();
case 4:
return DeadlyBehaviour();
//case 5:
// return SpookedBehaviour();
default:
return new Root(new Action(() => Turn(0.1f)));
......@@ -36,7 +40,22 @@ namespace Complete
}
private Node RandomFire() {
return new Action(() => Fire(UnityEngine.Random.Range(0.0f, 0.5f)));
return new Action(() => Fire(UnityEngine.Random.Range(0.0f, 1.0f)));
}
private Node ShortFire()
{
return new Action(() => Fire(UnityEngine.Random.Range(0.0f, 0.3f)));
}
private Node MedFire()
{
return new Action(() => Fire(UnityEngine.Random.Range(0.3f, 0.7f)));
}
private Node LongFire()
{
return new Action(() => Fire(UnityEngine.Random.Range(0.7f, 1.0f)));
}
private Node StopMoving()
......@@ -88,15 +107,33 @@ namespace Complete
new Sequence(//Sequence allows behaviour to rotate and move at same time
new Selector(
new BlackboardCondition("targetOffCentre",
Operator.IS_SMALLER_OR_EQUAL, 0.1f,
new BlackboardCondition("targetOffCentre",
Operator.IS_SMALLER_OR_EQUAL, 0.2f,
Stops.IMMEDIATE_RESTART,
// Stop turning and fire
// Stop turning and fire before before being exactly on center
new Sequence(StopTurning(),
new Wait(0.8f),
RandomFire())
),
new Wait(0.3f),
new Selector(//Fire a shot of differing strengths depending on target distance
new BlackboardCondition("targetDistance",
Operator.IS_SMALLER_OR_EQUAL, 15.0f,
Stops.IMMEDIATE_RESTART,
// Stop turning and fire a short range shot
ShortFire()),
new BlackboardCondition("targetDistance",
Operator.IS_SMALLER_OR_EQUAL, 20.0f,
Stops.IMMEDIATE_RESTART,
// Stop turning and fire a medium range shot
MedFire()),
new BlackboardCondition("targetDistance",
Operator.IS_GREATER, 20.0f,
Stops.IMMEDIATE_RESTART,
// Stop turning and fire a medium range shot
LongFire())
))
),
new BlackboardCondition("targetOnRight",
Operator.IS_EQUAL, true,
......@@ -109,37 +146,118 @@ namespace Complete
new Selector(//Go forwards or backwards at the same time as other actions
new BlackboardCondition("targetInFront",
Operator.IS_EQUAL, true,
Stops.IMMEDIATE_RESTART,
// Go forwards
// Go forwards if the target is in front
new Sequence(
new Wait(0.1f),
new Action(() => Move(0.6f)))
new Action(() => Move(0.8f)))
),
new BlackboardCondition("targetInFront",
Operator.IS_EQUAL, false,
Stops.IMMEDIATE_RESTART,
// Go backwards
// Go backwards if the target is behind
new Sequence(
new Wait(0.1f),
new Action(() => Move(-0.6f)))
new Action(() => Move(-0.8f)))
)
),
new BlackboardCondition("targetDistance",
Operator.IS_SMALLER_OR_EQUAL, 20.0f,
Operator.IS_SMALLER_OR_EQUAL, 25.0f,
Stops.IMMEDIATE_RESTART,
// Stop Moving
//new Sequence(StopTurning(),
//new Wait(0.1f),
// Stops Moving if within a certain distance of the other tank
StopMoving()
)
)
)
);
}
private Root DeadlyBehaviour() //Shooting before exactly on target results in a
{ //'spray and pray' bot that has a higher fire rate
return new Root(
new Service(0.2f, UpdatePerception,
new Sequence(//Sequence allows behaviour to rotate and move at same time
new Selector(
new BlackboardCondition("targetOffCentre",
Operator.IS_SMALLER_OR_EQUAL, 0.2f,
Stops.IMMEDIATE_RESTART,
// Stop turning and fire slightly before directly center
new Sequence(
StopTurning(),
new Selector(//Fire a shot of differing strengths depending on target distance
new BlackboardCondition("targetDistance",
Operator.IS_SMALLER_OR_EQUAL, 15.0f,
Stops.IMMEDIATE_RESTART,
// Stop turning and fire a short range shot
ShortFire()),
new BlackboardCondition("targetDistance",
Operator.IS_SMALLER_OR_EQUAL, 20.0f,
Stops.IMMEDIATE_RESTART,
// Stop turning and fire a medium range shot
MedFire()),
new BlackboardCondition("targetDistance",
Operator.IS_GREATER, 20.0f,
Stops.IMMEDIATE_RESTART,
// Stop turning and fire a medium range shot
LongFire())
),
new BlackboardCondition("targetOffCentre",
Operator.IS_SMALLER_OR_EQUAL, 0.1f,
Stops.IMMEDIATE_RESTART,
// Stop turning when looking directly at tank
StopTurning())
)
),
//new Action(() => Move(0.0f)))
new BlackboardCondition("targetOnRight",
Operator.IS_EQUAL, true,
Stops.IMMEDIATE_RESTART,
// Turn right toward target
new Action(() => Turn(1.0f))),
// Turn left toward target
new Action(() => Turn(-1.0f))
),
new Selector(//Go forwards or backwards at the same time as other actions
new BlackboardCondition("targetInFront",
Operator.IS_EQUAL, true,
Stops.IMMEDIATE_RESTART,
// Go forwards if the target is in front
new Sequence(
new Wait(0.1f),
new Action(() => Move(0.8f)))
),
new BlackboardCondition("targetInFront",
Operator.IS_EQUAL, false,
Stops.IMMEDIATE_RESTART,
// Go backwards if the target is behind
new Sequence(
new Wait(0.1f),
new Action(() => Move(-0.8f)))
)
),
new BlackboardCondition("targetDistance",
Operator.IS_SMALLER_OR_EQUAL, 25.0f,
Stops.IMMEDIATE_RESTART,
// Stops Moving if within a certain distance of the other tank
StopMoving()
)
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment