课程学习:学院在第一课中更新两次

时间:2019-07-14 14:06:42

标签: c# unity3d

我正在通过课程学习来训练大脑,并且我发现该学院在第一堂课中两次更新了重置参数,请参见图片。 链接到图像here

我通过检查重置参数是否已更改来调用学院的重置,因为我不会避免使用最大步数。

public override void InitializeAcademy()
  {
    environments = GameObject.FindGameObjectsWithTag("Ground");
    extendX = (environments[0].transform.localScale.x) / 2;// The first element in the environments array are used, because all environments are identical, and it therefore doesn't matter.
    extendZ = (environments[0].transform.localScale.z) / 2;

    previousMovingSensors = (int)resetParameters["NumberOfMovingSensors"];
    previousSensors = (int)resetParameters["NumberOfSensors"];
    previousClouds = (int)resetParameters["NumberOfSensorClouds"];
    previousRadius = (float)resetParameters["Radius"];

    // Disabling all obstacle at initialisation
    GameObject[] obstacles = GameObject.FindGameObjectsWithTag("Obstacle");
    for (var i = 0; i < obstacles.Length;i++)
    {
      obstacles[i].GetComponent<MeshRenderer>().enabled = false;
      obstacles[i].GetComponent<BoxCollider>().enabled = false;
    }

    // Defining the incrementer to be used for setting sensors.
    incrementer = obstacles.Length / environments.Length;
  }

  public override void AcademyReset()
  {
    lB = 0;
    uB = incrementer;

    foreach (GameObject environment in environments)
    {
      addMovingSensors(extendX,extendZ,environment.transform.position,environment.transform);
      addSensorClouds(extendX,extendZ,environment.transform.position,environment.transform);
      enableWalls(lB,uB);
      lB += incrementer;
      uB += incrementer;
    }

    // Status report
    // Debug.Log("Number of:");
    // Debug.Log("- moving sensors: " + GameObject.FindGameObjectsWithTag("Pedestrian").Length);
    // Debug.Log("- sensors in the clouds: " + GameObject.FindGameObjectsWithTag("Sensor").Length);
    // Debug.Log("- obstacles: " + processedObstacles.Count);
  }

  public void Update()
  {
    // Check if there has been any updates in the resetParameters.

    if ((previousMovingSensors != (int)resetParameters["NumberOfMovingSensors"]) ||
     (previousSensors != (int)resetParameters["NumberOfSensors"]) ||
      (previousClouds != (int)resetParameters["NumberOfSensorClouds"]) ||
       (previousRadius != (float)resetParameters["Radius"]))
    {
      Debug.Log("Test");
      // If changes has occured, reset the environment with the new resetParameters.
      // string[] objectsOfInterest = {"Sensor","Pedestrian"};
      //
      // foreach (string objectOfInterst in objectsOfInterest)
      // {
      //   GameObject[] objectsToDestroy = GameObject.FindGameObjectsWithTag(objectOfInterst);
      //   foreach(GameObject removeObject in objectsToDestroy)
      //   {
      //     Destroy(removeObject);
      //   }
      // }

      Done();

      previousMovingSensors = (int)resetParameters["NumberOfMovingSensors"];
      previousSensors = (int)resetParameters["NumberOfSensors"];
      previousClouds = (int)resetParameters["NumberOfSensorClouds"];
      previousRadius = (float)resetParameters["Radius"];
    }
  }

有人知道为什么在第一堂课时学院要更新两次吗?

1 个答案:

答案 0 :(得分:0)

答案是不实施更新方法。 我认为有必要指定最大步数,或者调用“ Done()”来重置环境,但是事实并非如此。选择的度量标准达到指定值后立即进行重置。如果您需要在选择的指标达到指定值之前重置环境,则仅设置“ max step”或调用“ Done()”。 其中也提到了文档here