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); }
/// Initialize fields that other objects depend on. void Awake() { stateChangeListenerFactory = new StateChangeListenerFactory(); #if UNITY_EDITOR playDataLogger = new PlayDataLogger(Application.streamingAssetsPath + "/pdl.txt"); stateChangeListenerFactory.Add(playDataLogger); #endif sPlayerData = new List <ServerPlayerData>(); Layers.Init(); PlayersInitialized += players => { var aiStrategies = new List <Strategy>(); var aiPlayerIds = new List <int>(); FindObjectOfType <EnableUI>().Enable(); foreach (var player in players) { IInputManager playerInputManager; if (isClient && player.eId == cPlayerId) { playerInputManager = GetComponent <InputManager>(); } else if (isServer && sPlayerData[player.eId].aiLevel > 0) { var aiim = new AIInputManager(); // TODO: Redo this function for S2AI. AddAI(player.gameObject, aiim, sPlayerData[player.eId].aiLevel); playerInputManager = aiim; if (sPlayerData[player.eId].aiLevel == 3) { var aiCount = aiPlayerIds.Count; var set = StrategySets.GetStandardSet(aiCount, aiim); aiStrategies.AddRange(set); aiPlayerIds.Add(player.eId); } } else { playerInputManager = NullInputManager.Instance; } player.GameControllerReady(this, playerInputManager); } if (s2ai != null) { var env = new AIEnvironment(aiPlayerIds, this, this, players); s2ai.Ready(env, aiStrategies); } }; GameStarted += () => { foreach (var data in sPlayerData) { var player = data.player; player.RemoveModifier(ModId.CantAttack); player.RemoveModifier(ModId.CantMove); if (player.isLocalPlayer) { FindObjectOfType <CameraScroll>().playerToFollow = player; } } if (s2ai != null) { s2ai.BeginEvaluate(); } }; if (TransitionParams.gameType == GameType.Single) { spawnPrefabList = new JitList <GameObject>(); } else { spawnPrefabList = NetworkManager.singleton.spawnPrefabs; } gameObjectPool = new GameObjectPool(); Instance = this; }