Implementing the code

Now we need to implement the code that will describe the agent's behavior and the ML-Agent's Academy. The agent's behavior script describes the way the agents performs actions in the simulation, the reward it receives, and the way we reset it to start a new simulation:

  1. Click on the Academy and add to it a new script called SphereAcademy with the following code:
using MLAgents;public class SphereAcademy : Academy { }

This will create a default training academy for our agent.

  1. Select the Brain object and add the Brain script to it.
  2. Select the Sphere. Let's add to it a new script, called SphereAgent, with the following contents:
 using System.Collections.Generic; using UnityEngine; using MLAgents; public class SphereAgent ...

Get Unity Artificial Intelligence Programming - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.