浏览代码

about to merge in master

/develop/dodgeball-tests
HH 4 年前
当前提交
9d17392a
共有 15 个文件被更改,包括 1052 次插入1038 次删除
  1. 18
      Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/AgentCubeMovement.cs
  2. 22
      Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallAgent.cs
  3. 1
      Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallGameController.cs
  4. 3
      Project/Assets/ML-Agents/Examples/Dodgeball/Input/FPSAgentInput.cs
  5. 2
      Project/Packages/manifest.json
  6. 2
      Project/Packages/packages-lock.json
  7. 24
      config/ppo/DodgeBall.yaml
  8. 8
      Project/Assets/ML-Agents/Examples/Dodgeball/Settings.meta
  9. 1001
      Project/Assets/ML-Agents/Examples/Dodgeball/Scenes/Dodgeball.unity
  10. 8
      Project/Assets/ML-Agents/Examples/Dodgeball/Scenes/FPS_Game_Profiles.meta
  11. 1001
      Project/Assets/ML-Agents/Examples/Dodgeball/Scenes/FPS_Game.unity
  12. 0
      /Project/Assets/ML-Agents/Examples/Dodgeball.meta
  13. 0
      /Project/Assets/ML-Agents/Examples/Dodgeball
  14. 0
      /Project/Assets/ML-Agents/Examples/Dodgeball/Scenes/Dodgeball.unity.meta
  15. 0
      /Project/Assets/ML-Agents/Examples/Dodgeball/Settings

18
Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/AgentCubeMovement.cs


