Skip to content

Commit 6249f6a

Browse files
Chris ElionErvin Tvincentpierre
authored
[MLA-1223] Backport Heuristic fixes (#4176)
* [bugfix] Make FoodCollector heuristic playable (#4147) * Modified the documentation of the Heuristic method (default action = previous action) (#4174) Co-authored-by: Ervin T <[email protected]> Co-authored-by: Vincent-Pierre BERGES <[email protected]>
1 parent 4001909 commit 6249f6a

File tree

5 files changed

+9
-0
lines changed

5 files changed

+9
-0
lines changed

Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorAgent.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ public override void OnActionReceived(float[] vectorAction)
209209

210210
public override void Heuristic(float[] actionsOut)
211211
{
212+
actionsOut[0] = 0f;
213+
actionsOut[1] = 0f;
214+
actionsOut[2] = 0f;
212215
if (Input.GetKey(KeyCode.D))
213216
{
214217
actionsOut[2] = 2f;

Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public override void OnActionReceived(float[] vectorAction)
166166

167167
public override void Heuristic(float[] actionsOut)
168168
{
169+
Array.Clear(actionsOut, 0, actionsOut.Length);
169170
//forward
170171
if (Input.GetKey(KeyCode.W))
171172
{

Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpAgent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ public override void OnActionReceived(float[] vectorAction)
242242

243243
public override void Heuristic(float[] actionsOut)
244244
{
245+
System.Array.Clear(actionsOut, 0, actionsOut.Length);
245246
if (Input.GetKey(KeyCode.D))
246247
{
247248
actionsOut[1] = 2f;

com.unity.ml-agents/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to
1212
- Fixed an issue where RayPerceptionSensor would raise an exception when the
1313
list of tags was empty, or a tag in the list was invalid (unknown, null, or
1414
empty string). (#4155)
15+
#### ml-agents / ml-agents-envs / gym-unity (Python)
16+
- Fixed issue with FoodCollector, Soccer, and WallJump when playing with keyboard. (#4147, #4174)
1517

1618
## [1.0.2] - 2020-06-04
1719
### Minor Changes

com.unity.ml-agents/Runtime/Agent.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ public virtual void Initialize() {}
761761
///
762762
/// Your heuristic implementation can use any decision making logic you specify. Assign decision
763763
/// values to the float[] array, <paramref name="actionsOut"/>, passed to your function as a parameter.
764+
/// The same array will be reused between steps. It is up to the user to initialize
765+
/// the values on each call, for example by calling `Array.Clear(actionsOut, 0, actionsOut.Length);`.
764766
/// Add values to the array at the same indexes as they are used in your
765767
/// <seealso cref="OnActionReceived(float[])"/> function, which receives this array and
766768
/// implements the corresponding agent behavior. See [Actions] for more information

0 commit comments

Comments
 (0)