示例#1
0
        public void selector_1()
        {
            _log.enterScope();

            UtilityVector   vector = new UtilityVector(0, 1, 0, 2);
            BehaviorAction  action = new BehaviorAction(delegate() { return(BehaviorReturnCode.Success); });
            UtilityPair     pair   = new UtilityPair(vector, action);
            UtilitySelector sel    = new UtilitySelector(delegate(){ return(new UtilityVector(0, 1, 1, 2)); }, pair, pair);

            BehaviorReturnCode result = sel.Behave();

            Verify.VerifyNotEquals("basic vector compare", true, result, BehaviorReturnCode.Failure);

            _log.exitScope();
        }
示例#2
0
		public void selector_1()
        {
            _log.enterScope();

            UtilityVector vector = new UtilityVector(0, 1, 0, 2);
            BehaviorAction action = new BehaviorAction(delegate() { return BehaviorReturnCode.Success; });
            UtilityPair pair = new UtilityPair(vector, action);
			UtilitySelector sel = new UtilitySelector(delegate(){return new UtilityVector(0,1,1,2);},pair,pair);

			BehaviorReturnCode result = sel.Behave();

			Verify.VerifyNotEquals("basic vector compare", true, result, BehaviorReturnCode.Failure);

            _log.exitScope();
        }
示例#3
0
		public void selector_3(){
			_log.enterScope();

			//build vectors
			UtilityVector a = new UtilityVector(0, 1, 0, 1);
			UtilityVector b = new UtilityVector(1, 1, 0, 0);
			UtilityVector c = new UtilityVector(1, 0, 1, 0);
			UtilityVector d = new UtilityVector(0, 0, 1, 1);

			string choice = "";

			//build actions that change choice if called
			BehaviorAction aa = new BehaviorAction (delegate() {
				choice = "a";
				return BehaviorReturnCode.Success;
			});
			BehaviorAction ba = new BehaviorAction (delegate() {
				choice = "b";
				return BehaviorReturnCode.Success;
			});
			BehaviorAction ca = new BehaviorAction (delegate() {
				choice = "c";
				return BehaviorReturnCode.Success;
			});
			BehaviorAction da = new BehaviorAction (delegate() {
				choice = "d";
				return BehaviorReturnCode.Success;
			});

			//build the appropraite pairs
			UtilityPair ap = new UtilityPair (a, aa);
			UtilityPair bp = new UtilityPair (b, ba);
			UtilityPair cp = new UtilityPair (c, ca);
			UtilityPair dp = new UtilityPair (d, da);


			//execute tests
			UtilitySelector sel = new UtilitySelector (delegate() {
				return new UtilityVector (0.5f,0.7f,0.4f,0.8f);
			}, ap, bp, cp, dp);

			sel.Behave ();

			Verify.VerifyTrue ("a chosen", true, choice == "a");

			sel = new UtilitySelector (delegate() {
				return new UtilityVector (0.7f,0.8f,0.5f,0.4f);
			}, ap, bp, cp, dp);

			sel.Behave ();

			Verify.VerifyTrue ("b chosen", true, choice == "b");

			sel = new UtilitySelector (delegate() {
				return new UtilityVector (0.7f,0.5f,0.8f,0.4f);
			}, ap, bp, cp, dp);

			sel.Behave ();

			Verify.VerifyTrue ("c chosen", true, choice == "c");

			sel = new UtilitySelector (delegate() {
				return new UtilityVector (0.5f,0.4f,0.7f,0.8f);
			}, ap, bp, cp, dp);

			sel.Behave ();

			Verify.VerifyTrue ("d chosen", true, choice == "d");


			_log.exitScope ();
		}
示例#4
0
        public void selector_3()
        {
            _log.enterScope();

            //build vectors
            UtilityVector a = new UtilityVector(0, 1, 0, 1);
            UtilityVector b = new UtilityVector(1, 1, 0, 0);
            UtilityVector c = new UtilityVector(1, 0, 1, 0);
            UtilityVector d = new UtilityVector(0, 0, 1, 1);

            string choice = "";

            //build actions that change choice if called
            BehaviorAction aa = new BehaviorAction(delegate() {
                choice = "a";
                return(BehaviorReturnCode.Success);
            });
            BehaviorAction ba = new BehaviorAction(delegate() {
                choice = "b";
                return(BehaviorReturnCode.Success);
            });
            BehaviorAction ca = new BehaviorAction(delegate() {
                choice = "c";
                return(BehaviorReturnCode.Success);
            });
            BehaviorAction da = new BehaviorAction(delegate() {
                choice = "d";
                return(BehaviorReturnCode.Success);
            });

            //build the appropraite pairs
            UtilityPair ap = new UtilityPair(a, aa);
            UtilityPair bp = new UtilityPair(b, ba);
            UtilityPair cp = new UtilityPair(c, ca);
            UtilityPair dp = new UtilityPair(d, da);


            //execute tests
            UtilitySelector sel = new UtilitySelector(delegate() {
                return(new UtilityVector(0.5f, 0.7f, 0.4f, 0.8f));
            }, ap, bp, cp, dp);

            sel.Behave();

            Verify.VerifyTrue("a chosen", true, choice == "a");

            sel = new UtilitySelector(delegate() {
                return(new UtilityVector(0.7f, 0.8f, 0.5f, 0.4f));
            }, ap, bp, cp, dp);

            sel.Behave();

            Verify.VerifyTrue("b chosen", true, choice == "b");

            sel = new UtilitySelector(delegate() {
                return(new UtilityVector(0.7f, 0.5f, 0.8f, 0.4f));
            }, ap, bp, cp, dp);

            sel.Behave();

            Verify.VerifyTrue("c chosen", true, choice == "c");

            sel = new UtilitySelector(delegate() {
                return(new UtilityVector(0.5f, 0.4f, 0.7f, 0.8f));
            }, ap, bp, cp, dp);

            sel.Behave();

            Verify.VerifyTrue("d chosen", true, choice == "d");


            _log.exitScope();
        }
示例#5
0
        protected override void OnUpdate()
        {
            base.OnUpdate();

            Tank oppTank = Match.instance.GetOppositeTank(Team);

            if (oppTank != null && oppTank.IsDead == false)
            {
                TurretTurnTo(oppTank.Position);
            }
            else
            {
                TurretTurnTo(Position + Forward);
            }
            EAction action = (EAction)UtilitySelector.Select(this, m_MaxSelector, m_Fire, m_GetStar, m_BackToHome);

            switch (action)
            {
            case EAction.Fire:
                Fire();
                break;

            case EAction.BackToHome:
                Move(Match.instance.GetRebornPos(Team));
                break;

            case EAction.GetStar:
                bool    hasStar        = false;
                float   nearestDist    = float.MaxValue;
                Vector3 nearestStarPos = Vector3.zero;
                foreach (var pair in Match.instance.GetStars())
                {
                    Star s = pair.Value;
                    if (s.IsSuperStar)
                    {
                        hasStar        = true;
                        nearestStarPos = s.Position;
                        break;
                    }
                    else
                    {
                        float dist = (s.Position - Position).sqrMagnitude;
                        if (dist < nearestDist)
                        {
                            hasStar        = true;
                            nearestDist    = dist;
                            nearestStarPos = s.Position;
                        }
                    }
                }
                if (hasStar == true)
                {
                    Move(nearestStarPos);
                }
                break;

            default:
                if (Time.time > m_LastTime && ApproachNextDestination())
                {
                    m_LastTime = Time.time + Random.Range(3, 8);
                }
                break;
            }
        }