コード例 #1
0
		/// <summary>
		/// Dot between this and another specified vector. (based on normalized vectors)
		/// </summary>
		/// <param name="vector">Vector.</param>
		public float dot(UtilityVector vector){
			if (this.magnitude == 0 || vector.magnitude == 0)
				return -2;

			UtilityVector a = this.normalize ();
			UtilityVector b = vector.normalize ();

			float val = 0;

			for (int i = 0; i < this.values.Length; i++)
				val += a.values [i] * b.values [i];

			return val;
		}
コード例 #2
0
		/// <summary>
		/// Return a new vector based on the normalization of this instance.
		/// </summary>
		public UtilityVector normalize(){
			if (this.values.Length <= 0)
				return null;

			UtilityVector vec = new UtilityVector();
			vec.values = new float[this.values.Length];
			this.values.CopyTo (vec.values, 0);

			float mag = vec.magnitude;

			for (int i = 0; i < vec.values.Length; i++)
				vec.values [i] = vec.values [i] / mag;

			return vec;
		}
コード例 #3
0
        /// <summary>
        /// Dot between this and another specified vector. (based on normalized vectors)
        /// </summary>
        /// <param name="vector">Vector.</param>
        public float dot(UtilityVector vector)
        {
            if (this.magnitude == 0 || vector.magnitude == 0)
            {
                return(-2);
            }

            UtilityVector a = this.normalize();
            UtilityVector b = vector.normalize();

            float val = 0;

            for (int i = 0; i < this.values.Length; i++)
            {
                val += a.values [i] * b.values [i];
            }

            return(val);
        }
コード例 #4
0
        /// <summary>
        /// Return a new vector based on the normalization of this instance.
        /// </summary>
        public UtilityVector normalize()
        {
            if (this.values.Length <= 0)
            {
                return(null);
            }

            UtilityVector vec = new UtilityVector();

            vec.values = new float[this.values.Length];
            this.values.CopyTo(vec.values, 0);

            float mag = vec.magnitude;

            for (int i = 0; i < vec.values.Length; i++)
            {
                vec.values [i] = vec.values [i] / mag;
            }

            return(vec);
        }
コード例 #5
0
        public override BehaviorReturnCode Behave()
        {
            try{
                UtilityVector func_vector = this._utility_function.Invoke();

                float       min        = -2.0f;
                UtilityPair best_match = null;

                //find max pair match
                foreach (UtilityPair pair in this._utility_pairs)
                {
                    float val = func_vector.dot(pair.vector);
                    if (val > min)
                    {
                        min        = val;
                        best_match = pair;
                    }
                }

                //make sure we found a match
                if (best_match == null)
                {
                                        #if DEBUG
                    Console.WriteLine("best_match not defined...");
                                        #endif
                    this.ReturnCode = BehaviorReturnCode.Failure;
                    return(this.ReturnCode);
                }

                //execute best pair match and return result
                this.ReturnCode = best_match.behavior.Behave();
                return(this.ReturnCode);
            }catch (Exception e) {
                                #if DEBUG
                Console.WriteLine(e.ToString());
                                #endif
                ReturnCode = BehaviorReturnCode.Failure;
                return(BehaviorReturnCode.Failure);
            }
        }
コード例 #6
0
 public UtilityPair(UtilityVector vector, BehaviorComponent behavior)
 {
     this.vector   = vector;
     this.behavior = behavior;
 }
コード例 #7
0
        public UtilityPair(UtilityVector vector, BehaviorComponent behavior)
        {
			this.vector = vector;
			this.behavior = behavior;
        }