Exemplo n.º 1
0
 static void Test2(CharacterInfo characterInfo, NodeWalker walker, Stopwatch timer)
 {
     characterInfo.Input.MoveStick.X   = -0.5f;
     characterInfo.Input.MoveStick.Y   = -0.5f;
     characterInfo.Input.AttackStick.X = 0.0f;
     characterInfo.Input.AttackStick.Y = 0.0f;
     timer.Reset();
     for (int i = 0; i < MAX_TIMES; ++i)
     {
         timer.Start();
         walker.Restart();
         walker.ComputeAllSteps();
         timer.Stop();
     }
     System.Console.WriteLine("Time elapsed : " + timer.Elapsed.TotalMilliseconds / MAX_TIMES);
     System.Console.WriteLine("walker.IsComplete : " + walker.IsComplete);
     System.Console.WriteLine("walker.Outcome : " + walker.Outcome);
     System.Console.WriteLine("IsMoving : " + characterInfo.Current.IsMoving);
     System.Console.WriteLine("IsGuardUp : " + characterInfo.Current.IsGuardUp);
 }
Exemplo n.º 2
0
        public void TestCase()
        {
            const bool EXPECTED = false;

            var board      = new TransistentBlackboard <CharacterInfo>(() => new CharacterInfo());
            var dictionary = new TreeDictionary();
            var builder    = new BlackboardTreeBuilder <Enemy>(new TreeBuilder(), dictionary);
            var plan       = builder
                             .Success();

            var compiled = plan.Build();

            var walker = new NodeWalker(compiled);

            walker.Restart();
            walker.ComputeAllSteps();
            Assert.AreEqual(EXPECTED, board.Context.IsLeader);
            Assert.IsTrue(walker.IsComplete);
            Assert.AreEqual(Result.SUCCESS, walker.Outcome);
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            // build empty tree
            var store = new TreeDictionary();

            var minorBuilder = new BlackboardTreeBuilder <Enemy>(new TreeBuilder(), store);

            // gererate a behavior tree as a stub for later reuse
            minorBuilder
            .Sequence()
            .Begin()
            .Selector()
            .Begin()
            .IsTrue((e) => e.WithinDistance())
            .Step((e) => e.MoveTowards())
            .End()
            .Sequence()
            .Begin()
            .IsTrue((e) => e.WithinDistance())
            .Step((e) => e.HitTarget())
            .End()
            .End()
            .BuildAndRegisterAs <BaseEnemyAI> ();

            var playerOne = new Player {
                HealthPoints = 10, X = 10
            };
            var ogre      = new Enemy();
            var locator   = new MockPlayerLocator(playerOne);
            var situation = new Simulation {
                Individual = ogre, Locator = locator, Current = playerOne
            };

            var upperTree = new BlackboardTreeBuilder <Simulation>(new TreeBuilder(), store);

            upperTree
            .Sequence()
            .Begin()
            .Selector()
            .Begin()
            .IsTrue((e) => e.Individual.HasTarget())
            .Step((e) => {
                bool result = e.Locator.Find(out e.Individual.Target);
                return((result) ? Result.SUCCESS : Result.FAILED);
            }
                  )
            .End()
            .UseStub <BaseEnemyAI, Enemy> ()
            .IsTrue((e) => e.Current.HealthPoints <= 0)
            .End();

            var linker = new BlackboardLinker();

            linker.AddDependency <Simulation, Enemy>((es) => es.Individual);

            var board = new Blackboard <Simulation> {
                Context = situation
            };

            linker.AddParameter <Simulation>(new StaticParameter <Simulation>(board));

            // generate tree as a stub for an BaseEnemyAI implementation
            var finalTree = upperTree.Build();

            var walker = new NodeWalker(finalTree, linker);

            Result outcome = Result.INCOMPLETE;

            while (!(outcome == Result.SUCCESS || outcome == Result.UNEXCEPTED_ERROR))
            {
                walker.Restart();
                walker.ComputeAllSteps();
                outcome = walker.Outcome;
                Console.WriteLine("Ogre X:{0}, Player [HP :{1}] X:{2}", ogre.X, playerOne.HealthPoints, playerOne.X);
            }

            Console.WriteLine("PLAYER IS DEAD");
        }
Exemplo n.º 4
0
		static void Test2 (CharacterInfo characterInfo, NodeWalker walker, Stopwatch timer)
		{
			characterInfo.Input.MoveStick.X = -0.5f;
			characterInfo.Input.MoveStick.Y = -0.5f;
			characterInfo.Input.AttackStick.X = 0.0f;
			characterInfo.Input.AttackStick.Y = 0.0f;
			timer.Reset ();
			for (int i = 0; i < MAX_TIMES; ++i)
			{
				timer.Start ();
				walker.Restart ();
				walker.ComputeAllSteps ();
				timer.Stop ();
			}
			System.Console.WriteLine ("Time elapsed : " + timer.Elapsed.TotalMilliseconds / MAX_TIMES);
			System.Console.WriteLine ("walker.IsComplete : " + walker.IsComplete);
			System.Console.WriteLine ("walker.Outcome : " + walker.Outcome);
			System.Console.WriteLine ("IsMoving : " + characterInfo.Current.IsMoving);
			System.Console.WriteLine ("IsGuardUp : " + characterInfo.Current.IsGuardUp);
		}