Beispiel #1
0
    public int Write(ObservationWriter writer)
    {
        BoardState state  = board.GetCurrentBoardState();
        int        offset = 0;

        foreach (Index index in Index.GetAllIndices())
        {
            if (state.TryGetPiece(index, out (Team team, Piece piece)teamedPiece))
            {
                Piece realPiece = board.currentGame.GetRealPiece(teamedPiece);

                writer.Add(new Vector3(
                               (float)teamedPiece.team,
                               ((float)realPiece) + 1f,
                               index.GetSingleVal()
                               ), offset);
            }
            else
            {
                writer.Add(new Vector3(0, 0, index.GetSingleVal()), offset);
            }

            offset += 3;
        }

        return(offset);
    }
Beispiel #2
0
        /// <summary>
        /// Utility method for writing a PoseExtractor to an ObservationWriter.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="settings"></param>
        /// <param name="poseExtractor"></param>
        /// <param name="baseOffset">The offset into the ObservationWriter to start writing at.</param>
        /// <returns>The number of observations written.</returns>
        public static int WritePoses(this ObservationWriter writer, PhysicsSensorSettings settings, PoseExtractor poseExtractor, int baseOffset = 0)
        {
            var offset = baseOffset;

            if (settings.UseModelSpace)
            {
                foreach (var pose in poseExtractor.GetEnabledModelSpacePoses())
                {
                    if (settings.UseModelSpaceTranslations)
                    {
                        writer.Add(pose.position, offset);
                        offset += 3;
                    }

                    if (settings.UseModelSpaceRotations)
                    {
                        writer.Add(pose.rotation, offset);
                        offset += 4;
                    }
                }

                foreach (var vel in poseExtractor.GetEnabledModelSpaceVelocities())
                {
                    if (settings.UseModelSpaceLinearVelocity)
                    {
                        writer.Add(vel, offset);
                        offset += 3;
                    }
                }
            }

            if (settings.UseLocalSpace)
            {
                foreach (var pose in poseExtractor.GetEnabledLocalSpacePoses())
                {
                    if (settings.UseLocalSpaceTranslations)
                    {
                        writer.Add(pose.position, offset);
                        offset += 3;
                    }

                    if (settings.UseLocalSpaceRotations)
                    {
                        writer.Add(pose.rotation, offset);
                        offset += 4;
                    }
                }

                foreach (var vel in poseExtractor.GetEnabledLocalSpaceVelocities())
                {
                    if (settings.UseLocalSpaceLinearVelocity)
                    {
                        writer.Add(vel, offset);
                        offset += 3;
                    }
                }
            }

            return(offset - baseOffset);
        }
        /// <summary>
        /// Utility method for writing a PoseExtractor to an ObservationWriter.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="settings"></param>
        /// <param name="poseExtractor"></param>
        /// <param name="baseOffset">The offset into the ObservationWriter to start writing at.</param>
        /// <returns>The number of observations written.</returns>
        public static int WritePoses(this ObservationWriter writer, PhysicsSensorSettings settings, PoseExtractor poseExtractor, int baseOffset = 0)
        {
            var offset = baseOffset;

            if (settings.UseModelSpace)
            {
                var poses = poseExtractor.ModelSpacePoses;
                var vels  = poseExtractor.ModelSpaceVelocities;

                for (var i = 0; i < poseExtractor.NumPoses; i++)
                {
                    var pose = poses[i];
                    if (settings.UseModelSpaceTranslations)
                    {
                        writer.Add(pose.position, offset);
                        offset += 3;
                    }
                    if (settings.UseModelSpaceRotations)
                    {
                        writer.Add(pose.rotation, offset);
                        offset += 4;
                    }
                    if (settings.UseModelSpaceLinearVelocity)
                    {
                        writer.Add(vels[i], offset);
                        offset += 3;
                    }
                }
            }

            if (settings.UseLocalSpace)
            {
                var poses = poseExtractor.LocalSpacePoses;
                var vels  = poseExtractor.LocalSpaceVelocities;

                for (var i = 0; i < poseExtractor.NumPoses; i++)
                {
                    var pose = poses[i];
                    if (settings.UseLocalSpaceTranslations)
                    {
                        writer.Add(pose.position, offset);
                        offset += 3;
                    }
                    if (settings.UseLocalSpaceRotations)
                    {
                        writer.Add(pose.rotation, offset);
                        offset += 4;
                    }
                    if (settings.UseLocalSpaceLinearVelocity)
                    {
                        writer.Add(vels[i], offset);
                        offset += 3;
                    }
                }
            }

            return(offset - baseOffset);
        }
Beispiel #4
0
        internal override void WriteReflectedField(ObservationWriter writer)
        {
            var vecVal = (UnityEngine.Vector4)GetReflectedValue();

            writer.Add(vecVal);
        }
        internal override void WriteReflectedField(ObservationWriter writer)
        {
            var quatVal = (UnityEngine.Quaternion)GetReflectedValue();

            writer.Add(quatVal);
        }