浏览代码

Refactored GridWorld (#225)

Greatly simplified GridWorld code. It now also only uses a visual observation rather than state vector in order to demonstrate learning purely from a visual input.
/develop-generalizationTraining-TrainerController
GitHub 7 年前
当前提交
00534390
共有 12 个文件被更改,包括 796 次插入752 次删除
  1. 2
      docs/Example-Environments.md
  2. 4
      python/ppo/models.py
  3. 1
      python/unityagents/environment.py
  4. 297
      unity-environment/Assets/ML-Agents/Examples/GridWorld/GridWorld.unity
  5. 51
      unity-environment/Assets/ML-Agents/Examples/GridWorld/Resources/agent.prefab
  6. 10
      unity-environment/Assets/ML-Agents/Examples/GridWorld/Resources/goal.prefab
  7. 10
      unity-environment/Assets/ML-Agents/Examples/GridWorld/Resources/pit.prefab
  8. 63
      unity-environment/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAcademy.cs
  9. 95
      unity-environment/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs
  10. 1000
      unity-environment/Assets/ML-Agents/Examples/GridWorld/TFModels/GridWorld.bytes
  11. 7
      unity-environment/Assets/ML-Agents/Examples/GridWorld/TFModels/GridWorld.bytes.meta
  12. 8
      unity-environment/Assets/ML-Agents/Materials/MaterialsGrid/Floor.mat

2
docs/Example-Environments.md


* +1.0 if the agent navigates to the goal position of the grid (episode ends).
* -1.0 if the agent navigates to an obstacle (episode ends).
* Brains: One brain with the following state/action space.
* State space: (Continuous) 6 variables corresponding to position of agent and nearest goal and obstacle.
* State space: None
* Action space: (Discrete) Size of 4, corresponding to movement in cardinal directions.
* Observations: One corresponding to top-down view of GridWorld.
* Reset Parameters: Three, corresponding to grid size, number of obstacles, and number of goals.

4
python/ppo/models.py


self.advantage = tf.placeholder(shape=[None, 1], dtype=tf.float32, name='advantages')
decay_epsilon = tf.train.polynomial_decay(epsilon, self.global_step,
max_step, 1e-2,
max_step, 0.1,
power=1.0)
r_theta = probs / (old_probs + 1e-10)

decay_beta = tf.train.polynomial_decay(beta, self.global_step,
max_step, 1e-5,
power=1.0)
self.loss = self.policy_loss + self.value_loss - decay_beta * tf.reduce_mean(entropy)
self.loss = self.policy_loss + 0.5 * self.value_loss - decay_beta * tf.reduce_mean(entropy)
self.learning_rate = tf.train.polynomial_decay(lr, self.global_step,
max_step, 1e-10,

1
python/unityagents/environment.py


for k in self._resetParameters])) + '\n' + \
'\n'.join([str(self._brains[b]) for b in self._brains])
def _recv_bytes(self):
try:
s = self._conn.recv(self._buffer_size)

297
unity-environment/Assets/ML-Agents/Examples/GridWorld/GridWorld.unity


m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFiltering: 0
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringAtrousColorSigma: 1
m_PVRFilteringAtrousNormalSigma: 1
m_PVRFilteringAtrousPositionSigma: 1
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 0
--- !u!196 &4

manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &2047662
GameObject:

m_EditorClassIdentifier:
maxSteps: 0
frameToSkip: 0
waitTime: 0.3
waitTime: 0
isInference: 0
width: 80
height: 80
qualityLevel: 1
timeScale: 100
targetFrameRate: 60
width: 300
height: 300
qualityLevel: 0
timeScale: 10
targetFrameRate: -1
inferenceConfiguration:
width: 1280
height: 720

defaultResetParameters:
- key: gridSize
value: 5
value: 3
- key: numObstacles
value: 1
- key: numGoals

currentStep: 0
isInference: 0
windowResize: 1
trueAgent: {fileID: 0}
visualAgent: {fileID: 0}
trueAgent: {fileID: 2008405822}
gridSize: 0
camObject: {fileID: 231883441}
--- !u!4 &2047664
Transform:
m_ObjectHideFlags: 0