public class AgentCubeMovement : MonoBehaviour
{
[Header("INPUT")] public bool allowKeyboardInput = true;
//ONLY ALLOW SCRIPTED MOVEMENT VIA ML-AGENTS OR OTHER HEURISTIC SCRIPTS
[Header("INPUT")] public bool allowHumanInput = true;
[Header("RIGIDBODY")] public float maxAngularVel = 50;
[Header("RUNNING")] public ForceMode runningForceMode = ForceMode.Impulse;
//speed agent can run if grounded

// // targetRot.y = 0;
// transform.rotation = Quaternion.Euler(targetRot);
// }
if (!allowKeyboardInput)
if (!allowHumanInput)
{
return;
}

public float standingForcePositionOffset = .5f;
void FixedUpdate()
{
if (!allowHumanInput)
{
return;
}
if (UseMouseRotation)
{
if (axes == RotationAxes.MouseXAndY)

standingForceForceMode);
}
if (!allowKeyboardInput)
{
return;
}
// if (!allowHumanInput)
// {
// return;
// }

22
Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallAgent.cs


[HideInInspector]
public BehaviorParameters m_BehaviorParameters;
// [Header("DUMB AI HEURISTIC")] public bool DoNotPerformActions;
//PLAYER STATE TO OBSERVE
// Start is called before the first frame update

{
if (UseVectorObs)
{
sensor.AddObservation(StepCount / (float)MaxStep); //Help with credit assign?
sensor.AddObservation(currentNumberOfBalls/4); //Held DBs Normalized
sensor.AddObservation(HitPointsRemaining/NumberOfTimesPlayerCanBeHit); //Remaining Hit Points Normalized
// sensor.AddObservation((float)StepCount / (float)MaxStep); //Helps with credit assign?
sensor.AddObservation((float)currentNumberOfBalls/4); //Held DBs Normalized
sensor.AddObservation((float)HitPointsRemaining/(float)NumberOfTimesPlayerCanBeHit); //Remaining Hit Points Normalized
// // var localVelocity = transform.InverseTransformDirection(m_AgentRb.velocity);
// // sensor.AddObservation(localVelocity.x);
// // sensor.AddObservation(localVelocity.z);

public void MoveAgent(ActionSegment<float> act)
{
// if (DoNotPerformActions)
// {
// return;
// }
// if (!m_Frozen)
// {
// var shootCommand = false;

//HANDLE THROWING
if (m_ThrowInput > 0)
// if (input.shootPressed)
{
ThrowTheBall();
}

public float m_InputH;
private float m_InputV;
private float m_Rotate;
public bool leftStrafe;
public bool rightStrafe;
// void Update()
// {

if (db.TeamToIgnore != -1 && db.TeamToIgnore != m_BehaviorParameters.TeamId) //HIT BY LIVE BALL
{
m_GameController.PlayerWasHit(this);
PlayHitFX();
// if (HitPointsRemaining == 1)
// {
// //RESET ENV

// contActionsOut[2] = input.rotateInput.x; //rotate
contActionsOut[2] = input.rotateInput.x; //rotate
// contActionsOut[3] = input.shootInput ? 1 : 0; //shoot
contActionsOut[3] = input.CheckIfInputSinceLastFrame(ref input.shootInput) ? 1 : 0; //jump
contActionsOut[4] = input.CheckIfInputSinceLastFrame(ref input.dashInput) ? 1 : 0; //jump
contActionsOut[3] = input.shootPressed ? 1 : 0; //shoot
// contActionsOut[3] = input.CheckIfInputSinceLastFrame(ref input.shootInput) ? 1 : 0; //jump
// contActionsOut[3] = input.CheckIfInputSinceLastFrame(ref input.shootPressed) ? 1 : 0; //throw
contActionsOut[4] = input.CheckIfInputSinceLastFrame(ref input.dashInput) ? 1 : 0; //dash
// contActionsOut[5] = input.CheckIfInputSinceLastFrame(ref input.jumpInput) ? 1 : 0; //jump
// // contActionsOut[4] = input.jumpInput ? 1 : 0; //jump
// // contActionsOut[5] = input.dashInput ? 1 : 0; //dash

1
Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallGameController.cs


agent.AddReward(-.1f); //small hit penalty
HitByTeamList[0].Agent.AddReward(.1f);
}
// ResetScene();
}

3
Project/Assets/ML-Agents/Examples/Dodgeball/Input/FPSAgentInput.cs


}
moveInput = actionMap.Walk.ReadValue<Vector2>();
shootInput = actionMap.Shoot.ReadValue<float>() > 0;
shootPressed = actionMap.Shoot.triggered;
// shootPressed = actionMap.Shoot.triggered;
shootPressed = actionMap.Shoot.phase == InputActionPhase.Started;
// shootInput = gamepad.rightTrigger.isPressed;
shieldInput = actionMap.Shield.ReadValue<float>() > 0;
// rotateInput = actionMap.RotateBody.ReadValue<Vector2>();

2
Project/Packages/manifest.json


"com.unity.analytics": "3.3.5",
"com.unity.cinemachine": "2.7.1",
"com.unity.collab-proxy": "1.2.16",
"com.unity.ide.rider": "3.0.3",
"com.unity.ide.rider": "3.0.4",
"com.unity.ide.vscode": "1.2.3",
"com.unity.inputsystem": "1.0.2",
"com.unity.ml-agents": "file:../../com.unity.ml-agents",

2
Project/Packages/packages-lock.json


"url": "https://packages.unity.com"
},
"com.unity.ide.rider": {
"version": "3.0.3",
"version": "3.0.4",
"depth": 0,
"source": "registry",
"dependencies": {

24
config/ppo/DodgeBall.yaml


hidden_units: 256
num_layers: 2
vis_encode_type: simple
# reward_signals:
# extrinsic:
# gamma: 0.99
# strength: 1.0
extrinsic:
gamma: 0.99
strength: 1.0
curiosity:
gamma: 0.99
strength: 0.02
encoding_size: 256
learning_rate: 0.0003
extrinsic:
gamma: 0.99
strength: 1.0
# reward_signals:
# extrinsic:
# gamma: 0.99
# strength: 1.0
# curiosity:
# gamma: 0.99
# strength: 0.02
# encoding_size: 256
# learning_rate: 0.0003
keep_checkpoints: 5
max_steps: 2000000
time_horizon: 64

8
Project/Assets/ML-Agents/Examples/Dodgeball/Settings.meta


fileFormatVersion: 2
guid: 27ed1c071e9af4a9293a93a51bac5515
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Project/Assets/ML-Agents/Examples/Dodgeball/Scenes/Dodgeball.unity
文件差异内容过多而无法显示
查看文件

8
Project/Assets/ML-Agents/Examples/Dodgeball/Scenes/FPS_Game_Profiles.meta


fileFormatVersion: 2
guid: 94050c67f19fe4e418799f6fa8886801
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Project/Assets/ML-Agents/Examples/Dodgeball/Scenes/FPS_Game.unity
文件差异内容过多而无法显示
查看文件

/Project/Assets/ML-Agents/Examples/FPS_Game.meta → /Project/Assets/ML-Agents/Examples/Dodgeball.meta

/Project/Assets/ML-Agents/Examples/FPS_Game → /Project/Assets/ML-Agents/Examples/Dodgeball

/Project/Assets/ML-Agents/Examples/Dodgeball/Scenes/FPS_Game.unity.meta → /Project/Assets/ML-Agents/Examples/Dodgeball/Scenes/Dodgeball.unity.meta

/Project/Assets/ML-Agents/Examples/Dodgeball/Scenes/FPS_Game_Profiles → /Project/Assets/ML-Agents/Examples/Dodgeball/Settings

正在加载...
取消
保存