浏览代码

[MLA-1912] Move Match3 to com.unity.ml-agents (#5259)

/check-for-ModelOverriders
GitHub 4 年前
当前提交
76722df4
共有 30 个文件被更改,包括 57 次插入44 次删除
  1. 2
      Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3Agent.cs
  2. 2
      Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3Board.cs
  3. 2
      Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuator.cs
  4. 2
      Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs
  5. 3
      com.unity.ml-agents.extensions/Documentation~/com.unity.ml-agents.extensions.md
  6. 1
      com.unity.ml-agents/CHANGELOG.md
  7. 15
      com.unity.ml-agents/Documentation~/com.unity.ml-agents.md
  8. 3
      com.unity.ml-agents/Tests/Editor/Unity.ML-Agents.Editor.Tests.asmdef
  9. 2
      docs/Migrating.md
  10. 11
      docs/Integrations-Match3.md
  11. 6
      com.unity.ml-agents/Runtime/Integrations/Match3/AbstractBoard.cs
  12. 3
      com.unity.ml-agents/Runtime/Integrations/Match3/Match3Actuator.cs
  13. 2
      com.unity.ml-agents/Runtime/Integrations/Match3/Match3ActuatorComponent.cs
  14. 3
      com.unity.ml-agents/Runtime/Integrations/Match3/Match3Sensor.cs
  15. 2
      com.unity.ml-agents/Runtime/Integrations/Match3/Match3SensorComponent.cs
  16. 4
      com.unity.ml-agents/Runtime/Integrations/Match3/Move.cs
  17. 4
      com.unity.ml-agents/Tests/Editor/Integrations/Match3/AbstractBoardTests.cs
  18. 4
      com.unity.ml-agents/Tests/Editor/Integrations/Match3/Match3ActuatorTests.cs
  19. 10
      com.unity.ml-agents/Tests/Editor/Integrations/Match3/Match3SensorTests.cs
  20. 4
      com.unity.ml-agents/Tests/Editor/Integrations/Match3/MoveTests.cs
  21. 3
      com.unity.ml-agents/Runtime/Integrations.meta
  22. 3
      com.unity.ml-agents/Tests/Editor/Integrations.meta
  23. 10
      docs/Integrations.md
  24. 0
      /docs/Integrations-Match3.md
  25. 0
      /com.unity.ml-agents/Runtime/Integrations/Match3.meta
  26. 0
      /com.unity.ml-agents/Runtime/Integrations/Match3
  27. 0
      /com.unity.ml-agents/Tests/Editor/Integrations/Match3.meta
  28. 0
      /com.unity.ml-agents/Tests/Editor/Integrations/Match3

2
Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3Agent.cs


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Extensions.Match3;
using Unity.MLAgents.Integrations.Match3;
namespace Unity.MLAgentsExamples
{

2
Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3Board.cs


using System;
using Unity.MLAgents.Extensions.Match3;
using Unity.MLAgents.Integrations.Match3;
using UnityEngine;
using UnityEngine.Serialization;

2
Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuator.cs


using Unity.MLAgents;
using Unity.MLAgents.Extensions.Match3;
using Unity.MLAgents.Integrations.Match3;
namespace Unity.MLAgentsExamples
{

2
Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs


using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Extensions.Match3;
using Unity.MLAgents.Integrations.Match3;
namespace Unity.MLAgentsExamples
{

3
com.unity.ml-agents.extensions/Documentation~/com.unity.ml-agents.extensions.md


| _Runtime_ | Contains core C# APIs for integrating ML-Agents into your Unity scene. |
| _Tests_ | Contains the unit tests for the package. |
The Runtime directory currently contains three features:
* [Match-3 sensor and actuator](Match3.md)
The Runtime directory currently contains these features:
* [Grid-based sensor](Grid-Sensor.md)
* Physics-based sensors
* [Input System Package Integration](InputActuatorComponent.md)

1
com.unity.ml-agents/CHANGELOG.md


amount of memory that needs to be allocated during runtime. (#5233)
- Optimzed `ObservationWriter.WriteTexture()` so that it doesn't call `Texture2D.GetPixels32()` for `RGB24` textures.
This results in much less memory being allocated during inference with `CameraSensor` and `RenderTextureSensor`. (#5233)
- The Match-3 integration utilities were moved from `com.unity.ml-agents.extensions` to `com.unity.ml-agents`. (#5259)
#### ml-agents / ml-agents-envs / gym-unity (Python)
- Some console output have been moved from `info` to `debug` and will not be printed by default. If you want all messages to be printed, you can run `mlagents-learn` with the `--debug` option or add the line `debug: true` at the top of the yaml config file. (#5211)

15
com.unity.ml-agents/Documentation~/com.unity.ml-agents.md


The following table describes the package folder structure:
| **Location** | **Description** |
| ---------------- | ---------------------------------------------------------------------- |
| _Documentation~_ | Contains the documentation for the Unity package. |
| _Editor_ | Contains utilities for Editor windows and drawers. |
| _Plugins_ | Contains third-party DLLs. |
| _Runtime_ | Contains core C# APIs for integrating ML-Agents into your Unity scene. |
| _Tests_ | Contains the unit tests for the package. |
| **Location** | **Description** |
| ---------------------- | ----------------------------------------------------------------------- |
| _Documentation~_ | Contains the documentation for the Unity package. |
| _Editor_ | Contains utilities for Editor windows and drawers. |
| _Plugins_ | Contains third-party DLLs. |
| _Runtime_ | Contains core C# APIs for integrating ML-Agents into your Unity scene. |
| _Runtime/Integrations_ | Contains utilities for integrating ML-Agents into specific game genres. |
| _Tests_ | Contains the unit tests for the package. |
<a name="Installation"></a>

3
com.unity.ml-agents/Tests/Editor/Unity.ML-Agents.Editor.Tests.asmdef


"Unity.ML-Agents",
"Unity.Barracuda",
"Unity.ML-Agents.CommunicatorObjects",
"Unity.ML-Agents.Runtime.Utils.Tests"
"Unity.ML-Agents.Runtime.Utils.Tests",
"Unity.ML-Agents.Runtime.Sensor.Tests"
],
"optionalUnityReferences": [
"TestAssemblies"

2
docs/Migrating.md


- The abstract method `SensorComponent.CreateSensor()` was replaced with `CreateSensors()`, which returns an `ISensor[]`.
### Match3 integration changes
The Match-3 integration utilities were moved from `com.unity.ml-agents.extensions` to `com.unity.ml-agents`.
The `AbstractBoard` interface was changed:
* `AbstractBoard` no longer contains `Rows`, `Columns`, `NumCellTypes`, and `NumSpecialTypes` fields.
* `public abstract BoardSize GetMaxBoardSize()` was added as an abstract method. `BoardSize` is a new struct that

11
docs/Integrations-Match3.md


<img src="images/match3.png" align="center" width="3000"/>
## Getting started
The C# code for Match-3 exists inside of the extensions package (com.unity.ml-agents.extensions). A good first step
would be to familiarize with the extensions package by reading the document [here](com.unity.ml-agents.extensions.md).
The second step would be to take a look at how we have implemented the C# code in the example Match-3 scene (located
The C# code for Match-3 exists inside of the Unity package (`com.unity.ml-agents`).
The good first step would be to take a look at how we have implemented the C# code in the example Match-3 scene (located
isn't human playable as implemented and can be only played via training.
isn't human playable as implemented and can be only played via training.
## Technical specifications for Match-3 with ML-Agents

[we want to hear from you](https://forms.gle/TBsB9jc8WshgzViU9). Additionally, we are also looking for interested
Match-3 teams to speak with us for 45 minutes. If you are interested, please indicate that in the
[form](https://forms.gle/TBsB9jc8WshgzViU9). If selected, we will provide gift cards as a token of appreciation.
### Interested in more game templates?
Do you have a type of game you are interested for ML-Agents? If so, please post a
[forum issue](https://forum.unity.com/forums/ml-agents.453/) with [GAME TEMPLATE] in the title.

6
com.unity.ml-agents/Runtime/Integrations/Match3/AbstractBoard.cs


using UnityEngine;
using Debug = UnityEngine.Debug;
namespace Unity.MLAgents.Extensions.Match3
namespace Unity.MLAgents.Integrations.Match3
/// Representation of the AbstractBoard size and number of cell and special types.
/// Representation of the AbstractBoard dimensions, and number of cell and special types.
/// </summary>
public struct BoardSize
{

public abstract bool IsMoveValid(Move m);
/// <summary>
/// Instruct the game to make the given move. Returns true if the move was made.
/// Instruct the game to make the given Move. Returns true if the move was made.
/// Note that during training, a move that was marked as invalid may occasionally still be
/// requested. If this happens, it is safe to do nothing and request another move.
/// </summary>

3
com.unity.ml-agents/Runtime/Integrations/Match3/Match3Actuator.cs


using Debug = UnityEngine.Debug;
namespace Unity.MLAgents.Extensions.Match3
namespace Unity.MLAgents.Integrations.Match3
{
/// <summary>
/// Actuator for a Match3 game. It translates valid moves (defined by AbstractBoard.IsMoveValid())

/// <param name="forceHeuristic">Whether the inference action should be ignored and the Agent's Heuristic
/// should be called. This should only be used for generating comparison stats of the Heuristic.</param>
/// <param name="seed">The seed used to initialize <see cref="System.Random"/>.</param>
/// <param name="agent"></param>
/// <param name="name"></param>
public Match3Actuator(AbstractBoard board,
bool forceHeuristic,

2
com.unity.ml-agents/Runtime/Integrations/Match3/Match3ActuatorComponent.cs


using UnityEngine;
using UnityEngine.Serialization;
namespace Unity.MLAgents.Extensions.Match3
namespace Unity.MLAgents.Integrations.Match3
{
/// <summary>
/// Actuator component for a Match3 game. Generates a Match3Actuator at runtime.

3
com.unity.ml-agents/Runtime/Integrations/Match3/Match3Sensor.cs


using Unity.MLAgents.Sensors;
using UnityEngine;
namespace Unity.MLAgents.Extensions.Match3
namespace Unity.MLAgents.Integrations.Match3
{
/// <summary>
/// Delegate that provides integer values at a given (x,y) coordinate.

offset += m_OneHotSize;
}
}
return offset;
}

2
com.unity.ml-agents/Runtime/Integrations/Match3/Match3SensorComponent.cs


using Unity.MLAgents.Sensors;
using UnityEngine;
namespace Unity.MLAgents.Extensions.Match3
namespace Unity.MLAgents.Integrations.Match3
{
/// <summary>
/// Sensor component for a Match3 game.

4
com.unity.ml-agents/Runtime/Integrations/Match3/Move.cs


using System;
using UnityEngine;
namespace Unity.MLAgents.Extensions.Match3
namespace Unity.MLAgents.Integrations.Match3
{
/// <summary>
/// Directions for a Move.

}
/// <summary>
/// Construct a Move from the row, column, and direction.
/// Construct a Move from the row, column, direction, and board size.
/// </summary>
/// <param name="row"></param>
/// <param name="col"></param>

4
com.unity.ml-agents/Tests/Editor/Integrations/Match3/AbstractBoardTests.cs


using System.Collections.Generic;
using UnityEngine;
using NUnit.Framework;
using Unity.MLAgents.Extensions.Match3;
using Unity.MLAgents.Integrations.Match3;
namespace Unity.MLAgents.Extensions.Tests.Match3
namespace Unity.MLAgents.Tests.Integrations.Match3
{
internal class StringBoard : AbstractBoard
{

4
com.unity.ml-agents/Tests/Editor/Integrations/Match3/Match3ActuatorTests.cs


using System.Collections.Generic;
using NUnit.Framework;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Extensions.Match3;
using Unity.MLAgents.Integrations.Match3;
namespace Unity.MLAgents.Extensions.Tests.Match3
namespace Unity.MLAgents.Tests.Integrations.Match3
{
internal class SimpleBoard : AbstractBoard
{

10
com.unity.ml-agents/Tests/Editor/Integrations/Match3/Match3SensorTests.cs


using System.IO;
using System.Reflection;
using NUnit.Framework;
using Unity.MLAgents.Extensions.Match3;
using Unity.MLAgents.Extensions.Tests.Sensors;
using Unity.MLAgents.Integrations.Match3;
using Unity.MLAgents.Tests;
namespace Unity.MLAgents.Extensions.Tests.Match3
namespace Unity.MLAgents.Tests.Integrations.Match3
{
public class Match3SensorTests
{

for (var i = 0; i < splitPngs.Count; i++)
{
var pngData = splitPngs[i];
var path = $"Packages/com.unity.ml-agents.extensions/Tests/Editor/Match3/{pathPrefix}{i}.png";
var path = $"Packages/com.unity.ml-agents/Tests/Editor/Integrations/Match3/{pathPrefix}{i}.png";
using (var sw = File.Create(path))
{
foreach (var b in pngData)

var bytesOut = new List<byte>();
for (var i = 0; i < numExpected; i++)
{
var path = $"Packages/com.unity.ml-agents.extensions/Tests/Editor/Match3/{pathPrefix}{i}.png";
var path = $"Packages/com.unity.ml-agents/Tests/Editor/Integrations/Match3/{pathPrefix}{i}.png";
var res = File.ReadAllBytes(path);
bytesOut.AddRange(res);
}

4
com.unity.ml-agents/Tests/Editor/Integrations/Match3/MoveTests.cs


using System;
using NUnit.Framework;
using Unity.MLAgents.Extensions.Match3;
using Unity.MLAgents.Integrations.Match3;
namespace Unity.MLAgents.Extensions.Tests.Match3
namespace Unity.MLAgents.Tests.Integrations.Match3
{
public class MoveTests
{

3
com.unity.ml-agents/Runtime/Integrations.meta


fileFormatVersion: 2
guid: f8f4fd0bc35f4e8f9867228591f663e3
timeCreated: 1618359419

3
com.unity.ml-agents/Tests/Editor/Integrations.meta


fileFormatVersion: 2
guid: 7e89e6f6ab7e4c9397958c0320bd5931
timeCreated: 1618359633

10
docs/Integrations.md


# Game Integrations
ML-Agents provides some utilities to make it easier to integrate with some common genres of games.
## Match-3
The [Match-3 integration](Integrations-Match3.md) provides an abstraction of a match-3 game board and moves, along with
a sensor to observe the game state, and an actuator to translate the ML-Agent actions into game moves.
## Interested in more game templates?
Do you have a type of game you are interested for ML-Agents? If so, please post a
[forum issue](https://forum.unity.com/forums/ml-agents.453/) with `[GAME TEMPLATE]` in the title.

/com.unity.ml-agents.extensions/Documentation~/Match3.md → /docs/Integrations-Match3.md

/com.unity.ml-agents.extensions/Runtime/Match3.meta → /com.unity.ml-agents/Runtime/Integrations/Match3.meta

/com.unity.ml-agents.extensions/Runtime/Match3 → /com.unity.ml-agents/Runtime/Integrations/Match3

/com.unity.ml-agents.extensions/Tests/Editor/Match3.meta → /com.unity.ml-agents/Tests/Editor/Integrations/Match3.meta

/com.unity.ml-agents.extensions/Tests/Editor/Match3 → /com.unity.ml-agents/Tests/Editor/Integrations/Match3

正在加载...
取消
保存