Exemplo n.º 1
0
    private void Update()
    {
        if (is_activated)
        {
            if (actions[action_index][0] == -1)
            {
                car_controller.Accelerate(0);
                car_controller.Brake();
            }
            else
            {
                car_controller.Accelerate(actions[action_index][0]);
            }
            car_controller.Steer(actions[action_index][1]);
        }

        string full_log = "";

        full_log += "Last Reward Recived: " + current_reward + "\n";
        full_log += "Epsilon: " + epsilon + "\n";
        full_log += "Actions Q Value: \n";
        for (int i = 0; i < actions.Length; i++)
        {
            full_log += "       " + actions_name[i] + ": " + last_q_values[i] + "\n";
        }
        //Log
        for (int i = 0; i < log.Count; i++)
        {
            full_log += ">>" + log[i] + "\n";
        }
        text_log.text = full_log;
    }
    private void Update()
    {
        //Gas
        if (Input.GetKey(KeyCode.UpArrow))
        {
            controller.Accelerate(1.0f);
        }
        else if (Input.GetKey(KeyCode.DownArrow))
        {
            controller.Brake();
        }
        else
        {
            controller.Accelerate(0.0f);
        }

        //Steer
        float steer = 0.0f;

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            steer = -1.0f;
        }
        else if (Input.GetKey(KeyCode.RightArrow))
        {
            steer = 1.0f;
        }
        controller.Steer(steer);
    }
    private void Update()
    {
        if (!abort_learning)
        {
            if (actions[action_index][0] == -1)
            {
                car_controller.Accelerate(0);
                car_controller.Brake();
            }
            else
            {
                car_controller.Accelerate(actions[action_index][0]);
            }
            car_controller.Steer(actions[action_index][1]);

            if (text_log != null)
            {
                string full_log = "";
                full_log += "Working Particle: " + working_particle + "\n";
                full_log += "Current Reward: " + current_reward + "\n";
                full_log += "Best Score: " + particle_swarm.GetBestScore() + "\n";
                full_log += "Actions Q Value: \n";
                for (int i = 0; i < actions.Length; i++)
                {
                    full_log += "       " + actions_name[i] + ": " + last_q_values[i] + "\n";
                }
                text_log.text = full_log;
            }
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// Executes code based on the actions received from the NN
    /// </summary>
    /// <param name="vectorAction">Actions to take</param>
    public override void OnActionReceived(float[] vectorAction)
    {
        // Floor to int for error control
        float forwardAmount = Mathf.FloorToInt(vectorAction[0]);
        float steerAmount   = Mathf.FloorToInt(vectorAction[1]);

        if (!GameManager.instance.raceStarted || isFinished)
        {
            forwardAmount = 0f; steerAmount = 0f; return;
        }

        if (forwardAmount == 0f)
        {
            carController.Accelerate(0f);
        }
        else if (forwardAmount == 1f)
        {
            carController.Accelerate(1f);
        }
        else if (forwardAmount == 2f)
        {
            carController.Accelerate(-1f);
        }

        if (steerAmount == 0f)
        {
            carController.Steer(0f);
        }
        else if (steerAmount == 1f)
        {
            carController.Steer(1f);
        }
        else if (steerAmount == 2f)
        {
            carController.Steer(-1f);
        }

        // Add reward for actions
        AddReward(CalculateRewardFromRPM());

        if (isTraining)
        {
            if (StepCount > nextStepTimeout)
            {
                AddReward(-.5f);
                EndEpisode();
            }
        }
    }
Exemplo n.º 5
0
 private void Drive()
 {
     if (!isBraking)
     {
         controller.throttleInput = 1;
         controller.Accelerate(controller.backLeftW, controller.backRightW);
     }
 }
 private void Update()
 {
     controller.Accelerate(1.0f);
     body.gameObject.transform.localPosition = new Vector3(
         0,
         body.gameObject.transform.localPosition.y,
         body.gameObject.transform.localPosition.z
         );
     body.gameObject.transform.localRotation = Quaternion.Euler(
         body.gameObject.transform.localRotation.eulerAngles.x,
         0,
         body.gameObject.transform.localRotation.eulerAngles.z
         );
 }
Exemplo n.º 7
0
    private void Update()
    {
        if (activate_car)
        {
            float[] network_inputs  = car_camera.GetRays();
            float[] network_outputs = network.Compute(network_inputs);

            int   action_index = ChoseAction(network_outputs);
            float accel        = actions[action_index][0];
            float steer        = actions[action_index][1];

            controller.Accelerate(accel);
            if (accel == -1)
            {
                controller.Brake();
            }

            controller.Steer(steer);
        }
    }