// Update at regular time intervals - useful for physics void FixedUpdate() { bool failedX = agentX.applyForce(Time.deltaTime); bool failedZ = agentZ.applyForce(Time.deltaTime); int failures = agentX.getState().failures + agentZ.getState().failures; trialTxt.text = "Trial " + failures; timeTxt.text = "Time: " + Time.timeSinceLevelLoad.ToString("n3") + "s"; stepsTxt.text = "Steps: " + agentX.getState().steps; maxTimeTxt.text = "Max time: " + maxTime.ToString("n3") + "s"; if (Time.timeSinceLevelLoad > maxTime) { maxTime = Time.timeSinceLevelLoad; } if (failedX || failedZ) { agentX.setMaxTime(maxTime); agentZ.setMaxTime(maxTime); String text = "Trial: " + failures + "\tSteps: " + agentX.getState().steps + "\tTime: " + Time.timeSinceLevelLoad.ToString("n3") + "s" + "\tAngle: (" + agentX.getState().angle + ", " + agentZ.getState().angle + ")" + "\t Angle velocity: (" + agentX.getState().angle_speed + ", " + agentZ.getState().angle_speed + ")" + "\tCart pos: " + cart.position; Debug.Log(text); LogToFile("PoleCart3D.log", text); if (failedX) { agentX.saveState("trainingX.data"); } else { agentZ.saveState("trainingZ.data"); } SceneManager.LoadScene(0); } }
// Update at regular time intervals - useful for physics void FixedUpdate() { bool failed = agent.applyForce(Time.deltaTime); trialTxt.text = "Trial " + agent.getState().failures.ToString(); timeTxt.text = "Time: " + Time.timeSinceLevelLoad.ToString("n3") + "s"; stepsTxt.text = "Steps: " + agent.getState().steps; maxTimeTxt.text = "Max time: " + maxTime.ToString("n3") + "s"; if (Time.timeSinceLevelLoad > maxTime) { maxTime = Time.timeSinceLevelLoad; } if (failed) { float height = weight.position.y - cart.position.y; float x = weight.position.x - cart.position.x; float z = weight.position.z - cart.position.z; float angX = Mathf.Atan2(x, height) * Mathf.Rad2Deg; agent.setMaxTime(maxTime); String text = "Trial: " + agent.getState().failures + "\tSteps: " + agent.getState().steps + "\tTime: " + Time.timeSinceLevelLoad + "\tAngle: " + angX + "\t Angle velocity: " + agent.getState().angle_speed + "\tCart pos: " + cart.position; Debug.Log(text); LogToFile("PoleCart3D.log", text); agent.getState(); agent.saveState("training.data"); SceneManager.LoadScene(0); } }