Пример #1
0
        public void TestVectorObservations()
        {
            var boardString =
                @"000
                  000
                  010";
            var gameObj = new GameObject("board");
            var board   = gameObj.AddComponent <StringBoard>();

            board.SetBoard(boardString);

            var sensorComponent = gameObj.AddComponent <Match3SensorComponent>();

            sensorComponent.ObservationType = Match3ObservationType.Vector;
            var sensor = sensorComponent.CreateSensor();

            var expectedShape = new[] { 3 * 3 * 2 };

            Assert.AreEqual(expectedShape, sensorComponent.GetObservationShape());
            Assert.AreEqual(InplaceArray <int> .FromList(expectedShape), sensor.GetObservationSpec().Shape);

            var expectedObs = new float[]
            {
                1, 0, /**/ 0, 1, /**/ 1, 0,
                1, 0, /**/ 1, 0, /**/ 1, 0,
                1, 0, /**/ 1, 0, /**/ 1, 0,
            };

            SensorTestHelper.CompareObservation(sensor, expectedObs);
        }
Пример #2
0
        public void TestVectorObservationsSpecial()
        {
            var boardString =
                @"000
                  000
                  010";
            var specialString =
                @"010
                  200
                  000";

            var gameObj = new GameObject("board");
            var board   = gameObj.AddComponent <StringBoard>();

            board.SetBoard(boardString);
            board.SetSpecial(specialString);

            var sensorComponent = gameObj.AddComponent <Match3SensorComponent>();

            sensorComponent.ObservationType = Match3ObservationType.Vector;
            var sensors       = sensorComponent.CreateSensors();
            var cellSensor    = sensors[0];
            var specialSensor = sensors[1];


            {
                var expectedShape = new InplaceArray <int>(3 * 3 * 2);
                Assert.AreEqual(expectedShape, cellSensor.GetObservationSpec().Shape);

                var expectedObs = new float[]
                {
                    1, 0, /* (0) */ 0, 1, /* (1) */ 1, 0, /* (0) */
                    1, 0, /* (0) */ 1, 0, /* (0) */ 1, 0, /* (0) */
                    1, 0, /* (0) */ 1, 0, /* (0) */ 1, 0, /* (0) */
                };
                SensorTestHelper.CompareObservation(cellSensor, expectedObs);
            }
            {
                var expectedShape = new InplaceArray <int>(3 * 3 * 3);
                Assert.AreEqual(expectedShape, specialSensor.GetObservationSpec().Shape);

                var expectedObs = new float[]
                {
                    1, 0, 0, /* (0) */ 1, 0, 0, /* (1) */ 1, 0, 0, /* (0) */
                    0, 0, 1, /* (2) */ 1, 0, 0, /* (0) */ 1, 0, 0, /* (0) */
                    1, 0, 0, /* (0) */ 0, 1, 0, /* (1) */ 1, 0, 0, /* (0) */
                };
                SensorTestHelper.CompareObservation(specialSensor, expectedObs);
            }
        }
Пример #3
0
        public void TestVisualObservationsSpecial()
        {
            var boardString =
                @"000
                  000
                  010";
            var specialString =
                @"010
                  200
                  000";

            var gameObj = new GameObject("board");
            var board   = gameObj.AddComponent <StringBoard>();

            board.SetBoard(boardString);
            board.SetSpecial(specialString);

            var sensorComponent = gameObj.AddComponent <Match3SensorComponent>();

            sensorComponent.ObservationType = Match3ObservationType.UncompressedVisual;
            var sensor = sensorComponent.CreateSensor();

            var expectedShape = new[] { 3, 3, 2 + 3 };

            Assert.AreEqual(expectedShape, sensorComponent.GetObservationShape());
            Assert.AreEqual(InplaceArray <int> .FromList(expectedShape), sensor.GetObservationSpec().Shape);

            Assert.AreEqual(SensorCompressionType.None, sensor.GetCompressionType());

            var expectedObs = new float[]
            {
                1, 0, 1, 0, 0, /* (0, 0) */ 0, 1, 1, 0, 0, /* (0, 1) */ 1, 0, 1, 0, 0, /* (0, 0) */
                1, 0, 0, 0, 1, /* (0, 2) */ 1, 0, 1, 0, 0, /* (0, 0) */ 1, 0, 1, 0, 0, /* (0, 0) */
                1, 0, 1, 0, 0, /* (0, 0) */ 1, 0, 0, 1, 0, /* (0, 1) */ 1, 0, 1, 0, 0, /* (0, 0) */
            };

            SensorTestHelper.CompareObservation(sensor, expectedObs);

            var expectedObs3D = new float[, , ]
            {
                { { 1, 0, 1, 0, 0 }, { 0, 1, 1, 0, 0 }, { 1, 0, 1, 0, 0 } },
                { { 1, 0, 0, 0, 1 }, { 1, 0, 1, 0, 0 }, { 1, 0, 1, 0, 0 } },
                { { 1, 0, 1, 0, 0 }, { 1, 0, 0, 1, 0 }, { 1, 0, 1, 0, 0 } },
            };

            SensorTestHelper.CompareObservation(sensor, expectedObs3D);
        }
