private void HandleDiscreteAction(Done_PlayerController player, float[] act) { if (HasTarget(GameState.ObjectCategory.Asteroid) && act[0] == 5f) { // Fire at asteroid player.FireMissile(); } else if (HasTarget(GameState.ObjectCategory.Alien) && act[0] == 6f) { // Fire at alien player.FireMissile(); } else if (HasTarget(GameState.ObjectCategory.Missile) && act[0] == 7f) { // Fire at alien missile player.FireMissile(); } }
private void HandleContinuousAction(Done_PlayerController player, float[] act) { if (act[0] == 3) { // Fire if (HasTarget(GameState.ObjectCategory.Asteroid) && act[1] == 1f) { // Fire at asteroid player.FireMissile(); } else if (HasTarget(GameState.ObjectCategory.Alien) && act[1] == 2f) { // Fire at alien player.FireMissile(); } else if (HasTarget(GameState.ObjectCategory.Missile) && act[1] == 3f) { // Fire at alien missile player.FireMissile(); } } }
private void HandleContinuousAction(Done_PlayerController player, float[] act) { float factor; // Discourage lack of movement. reward -= 0.001f; if (act[0] == 1) { // Encourage movement. //// But we want to encourage it to the center. //// So we calculate a factor that is 1 in the center and 0 on the bounds. //float zHalf = (boundaryCollider.bounds.max.z - boundaryCollider.bounds.min.z) * 0.5f; //factor = 1 - Mathf.Abs((zHalf - player.transform.position.z + boundaryCollider.bounds.min.z) / zHalf); factor = 1.0f; reward += factor * 0.002f; // Forward and Backward float z = Mathf.Lerp(player.transform.position.z, player.transform.position.z + act[1], player.speed * Time.deltaTime); if (boundaryCollider != null && z < boundaryCollider.bounds.center.z - boundaryCollider.bounds.extents.z) { z = boundaryCollider.bounds.center.z - boundaryCollider.bounds.extents.z; } if (boundaryCollider != null && z > boundaryCollider.bounds.center.z + boundaryCollider.bounds.extents.z) { z = boundaryCollider.bounds.center.z + boundaryCollider.bounds.extents.z; } Vector3 newPosition = new Vector3(player.transform.position.x, player.transform.position.y, z); player.transform.position = newPosition; } else if (act[0] == 2) { // Encourage movement. //// But we want to encourage it to the center. //// So we calculate a factor that is 1 in the center and 0 on the bounds. //float xHalf = (boundaryCollider.bounds.max.x - boundaryCollider.bounds.min.x) * 0.5f; //factor = 1 - Mathf.Abs((xHalf - player.transform.position.x + boundaryCollider.bounds.min.x) / xHalf); factor = 1.0f; reward += factor * 0.002f; // Left and Right float x = Mathf.Lerp(player.transform.position.x, player.transform.position.x + act[1], player.speed * Time.deltaTime); if (boundaryCollider != null && x < boundaryCollider.bounds.center.x - boundaryCollider.bounds.extents.x) { x = boundaryCollider.bounds.center.x - boundaryCollider.bounds.extents.x; } if (boundaryCollider != null && x > boundaryCollider.bounds.center.x + boundaryCollider.bounds.extents.x) { x = boundaryCollider.bounds.center.x + boundaryCollider.bounds.extents.x; } Vector3 newPosition = new Vector3(x, player.transform.position.y, player.transform.position.z); player.transform.position = newPosition; } else if (act[0] == 3) { // Fire if (HasTarget(GameState.ObjectCategory.Asteroid) && act[1] == 1f) { // Fire at asteroid reward += 0.005f; player.FireMissile(); } else if (HasTarget(GameState.ObjectCategory.Alien) && act[1] == 2f) { // Fire at alien reward += 0.006f; player.FireMissile(); } else if (HasTarget(GameState.ObjectCategory.Missile) && act[1] == 3f) { // Fire at alien missile // These are more dangerous and should be avoided, but we still want to fire at them. reward += 0.007f; player.FireMissile(); } else { // Discourage firing at nothing reward -= 0.0005f; } } }
private void HandleDiscreteAction(Done_PlayerController player, float[] act) { float factor = 1.0f; float movementLocal = movement; if (act[0] == 1f || act[0] == 2f) { // Assume forward movement if (act[0] == 2f) { // Adjust for backward movement. movementLocal *= -1f; } // Encourage movement. // But we want to encourage it to the center. // So we calculate a factor that is 1 in the center and 0 on the bounds. float zHalf = (boundaryCollider.bounds.max.z - boundaryCollider.bounds.min.z) * 0.5f; factor = 1 - Mathf.Abs((zHalf - player.transform.position.z + boundaryCollider.bounds.min.z) / zHalf); reward += 0.8f * factor * 0.02f; // Forward and Backward float z = Mathf.Lerp(player.transform.position.z, player.transform.position.z + movementLocal, player.speed * Time.deltaTime); if (boundaryCollider != null && z < boundaryCollider.bounds.center.z - boundaryCollider.bounds.extents.z) { z = boundaryCollider.bounds.center.z - boundaryCollider.bounds.extents.z; } if (boundaryCollider != null && z > boundaryCollider.bounds.center.z + boundaryCollider.bounds.extents.z) { z = boundaryCollider.bounds.center.z + boundaryCollider.bounds.extents.z; } Vector3 newPosition = new Vector3(player.transform.position.x, player.transform.position.y, z); player.transform.position = newPosition; } else if (act[0] == 3f || act[0] == 4f) { // Assume right movement if (act[0] == 4f) { // Adjust for left movement. movementLocal *= -1f; } // Encourage movement. // But we want to encourage it to the center. // So we calculate a factor that is 1 in the center and 0 on the bounds. float xHalf = (boundaryCollider.bounds.max.x - boundaryCollider.bounds.min.x) * 0.5f; factor = 1 - Mathf.Abs((xHalf - player.transform.position.x + boundaryCollider.bounds.min.x) / xHalf); reward += factor * 0.02f; // Left and Right float x = Mathf.Lerp(player.transform.position.x, player.transform.position.x + movementLocal, player.speed * Time.deltaTime); if (boundaryCollider != null && x < boundaryCollider.bounds.center.x - boundaryCollider.bounds.extents.x) { x = boundaryCollider.bounds.center.x - boundaryCollider.bounds.extents.x; } if (boundaryCollider != null && x > boundaryCollider.bounds.center.x + boundaryCollider.bounds.extents.x) { x = boundaryCollider.bounds.center.x + boundaryCollider.bounds.extents.x; } Vector3 newPosition = new Vector3(x, player.transform.position.y, player.transform.position.z); player.transform.position = newPosition; } else if (act[0] == 5f) { if (HasTarget(GameState.ObjectCategory.Asteroid)) { // Fire at asteroid reward += 0.05f; player.FireMissile(); } } else if (act[0] == 6f) { if (HasTarget(GameState.ObjectCategory.Alien)) { // Fire at alien reward += 0.06f; player.FireMissile(); } } else if (act[0] == 7f) { if (HasTarget(GameState.ObjectCategory.Missile)) { // Fire at alien missile // These are more dangerous and should be avoided, but we still want to fire at them. reward += 0.07f; player.FireMissile(); } } }