Beispiel #1
0
        public BotMove PerformNextMove(SurroundingAreaInfo arenaInfo)
        {
            var nextMove = EnumValueHelper <AvailableActions> .RandomEnumValue();

            var result = new BotMove();

            result.Action = nextMove;
            switch (nextMove)
            {
            case AvailableActions.FireMissile:
            case AvailableActions.Move:
            {
                result.ActionDirection = EnumValueHelper <ActionDirections> .RandomEnumValue();

                break;
            }

            case AvailableActions.Watch:
            {
                result.ActionDirection = null;
                break;
            }
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Removes an enumerated type and returns the new value
        /// </summary>
        public static T Remove <T>(this Enum value, T remove)
        {
            var type = value.GetType();

            // determine the values
            object result = value;
            var    parsed = new EnumValueHelper(remove, type);

            if (parsed.Signed is long)
            {
                result = Convert.ToInt64(value) & ~(long)parsed.Signed;
            }
            else if (parsed.Unsigned is ulong)
            {
                result = Convert.ToUInt64(value) & ~(ulong)parsed.Unsigned;
            }

            // return the final value
            return((T)Enum.Parse(type, result.ToString(), true));
        }
Beispiel #3
0
        /// <summary>
        /// Checks if an enumerated type contains a value
        /// </summary>
        public static bool Has <T>(this Enum value, T check)
        {
            var type = value.GetType();

            // determine the values
            object result = value;
            var    parsed = new EnumValueHelper(check, type);

            if (parsed.Signed is long)
            {
                return((Convert.ToInt64(value) & (long)parsed.Signed) == parsed.Signed);
            }

            if (parsed.Unsigned is ulong)
            {
                return((Convert.ToUInt64(value) &
                        (ulong)parsed.Unsigned) == parsed.Unsigned);
            }

            return(false);
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        public static object NextEnum(
            this Random random,
            Type enumType)
        {
            Error.ThrowIfArgumentNull(nameof(random), random);
            Error.ThrowIfArgumentNull(nameof(enumType), enumType);
            Error.ThrowIfTypeIsNotEnum(nameof(enumType), enumType);
            var typeCode = Type.GetTypeCode(enumType.GetEnumUnderlyingType());
            var values   = EnumValueHelper.GetValues(enumType);

            if (typeCode == TypeCode.UInt32 ||
                typeCode == TypeCode.Int64 ||
                typeCode == TypeCode.UInt64)
            {
                return(values.GetValue(random.NextInt64(values.LongLength)));
            }
            else
            {
                return(values.GetValue(random.Next(values.Length)));
            }
        }