Пример #4
0
        public void TestVectorObservations(bool fullBoard)
        {
            var boardString =
                @"000
                  000
                  010";
            var gameObj = new GameObject("board");
            var board   = gameObj.AddComponent <StringBoard>();

            board.SetBoard(boardString);
            if (!fullBoard)
            {
                board.CurrentRows    = 2;
                board.CurrentColumns = 2;
            }

            var sensorComponent = gameObj.AddComponent <Match3SensorComponent>();

            sensorComponent.ObservationType = Match3ObservationType.Vector;
            var sensor = sensorComponent.CreateSensors()[0];

            var expectedShape = new InplaceArray <int>(3 * 3 * 2);

            Assert.AreEqual(expectedShape, sensor.GetObservationSpec().Shape);

            float[] expectedObs;

            if (fullBoard)
            {
                expectedObs = new float[]
                {
                    1, 0, /* 0 */ 0, 1, /* 1 */ 1, 0, /* 0 */
                    1, 0, /* 0 */ 1, 0, /* 0 */ 1, 0, /* 0 */
                    1, 0, /* 0 */ 1, 0, /* 0 */ 1, 0, /* 0 */
                };
            }
            else
            {
                expectedObs = new float[]
                {
                    1, 0, /*   0   */ 0, 1, /*   1   */ 0, 0, /* empty */
                    1, 0, /*   0   */ 1, 0, /*   0   */ 0, 0, /* empty */
                    0, 0, /* empty */ 0, 0, /* empty */ 0, 0, /* empty */
                };
            }
            SensorTestHelper.CompareObservation(sensor, expectedObs);
        }
        public void TestVisualObservations()
        {
            var boardString =
                @"000
                  000
                  010";
            var gameObj = new GameObject("board");
            var board   = gameObj.AddComponent <StringBoard>();

            board.SetBoard(boardString);

            var sensorComponent = gameObj.AddComponent <Match3SensorComponent>();

            sensorComponent.ObservationType = Match3ObservationType.UncompressedVisual;
            var sensor = sensorComponent.CreateSensor();

            var expectedShape = new[] { 3, 3, 2 };

            Assert.AreEqual(expectedShape, sensorComponent.GetObservationShape());
            Assert.AreEqual(expectedShape, sensor.GetObservationShape());

            Assert.AreEqual(SensorCompressionType.None, sensor.GetCompressionType());

            var expectedObs = new float[]
            {
                1, 0, /**/ 0, 1, /**/ 1, 0,
                1, 0, /**/ 1, 0, /**/ 1, 0,
                1, 0, /**/ 1, 0, /**/ 1, 0,
            };

            SensorTestHelper.CompareObservation(sensor, expectedObs);

            var expectedObs3D = new float[, , ]
            {
                { { 1, 0 }, { 0, 1 }, { 1, 0 } },
                { { 1, 0 }, { 1, 0 }, { 1, 0 } },
                { { 1, 0 }, { 1, 0 }, { 1, 0 } },
            };

            SensorTestHelper.CompareObservation(sensor, expectedObs3D);
        }
        public void TestVectorObservationsSpecial()
        {
            var boardString =
                @"000
                  000
                  010";
            var specialString =
                @"010
                  200
                  000";

            var gameObj = new GameObject("board");
            var board   = gameObj.AddComponent <StringBoard>();

            board.SetBoard(boardString);
            board.SetSpecial(specialString);

            var sensorComponent = gameObj.AddComponent <Match3SensorComponent>();

            sensorComponent.ObservationType = Match3ObservationType.Vector;
            var sensor = sensorComponent.CreateSensor();

            var expectedShape = new[] { 3 * 3 * (2 + 3) };

            Assert.AreEqual(expectedShape, sensorComponent.GetObservationShape());
            Assert.AreEqual(expectedShape, sensor.GetObservationShape());

            var expectedObs = new float[]
            {
                1, 0, 1, 0, 0, /* (0, 0) */ 0, 1, 1, 0, 0, /* (0, 1) */ 1, 0, 1, 0, 0, /* (0, 0) */
                1, 0, 0, 0, 1, /* (0, 2) */ 1, 0, 1, 0, 0, /* (0, 0) */ 1, 0, 1, 0, 0, /* (0, 0) */
                1, 0, 1, 0, 0, /* (0, 0) */ 1, 0, 0, 1, 0, /* (0, 1) */ 1, 0, 1, 0, 0, /* (0, 0) */
            };

            SensorTestHelper.CompareObservation(sensor, expectedObs);
        }