m_Children:
- {fileID: 1535917238}
m_Father: {fileID: 0}
m_RootOrder: 7
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &87755817
GameObject:

m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!114 &201074924
--- !u!114 &183002472
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}

m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 943466ab374444748a364f9d6c3e2fe2, type: 3}
m_Name: (Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)
m_Script: {fileID: 11500000, guid: 41e9bda8f3cf1492fa74926a530f6f70, type: 3}
m_Name: (Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)
brain: {fileID: 0}
broadcast: 1
continuousPlayerActions: []
discretePlayerActions:
- key: 273
value: 0
- key: 274
value: 1
- key: 276
value: 2
- key: 275
value: 3
defaultAction: -1
brain: {fileID: 1535917239}
--- !u!1 &231883441
GameObject:
m_ObjectHideFlags: 0

m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!124 &231883444
Behaviour:
m_ObjectHideFlags: 0

m_TargetEye: 3
m_HDR: 0
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_StereoMirrorMode: 0
--- !u!4 &231883447
Transform:
m_ObjectHideFlags: 0

m_TargetEye: 3
m_HDR: 0
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_StereoMirrorMode: 0
--- !u!114 &594701073
--- !u!114 &651992469
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}

m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 41e9bda8f3cf1492fa74926a530f6f70, type: 3}
m_Name: (Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)
m_Script: {fileID: 11500000, guid: 35813a1be64e144f887d7d5f15b963fa, type: 3}
m_Name: (Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)
continuousPlayerActions: []
discretePlayerActions:
- key: 273
value: 0
- key: 274
value: 1
- key: 276
value: 2
- key: 275
value: 3
defaultAction: -1
brain: {fileID: 1535917239}
--- !u!1 &742849316
GameObject:

m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Father: {fileID: 486401524}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &980448580
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 35813a1be64e144f887d7d5f15b963fa, type: 3}
m_Name: (Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)
m_EditorClassIdentifier:
brain: {fileID: 1535917239}
--- !u!1 &1045409640
GameObject:
m_ObjectHideFlags: 0

m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Father: {fileID: 486401524}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1104052206
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 943466ab374444748a364f9d6c3e2fe2, type: 3}
m_Name: (Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)
m_EditorClassIdentifier:
broadcast: 1
brain: {fileID: 1535917239}
--- !u!1 &1208586857
GameObject:
m_ObjectHideFlags: 0

m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 0
serializedVersion: 2
serializedVersion: 3
m_InflateMesh: 0
m_CookingOptions: 14
m_SkinWidth: 0.01
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!33 &1208586860

m_Name:
m_EditorClassIdentifier:
brainParameters:
stateSize: 6
stateSize: 0
- width: 32
height: 32
blackAndWhite: 1
- width: 84
height: 84
blackAndWhite: 0
actionDescriptions:
- Up
- Down

stateSpaceType: 1
brainType: 0
CoreBrains:
- {fileID: 594701073}
- {fileID: 201074924}
- {fileID: 980448580}
- {fileID: 1740992925}
instanceID: 12718
- {fileID: 183002472}
- {fileID: 1104052206}
- {fileID: 651992469}
- {fileID: 1737050307}
instanceID: 12658
--- !u!1 &1553342942
GameObject:
m_ObjectHideFlags: 0

m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1553342942}
--- !u!1 &1585576318
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1585576319}
- component: {fileID: 1585576320}
m_Layer: 0
m_Name: trueAgent
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1585576319
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1585576318}
m_LocalRotation: {x: 0.04613505, y: -0, z: -0, w: 0.9989352}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1585576320
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1585576318}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 857707f3f352541d5b858efca4479b95, type: 3}
m_Name:
m_EditorClassIdentifier:
brain: {fileID: 1535917239}
observations:
- {fileID: 489340228}
maxStep: 100
resetOnDone: 1
reward: 0
done: 0
value: 0
CummulativeReward: 0
stepCounter: 0
agentStoredAction: []
memory: []
id: 0
academy: {fileID: 2047663}
gridSize: 0
--- !u!1 &1726089810
GameObject:
m_ObjectHideFlags: 0

