Added respawn for AI, Game manager keeps track of laps
This commit is contained in:
@@ -33,6 +33,8 @@ public class AgentController: Agent
|
||||
public int distanceBetweenCheckpoints = 5;
|
||||
public bool ignoreMentalPain = true;
|
||||
bool isEnabled = true;
|
||||
public bool isPlaying = false;
|
||||
[HideInInspector] public bool isFinished = false; // needed for gamemanager
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
@@ -56,9 +58,13 @@ public class AgentController: Agent
|
||||
return;
|
||||
|
||||
stepsSinceCheckpoint = 0;
|
||||
checkpointsCollected = 0;
|
||||
totalReward = 0;
|
||||
totalMentalPain = 0;
|
||||
checkpointsCollected = 0;
|
||||
|
||||
// don't reset car unless in training
|
||||
if (isPlaying)
|
||||
return;
|
||||
|
||||
// reset wheels
|
||||
foreach (var wheel in wheels)
|
||||
@@ -92,6 +98,12 @@ public class AgentController: Agent
|
||||
|
||||
public override void CollectObservations(VectorSensor sensor)
|
||||
{
|
||||
if (!isEnabled)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
sensor.AddObservation(0);
|
||||
return;
|
||||
}
|
||||
|
||||
Transform currentCheckpoint = checkpoints[checkpointsCollected].transform;
|
||||
|
||||
@@ -249,7 +261,16 @@ public class AgentController: Agent
|
||||
if (checkpointsCollected == checkpoints.Count - 1)
|
||||
{
|
||||
AddReward(10f);
|
||||
EndEpisode();
|
||||
|
||||
if (isPlaying)
|
||||
{
|
||||
isFinished = true;
|
||||
}
|
||||
|
||||
EndEpisode();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
checkpointsCollected += 1;
|
||||
@@ -268,7 +289,34 @@ public class AgentController: Agent
|
||||
if (stepsSinceCheckpoint >= maxStepsPerCheckpoint)
|
||||
{
|
||||
stepsSinceCheckpoint = 0;
|
||||
EndEpisode();
|
||||
|
||||
if (isPlaying) // send back to previous checkpoint if stuck
|
||||
{
|
||||
|
||||
if (checkpointsCollected == 0)
|
||||
{
|
||||
transform.position = startPosition;
|
||||
transform.rotation = startRotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.position = new Vector3(
|
||||
checkpoints[checkpointsCollected - 1].transform.position.x,
|
||||
transform.position.y + 3,
|
||||
checkpoints[checkpointsCollected - 1].transform.position.z
|
||||
);
|
||||
|
||||
transform.eulerAngles = new Vector3(
|
||||
transform.eulerAngles.x,
|
||||
checkpoints[checkpointsCollected - 1].transform.eulerAngles.y,
|
||||
transform.eulerAngles.z
|
||||
);
|
||||
}
|
||||
|
||||
rb.velocity = Vector3.zero;
|
||||
}
|
||||
else
|
||||
EndEpisode();
|
||||
}
|
||||
|
||||
// print(GetCumulativeReward());
|
||||
|
||||
Reference in New Issue
Block a user