Пример #7
0
        public void TestVisualObservationsSpecial()
        {
            var boardString =
                @"000
                  000
                  010";
            var specialString =
                @"010
                  200
                  000";

            var gameObj = new GameObject("board");
            var board   = gameObj.AddComponent <StringBoard>();

            board.SetBoard(boardString);
            board.SetSpecial(specialString);

            var sensorComponent = gameObj.AddComponent <Match3SensorComponent>();

            sensorComponent.ObservationType = Match3ObservationType.UncompressedVisual;
            var sensors       = sensorComponent.CreateSensors();
            var cellSensor    = sensors[0];
            var specialSensor = sensors[1];

            {
                var expectedShape = new InplaceArray <int>(3, 3, 2);
                Assert.AreEqual(expectedShape, cellSensor.GetObservationSpec().Shape);

                Assert.AreEqual(SensorCompressionType.None, cellSensor.GetCompressionSpec().SensorCompressionType);

                var expectedObs = new float[]
                {
                    1, 0, /* (0) */ 0, 1, /* (1) */ 1, 0, /* (0) */
                    1, 0, /* (0) */ 1, 0, /* (0) */ 1, 0, /* (0) */
                    1, 0, /* (0) */ 1, 0, /* (0) */ 1, 0, /* (0) */
                };
                SensorTestHelper.CompareObservation(cellSensor, expectedObs);

                var expectedObs3D = new float[, , ]
                {
                    { { 1, 0 }, { 0, 1 }, { 1, 0 } },
                    { { 1, 0 }, { 1, 0 }, { 1, 0 } },
                    { { 1, 0 }, { 1, 0 }, { 1, 0 } },
                };
                SensorTestHelper.CompareObservation(cellSensor, expectedObs3D);
            }
            {
                var expectedShape = new InplaceArray <int>(3, 3, 3);
                Assert.AreEqual(expectedShape, specialSensor.GetObservationSpec().Shape);

                Assert.AreEqual(SensorCompressionType.None, specialSensor.GetCompressionSpec().SensorCompressionType);

                var expectedObs = new float[]
                {
                    1, 0, 0, /* (0) */ 1, 0, 0, /* (1) */ 1, 0, 0, /* (0) */
                    0, 0, 1, /* (2) */ 1, 0, 0, /* (0) */ 1, 0, 0, /* (0) */
                    1, 0, 0, /* (0) */ 0, 1, 0, /* (1) */ 1, 0, 0, /* (0) */
                };
                SensorTestHelper.CompareObservation(specialSensor, expectedObs);

                var expectedObs3D = new float[, , ]
                {
                    { { 1, 0, 0 }, { 1, 0, 0 }, { 1, 0, 0 } },
                    { { 0, 0, 1 }, { 1, 0, 0 }, { 1, 0, 0 } },
                    { { 1, 0, 0 }, { 0, 1, 0 }, { 1, 0, 0 } },
                };
                SensorTestHelper.CompareObservation(specialSensor, expectedObs3D);
            }

            // Test that Dispose() cleans up the component and its sensors
            sensorComponent.Dispose();

            var flags            = BindingFlags.Instance | BindingFlags.NonPublic;
            var componentSensors = (ISensor[])typeof(Match3SensorComponent).GetField("m_Sensors", flags).GetValue(sensorComponent);

            Assert.IsNull(componentSensors);
            var cellTexture = (Texture2D)typeof(Match3Sensor).GetField("m_ObservationTexture", flags).GetValue(cellSensor);

            Assert.IsNull(cellTexture);
            var specialTexture = (Texture2D)typeof(Match3Sensor).GetField("m_ObservationTexture", flags).GetValue(cellSensor);

            Assert.IsNull(specialTexture);
        }