m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Father: {fileID: 486401524}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0}
--- !u!114 &1740992925
--- !u!114 &1737050307
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}

m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8b23992c8eb17439887f5e944bf04a40, type: 3}
m_Name: (Clone)
m_Name: (Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)(Clone)
graphModel: {fileID: 4900000, guid: 9c75cb395cc9943838c0694ad4bc2604, type: 3}
broadcast: 0
graphModel: {fileID: 4900000, guid: 426162c47484e466d8378d2321a5617c, type: 3}
graphScope:
graphPlaceholders: []
BatchSizePlaceholderName: batch_size

m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Father: {fileID: 486401524}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0}
--- !u!1001 &2008405821
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4587181662868872, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_RootOrder
value: 7
objectReference: {fileID: 0}
- target: {fileID: 114841131957396212, guid: 628960e910f094ad1909ecc88cc8016d,
type: 2}
propertyPath: brain
value:
objectReference: {fileID: 1535917239}
- target: {fileID: 114841131957396212, guid: 628960e910f094ad1909ecc88cc8016d,
type: 2}
propertyPath: observations.Array.data[0]
value:
objectReference: {fileID: 489340228}
- target: {fileID: 114841131957396212, guid: 628960e910f094ad1909ecc88cc8016d,
type: 2}
propertyPath: academy
value:
objectReference: {fileID: 2047663}
- target: {fileID: 1657514749044530, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
propertyPath: m_Name
value: trueAgent
objectReference: {fileID: 0}
- target: {fileID: 54942316128460260, guid: 628960e910f094ad1909ecc88cc8016d,
type: 2}
propertyPath: m_Constraints
value: 126
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 114841131957396212, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
m_ParentPrefab: {fileID: 100100000, guid: 628960e910f094ad1909ecc88cc8016d, type: 2}
m_IsPrefabParent: 0
--- !u!1 &2008405822 stripped
GameObject:
m_PrefabParentObject: {fileID: 1657514749044530, guid: 628960e910f094ad1909ecc88cc8016d,
type: 2}
m_PrefabInternal: {fileID: 2008405821}
--- !u!114 &2008405823
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2008405822}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 857707f3f352541d5b858efca4479b95, type: 3}
m_Name:
m_EditorClassIdentifier:
brain: {fileID: 1535917239}
observations:
- {fileID: 489340228}
maxStep: 100
resetOnDone: 1
state: []
reward: 0
done: 0
value: 0
CumulativeReward: 0
stepCounter: 0
agentStoredAction: []
memory: []
id: 0
academy: {fileID: 2047663}

51
unity-environment/Assets/ML-Agents/Examples/GridWorld/Resources/agent.prefab


- component: {fileID: 4587181662868872}
- component: {fileID: 33731433020831250}
- component: {fileID: 65005393801495654}
- component: {fileID: 114841131957396212}
- component: {fileID: 54942316128460260}
m_Layer: 8
m_Name: agent
m_TagString: agent

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1124730825420414}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!54 &54942316128460260
Rigidbody:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1657514749044530}
serializedVersion: 2
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 0
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!65 &65005393801495654
BoxCollider:
m_ObjectHideFlags: 1

serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &114841131957396212
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1657514749044530}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 857707f3f352541d5b858efca4479b95, type: 3}
m_Name:
m_EditorClassIdentifier:
brain: {fileID: 0}
observations:
- {fileID: 0}
maxStep: 100
resetOnDone: 1
state: []
reward: 0
done: 0
value: 0
CumulativeReward: 0
stepCounter: 0
agentStoredAction: []
memory: []
id: 0
academy: {fileID: 0}

10
unity-environment/Assets/ML-Agents/Examples/GridWorld/Resources/goal.prefab


m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 0
m_CastShadows: 0
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1508142483324970}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_IsTrigger: 1
m_Size: {x: 1, y: 10, z: 1}
m_Size: {x: 0.9, y: 0.9, z: 0.9}
m_Center: {x: 0, y: 0, z: 0}
--- !u!65 &65991532807116388
BoxCollider:

