vincentpierre
4 年前
当前提交
bcec7303
共有 34 个文件被更改,包括 546 次插入 和 244 次删除
-
1.yamato/gym-interface-test.yml
-
16Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicActuatorComponent.cs
-
25Project/Assets/ML-Agents/Examples/Match3/Prefabs/Match3Heuristic.prefab
-
25Project/Assets/ML-Agents/Examples/Match3/Prefabs/Match3VectorObs.prefab
-
25Project/Assets/ML-Agents/Examples/Match3/Prefabs/Match3VisualObs.prefab
-
10Project/Assets/ML-Agents/Examples/Match3/Scenes/Match3.unity
-
166Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3Agent.cs
-
13Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3Board.cs
-
74com.unity.ml-agents.extensions/Runtime/Match3/Match3Actuator.cs
-
10com.unity.ml-agents.extensions/Runtime/Match3/Match3ActuatorComponent.cs
-
7com.unity.ml-agents/CHANGELOG.md
-
43com.unity.ml-agents/Runtime/Actuators/ActuatorManager.cs
-
27com.unity.ml-agents/Runtime/Actuators/VectorActuator.cs
-
38com.unity.ml-agents/Runtime/Agent.cs
-
9com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs
-
11com.unity.ml-agents/Runtime/Policies/HeuristicPolicy.cs
-
12com.unity.ml-agents/Runtime/SideChannels/EngineConfigurationChannel.cs
-
18com.unity.ml-agents/Tests/Editor/Actuators/ActuatorManagerTests.cs
-
11com.unity.ml-agents/Tests/Editor/Actuators/TestActuator.cs
-
19com.unity.ml-agents/Tests/Editor/Actuators/VectorActuatorTests.cs
-
6com.unity.ml-agents/Tests/Editor/BehaviorParameterTests.cs
-
8docs/Migrating.md
-
121Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuator.cs
-
3Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuator.cs.meta
-
18Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs
-
3Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs.meta
-
18com.unity.ml-agents/Runtime/Actuators/IHeuristicProvider.cs
-
3com.unity.ml-agents/Runtime/Actuators/IHeuristicProvider.cs.meta
-
3com.unity.ml-agents/Tests/Editor/SideChannels.meta
-
44com.unity.ml-agents/Tests/Editor/SideChannels/EngineConfigurationChannelTests.cs
-
3com.unity.ml-agents/Tests/Editor/SideChannels/EngineConfigurationChannelTests.cs.meta
-
0/com.unity.ml-agents/Tests/Editor/SideChannels/SideChannelTests.cs.meta
-
0/com.unity.ml-agents/Tests/Editor/SideChannels/SideChannelTests.cs
|
|||
using Unity.MLAgents; |
|||
using Unity.MLAgents.Extensions.Match3; |
|||
|
|||
namespace Unity.MLAgentsExamples |
|||
{ |
|||
public class Match3ExampleActuator : Match3Actuator |
|||
{ |
|||
Match3Board Board => (Match3Board)m_Board; |
|||
|
|||
public Match3ExampleActuator(Match3Board board, |
|||
bool forceHeuristic, |
|||
Agent agent, |
|||
string name, |
|||
int seed |
|||
) |
|||
: base(board, forceHeuristic, seed, agent, name) { } |
|||
|
|||
|
|||
protected override int EvalMovePoints(Move move) |
|||
{ |
|||
var pointsByType = new[] { Board.BasicCellPoints, Board.SpecialCell1Points, Board.SpecialCell2Points }; |
|||
// Counts the expected points for making the move.
|
|||
var moveVal = m_Board.GetCellType(move.Row, move.Column); |
|||
var moveSpecial = m_Board.GetSpecialType(move.Row, move.Column); |
|||
var (otherRow, otherCol) = move.OtherCell(); |
|||
var oppositeVal = m_Board.GetCellType(otherRow, otherCol); |
|||
var oppositeSpecial = m_Board.GetSpecialType(otherRow, otherCol); |
|||
|
|||
|
|||
int movePoints = EvalHalfMove( |
|||
otherRow, otherCol, moveVal, moveSpecial, move.Direction, pointsByType |
|||
); |
|||
int otherPoints = EvalHalfMove( |
|||
move.Row, move.Column, oppositeVal, oppositeSpecial, move.OtherDirection(), pointsByType |
|||
); |
|||
return movePoints + otherPoints; |
|||
} |
|||
|
|||
int EvalHalfMove(int newRow, int newCol, int newValue, int newSpecial, Direction incomingDirection, int[] pointsByType) |
|||
{ |
|||
// This is a essentially a duplicate of AbstractBoard.CheckHalfMove but also counts the points for the move.
|
|||
int matchedLeft = 0, matchedRight = 0, matchedUp = 0, matchedDown = 0; |
|||
int scoreLeft = 0, scoreRight = 0, scoreUp = 0, scoreDown = 0; |
|||
|
|||
if (incomingDirection != Direction.Right) |
|||
{ |
|||
for (var c = newCol - 1; c >= 0; c--) |
|||
{ |
|||
if (m_Board.GetCellType(newRow, c) == newValue) |
|||
{ |
|||
matchedLeft++; |
|||
scoreLeft += pointsByType[m_Board.GetSpecialType(newRow, c)]; |
|||
} |
|||
else |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (incomingDirection != Direction.Left) |
|||
{ |
|||
for (var c = newCol + 1; c < m_Board.Columns; c++) |
|||
{ |
|||
if (m_Board.GetCellType(newRow, c) == newValue) |
|||
{ |
|||
matchedRight++; |
|||
scoreRight += pointsByType[m_Board.GetSpecialType(newRow, c)]; |
|||
} |
|||
else |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (incomingDirection != Direction.Down) |
|||
{ |
|||
for (var r = newRow + 1; r < m_Board.Rows; r++) |
|||
{ |
|||
if (m_Board.GetCellType(r, newCol) == newValue) |
|||
{ |
|||
matchedUp++; |
|||
scoreUp += pointsByType[m_Board.GetSpecialType(r, newCol)]; |
|||
} |
|||
else |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (incomingDirection != Direction.Up) |
|||
{ |
|||
for (var r = newRow - 1; r >= 0; r--) |
|||
{ |
|||
if (m_Board.GetCellType(r, newCol) == newValue) |
|||
{ |
|||
matchedDown++; |
|||
scoreDown += pointsByType[m_Board.GetSpecialType(r, newCol)]; |
|||
} |
|||
else |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if ((matchedUp + matchedDown >= 2) || (matchedLeft + matchedRight >= 2)) |
|||
{ |
|||
// It's a match. Start from counting the piece being moved
|
|||
var totalScore = pointsByType[newSpecial]; |
|||
if (matchedUp + matchedDown >= 2) |
|||
{ |
|||
totalScore += scoreUp + scoreDown; |
|||
} |
|||
|
|||
if (matchedLeft + matchedRight >= 2) |
|||
{ |
|||
totalScore += scoreLeft + scoreRight; |
|||
} |
|||
return totalScore; |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9e6fe1a020a04421ab828be4543a655c |
|||
timeCreated: 1610665874 |
|
|||
using Unity.MLAgents; |
|||
using Unity.MLAgents.Actuators; |
|||
using Unity.MLAgents.Extensions.Match3; |
|||
|
|||
namespace Unity.MLAgentsExamples |
|||
{ |
|||
public class Match3ExampleActuatorComponent : Match3ActuatorComponent |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public override IActuator CreateActuator() |
|||
{ |
|||
var board = GetComponent<Match3Board>(); |
|||
var agent = GetComponentInParent<Agent>(); |
|||
var seed = RandomSeed == -1 ? gameObject.GetInstanceID() : RandomSeed + 1; |
|||
return new Match3ExampleActuator(board, ForceHeuristic, agent, ActuatorName, seed); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b17adcc6c9b241da903aa134f2dac930 |
|||
timeCreated: 1610665885 |
|
|||
namespace Unity.MLAgents.Actuators |
|||
{ |
|||
/// <summary>
|
|||
/// Interface that allows objects to fill out an <see cref="ActionBuffers"/> data structure for controlling
|
|||
/// behavior of Agents or Actuators.
|
|||
/// </summary>
|
|||
public interface IHeuristicProvider |
|||
{ |
|||
/// <summary>
|
|||
/// Method called on objects which are expected to fill out the <see cref="ActionBuffers"/> data structure.
|
|||
/// Object that implement this interface should be careful to be consistent in the placement of their actions
|
|||
/// in the <see cref="ActionBuffers"/> data structure.
|
|||
/// </summary>
|
|||
/// <param name="actionBuffersOut">The <see cref="ActionBuffers"/> data structure to be filled by the
|
|||
/// object implementing this interface.</param>
|
|||
void Heuristic(in ActionBuffers actionBuffersOut); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: be90ffb28f39444a8fb02dfd4a82870c |
|||
timeCreated: 1610057456 |
|
|||
fileFormatVersion: 2 |
|||
guid: 1228f198ceee45a38c7d9ff50425b65d |
|||
timeCreated: 1610760867 |
|
|||
using NUnit.Framework; |
|||
using Unity.MLAgents.SideChannels; |
|||
using UnityEngine; |
|||
|
|||
namespace Unity.MLAgents.Tests |
|||
{ |
|||
public class EngineConfigurationChannelTests |
|||
{ |
|||
float m_OldTimeScale = 1.0f; |
|||
|
|||
[SetUp] |
|||
public void Setup() |
|||
{ |
|||
m_OldTimeScale = Time.timeScale; |
|||
} |
|||
|
|||
[TearDown] |
|||
public void TearDown() |
|||
{ |
|||
Time.timeScale = m_OldTimeScale; |
|||
} |
|||
|
|||
[Test] |
|||
public void TestTimeScaleClamping() |
|||
{ |
|||
OutgoingMessage pythonMsg = new OutgoingMessage(); |
|||
pythonMsg.WriteInt32((int)EngineConfigurationChannel.ConfigurationType.TimeScale); |
|||
pythonMsg.WriteFloat32(1000f); |
|||
|
|||
var sideChannel = new EngineConfigurationChannel(); |
|||
sideChannel.ProcessMessage(pythonMsg.ToByteArray()); |
|||
|
|||
#if UNITY_EDITOR
|
|||
// Should be clamped
|
|||
Assert.AreEqual(100.0f, Time.timeScale); |
|||
#else
|
|||
// Not sure we can run this test from a player, but just in case, shouldn't clamp.
|
|||
Assert.AreEqual(1000.0f, Time.timeScale); |
|||
#endif
|
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 71aa620295f74ca5875e8e4782f08768 |
|||
timeCreated: 1610760906 |
撰写
预览
正在加载...
取消
保存
Reference in new issue