Example #1
0
        public void TestStayOnStage()
        {
            var ai          = new S2AI(2, 1);
            var inp         = new AIInputManager();
            var keepWalking = new KeepWalking(0, inp);

            Strategy[] strategies =
            {
                new StayOnStage(0, inp),
                keepWalking
            };
            var player = new DummyPlayerSnapshotProvider();
            var env    = new AIEnvironment(
                new [] { 0 },
                new DummyGameSnapshotProvider(),
                new DummyStageSnapshotProvider(20),
                new [] { player }
                );

            ai.Ready(env, strategies);
            ai.BeginEvaluate();
            float min = 0, max = 0;

            for (int i = 0; i < 30; i++)
            {
                ai.ExecAndMoveNext();
                if (inp.IsControlActive(Control.Left))
                {
                    player.Move(-1);
                    keepWalking.direction = Control.Left;
                }
                else if (inp.IsControlActive(Control.Right))
                {
                    player.Move(1);
                    keepWalking.direction = Control.Right;
                }
                if (player.x < min)
                {
                    min = player.x;
                }
                if (player.x > max)
                {
                    max = player.x;
                }
                Thread.Sleep(25);
            }
            ai.Dispose();
            Debug.Assert(min <-7f && max> 7f);
        }
Example #2
0
        /// Spawn items when they are due.
        void Update()
        {
            if (!isPlaying)
            {
                return;
            }

            if (Time.time > nextPingUpdateTime)
            {
                nextPingUpdateTime = Time.time + pingUpdateTime;
                pDbgLagField.Set("Ping: " + 0);
            }

            for (int i = 0; i < sPlayerData.Count; i++)
            {
                var data = sPlayerData[i];
                if (data.positionSampler == null)
                {
                    continue;
                }
                data.positionSampler.Run(data.playerGo.transform.position);
            }

            if (!isServer)
            {
                return;
            }

            if (s2ai != null)
            {
                s2ai.ExecAndMoveNext();
            }
            if (itemFrequency != ItemFrequency.None && Time.time > nextItemTime)
            {
                nextItemTime = Time.time + GetNextItemSpawnTime();
                SpawnItem();
            }
        }