10
unity-environment/Assets/ML-Agents/Examples/GridWorld/Resources/pit.prefab


m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 0
m_CastShadows: 0
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1811317785436014}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_IsTrigger: 1
m_Size: {x: 1, y: 1, z: 1}
m_Size: {x: 0.9, y: 0.9, z: 0.9}
m_Center: {x: 0, y: 0, z: 0}
--- !u!65 &65439704505015706
BoxCollider:

63
unity-environment/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAcademy.cs


public List<GameObject> actorObjs;
[HideInInspector]
public string[] players;
[HideInInspector]
[HideInInspector]
public GameObject visualAgent;
public int gridSize;
public GameObject camObject;
Camera cam;
gridSize = (int)resetParameters["gridSize"];
cam = camObject.GetComponent<Camera>();
trueAgent = GameObject.Find("trueAgent");
cam.transform.position = new Vector3(-((int)resetParameters["gridSize"] - 1) / 2f, (int)resetParameters["gridSize"] * 1.25f, -((int)resetParameters["gridSize"] - 1) / 2f);
cam.orthographicSize = ((int)resetParameters["gridSize"] + 5f) / 2f;
List<string> playersList = new List<string>();
actorObjs = new List<GameObject>();
for (int i = 0; i < (int)resetParameters["numObstacles"]; i++)

playersList.Add("agent");
for (int i = 0; i < (int)resetParameters["numGoals"]; i++)
{

Camera cam = GameObject.Find("Main Camera").GetComponent<Camera>();
cam.transform.position = new Vector3(-((int)resetParameters["gridSize"] - 1) / 2f, (int)resetParameters["gridSize"] * 1.25f, -((int)resetParameters["gridSize"] - 1) / 2f);
cam.orthographicSize = ((int)resetParameters["gridSize"] + 5f) / 2f;
GameObject.Find("Plane").transform.localScale = new Vector3((int)resetParameters["gridSize"] / 10.0f, 1f, (int)resetParameters["gridSize"] / 10.0f);
GameObject.Find("Plane").transform.position = new Vector3(((int)resetParameters["gridSize"] - 1) / 2f, -0.5f, ((int)resetParameters["gridSize"] - 1) / 2f);
GameObject.Find("sN").transform.localScale = new Vector3(1, 1, (int)resetParameters["gridSize"] + 2);
GameObject.Find("sS").transform.localScale = new Vector3(1, 1, (int)resetParameters["gridSize"] + 2);
GameObject.Find("sN").transform.position = new Vector3(((int)resetParameters["gridSize"] - 1) / 2f, 0.0f, (int)resetParameters["gridSize"]);
GameObject.Find("sS").transform.position = new Vector3(((int)resetParameters["gridSize"] - 1) / 2f, 0.0f, -1);
GameObject.Find("sE").transform.localScale = new Vector3(1, 1, (int)resetParameters["gridSize"] + 2);
GameObject.Find("sW").transform.localScale = new Vector3(1, 1, (int)resetParameters["gridSize"] + 2);
GameObject.Find("sE").transform.position = new Vector3((int)resetParameters["gridSize"], 0.0f, ((int)resetParameters["gridSize"] - 1) / 2f);
GameObject.Find("sW").transform.position = new Vector3(-1, 0.0f, ((int)resetParameters["gridSize"] - 1) / 2f);
GameObject.Find("Plane").transform.localScale = new Vector3(gridSize / 10.0f, 1f, gridSize / 10.0f);
GameObject.Find("Plane").transform.position = new Vector3((gridSize - 1) / 2f, -0.5f, (gridSize - 1) / 2f);
GameObject.Find("sN").transform.localScale = new Vector3(1, 1, gridSize + 2);
GameObject.Find("sS").transform.localScale = new Vector3(1, 1, gridSize + 2);
GameObject.Find("sN").transform.position = new Vector3((gridSize - 1) / 2f, 0.0f, gridSize);
GameObject.Find("sS").transform.position = new Vector3((gridSize - 1) / 2f, 0.0f, -1);
GameObject.Find("sE").transform.localScale = new Vector3(1, 1, gridSize + 2);
GameObject.Find("sW").transform.localScale = new Vector3(1, 1, gridSize + 2);
GameObject.Find("sE").transform.position = new Vector3(gridSize, 0.0f, (gridSize - 1) / 2f);
GameObject.Find("sW").transform.position = new Vector3(-1, 0.0f, (gridSize - 1) / 2f);
aCam.orthographicSize = ((int)resetParameters["gridSize"]) / 2f;
aCam.transform.position = new Vector3(((int)resetParameters["gridSize"] - 1) / 2f, (int)resetParameters["gridSize"] + 1f, ((int)resetParameters["gridSize"] - 1) / 2f);
aCam.orthographicSize = (gridSize) / 2f;
aCam.transform.position = new Vector3((gridSize - 1) / 2f, gridSize + 1f, (gridSize - 1) / 2f);
}

actorObjs = new List<GameObject>();
HashSet<int> numbers = new HashSet<int>();
while (numbers.Count < players.Length)
while (numbers.Count < players.Length + 1)
numbers.Add(Random.Range(0, (int)resetParameters["gridSize"] * (int)resetParameters["gridSize"]));
numbers.Add(Random.Range(0, gridSize * gridSize));
int x = (numbersA[i]) / (int)resetParameters["gridSize"];
int y = (numbersA[i]) % (int)resetParameters["gridSize"];
int x = (numbersA[i]) / gridSize;
int y = (numbersA[i]) % gridSize;
if (players[i] == "agent")
{
trueAgent.transform.position = actorObj.transform.position;
trueAgent.transform.rotation = actorObj.transform.rotation;
visualAgent = actorObj;
}
int x_a = (numbersA[players.Length]) / gridSize;
int y_a = (numbersA[players.Length]) % gridSize;
trueAgent.transform.position = new Vector3(x_a, -0.25f, y_a);
}

95
unity-environment/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs


{
[Header("Specific to GridWorld")]
public GridAcademy academy;
[HideInInspector]
public int gridSize;
GameObject trueAgent;
trueAgent = gameObject;
gridSize = (int)academy.resetParameters["gridSize"];
int closestGoalDistance = 2 * (int)academy.resetParameters["gridSize"];
GameObject currentClosestGoal = academy.actorObjs[0];
int closestPitDistance = 2 * (int)academy.resetParameters["gridSize"];
GameObject currentClosestPit = academy.actorObjs[0];
GameObject agent = academy.actorObjs[0];
foreach (GameObject actor in academy.actorObjs)
{
if (actor.CompareTag("agent"))
{
agent = actor;
state.Add(actor.transform.position.x / (gridSize + 1));
state.Add(actor.transform.position.z / (gridSize + 1));
continue;
}
}
foreach (GameObject actor in academy.actorObjs)
{
if (actor.CompareTag("goal"))
{
int distance = (int)Mathf.Abs(agent.transform.position.x - actor.transform.position.x) + (int)Mathf.Abs(agent.transform.position.z - actor.transform.position.z);
if (closestGoalDistance > distance)
{
closestGoalDistance = distance;
currentClosestGoal = actor;
}
}
if (actor.CompareTag("pit"))
{
int distance = (int)Mathf.Abs(agent.transform.position.x - actor.transform.position.x) + (int)Mathf.Abs(agent.transform.position.z - actor.transform.position.z);
if (closestPitDistance > distance)
{
closestPitDistance = distance;
currentClosestPit = actor;
}
}
}
state.Add(currentClosestGoal.transform.position.x / (gridSize + 1));
state.Add(currentClosestGoal.transform.position.z / (gridSize + 1));
state.Add(currentClosestPit.transform.position.x / (gridSize + 1));
state.Add(currentClosestPit.transform.position.z / (gridSize + 1));
return state;
}

int action = Mathf.FloorToInt(act[0]);
// 0 - Forward, 1 - Backward, 2 - Left, 3 - Right
Vector3 targetPos = transform.position;
Collider[] blockTest = Physics.OverlapBox(new Vector3(trueAgent.transform.position.x + 1, 0, trueAgent.transform.position.z), new Vector3(0.3f, 0.3f, 0.3f));
if (blockTest.Where(col => col.gameObject.tag == "wall").ToArray().Length == 0)
{
trueAgent.transform.position = new Vector3(trueAgent.transform.position.x + 1, 0, trueAgent.transform.position.z);
}
targetPos = transform.position + new Vector3(1f, 0, 0f);
Collider[] blockTest = Physics.OverlapBox(new Vector3(trueAgent.transform.position.x - 1, 0, trueAgent.transform.position.z), new Vector3(0.3f, 0.3f, 0.3f));
if (blockTest.Where(col => col.gameObject.tag == "wall").ToArray().Length == 0)
{
trueAgent.transform.position = new Vector3(trueAgent.transform.position.x - 1, 0, trueAgent.transform.position.z);
}
targetPos = transform.position + new Vector3(-1f, 0, 0f);
Collider[] blockTest = Physics.OverlapBox(new Vector3(trueAgent.transform.position.x, 0, trueAgent.transform.position.z + 1), new Vector3(0.3f, 0.3f, 0.3f));
if (blockTest.Where(col => col.gameObject.tag == "wall").ToArray().Length == 0)
{
trueAgent.transform.position = new Vector3(trueAgent.transform.position.x, 0, trueAgent.transform.position.z + 1);
}
targetPos = transform.position + new Vector3(0f, 0, 1f);
Collider[] blockTest = Physics.OverlapBox(new Vector3(trueAgent.transform.position.x, 0, trueAgent.transform.position.z - 1), new Vector3(0.3f, 0.3f, 0.3f));
if (blockTest.Where(col => col.gameObject.tag == "wall").ToArray().Length == 0)
{
trueAgent.transform.position = new Vector3(trueAgent.transform.position.x, 0, trueAgent.transform.position.z - 1);
}
targetPos = transform.position + new Vector3(0f, 0, -1f);
}
Collider[] blockTest = Physics.OverlapBox(targetPos, new Vector3(0.3f, 0.3f, 0.3f));
if (blockTest.Where(col => col.gameObject.tag == "wall").ToArray().Length == 0)
{
transform.position = targetPos;
}
Collider[] hitObjects = Physics.OverlapBox(trueAgent.transform.position, new Vector3(0.3f, 0.3f, 0.3f));
if (hitObjects.Where(col => col.gameObject.tag == "goal").ToArray().Length == 1)
void OnTriggerEnter(Collider col)
{
if (col.gameObject.CompareTag("goal"))
if (hitObjects.Where(col => col.gameObject.tag == "pit").ToArray().Length == 1)
if (col.gameObject.CompareTag("pit"))
}
//if (trainMode == "train") {
if (true)
{
academy.visualAgent.transform.position = trueAgent.transform.position;
academy.visualAgent.transform.rotation = trueAgent.transform.rotation;
}
}

1000
unity-environment/Assets/ML-Agents/Examples/GridWorld/TFModels/GridWorld.bytes
文件差异内容过多而无法显示
查看文件

7
unity-environment/Assets/ML-Agents/Examples/GridWorld/TFModels/GridWorld.bytes.meta


fileFormatVersion: 2
guid: 9c75cb395cc9943838c0694ad4bc2604
timeCreated: 1505542949
licenseType: Free
guid: 426162c47484e466d8378d2321a5617c
timeCreated: 1515001510
licenseType: Pro
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
unity-environment/Assets/ML-Agents/Materials/MaterialsGrid/Floor.mat


m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 0.9, y: 0.9}
m_Scale: {x: 3, y: 3}
m_Scale: {x: 0.9, y: 0.9}
m_Scale: {x: 3, y: 3}
m_Offset: {x: 0.03, y: 0.06}
- _MetallicGlossMap:
m_Texture: {fileID: 0}

- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 1
- _Metallic: 0

- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0.94509804, g: 0.9529412, b: 0.95686275, a: 1}
- _Color: {r: 0, g: 0, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
正在加载...
取消
保存