// Use this for initialization //FInd agent //Find all of our position transforms void Start() { agent = GetComponent <NavMeshAgent>(); animator = GetComponent <Animator> (); GameObject stairs = GameObject.FindGameObjectWithTag("Stairwell"); stairsTransform = stairs.GetComponent <Transform> (); GameObject cellDoor = GameObject.FindGameObjectWithTag("CellDoor"); cellDoorTransform = cellDoor.GetComponent <Transform> (); GameObject storage = GameObject.FindGameObjectWithTag("Storage"); storageTransform = storage.GetComponent <Transform> (); GameObject bathroom = GameObject.FindGameObjectWithTag("Bathroom"); bathroomTransform = bathroom.GetComponent <Transform> (); GameObject recRoom = GameObject.FindGameObjectWithTag("RecRoom"); recRoomTransform = recRoom.GetComponent <Transform> (); GameObject medRoom = GameObject.FindGameObjectWithTag("MedRoom"); medRoomTransform = medRoom.GetComponent <Transform> (); agentState = AiMode.WaitingToWalk; }
//////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// IEnumerator DieSequence() { //Debug.Log("Ship is dead"); speed = 0; currentAiMode = AiMode.isDead; transform.GetChild(0).transform.GetChild(1).transform.GetComponent <TrailRenderer>().emitting = false; transform.GetChild(0).transform.GetChild(2).transform.gameObject.SetActive(false); transform.GetComponent <SphereCollider>().enabled = false; transform.GetComponent <Rigidbody>().AddExplosionForce(100, transform.position + new Vector3(0, 0, 2), 10); transform.GetComponent <Rigidbody>().useGravity = true; transform.GetComponent <Rigidbody>().angularDrag = 0; transform.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None; yield return(new WaitForSeconds(4)); GameObject newExplosion = Instantiate(GameManager.Instance.explosionShip, transform.position, Quaternion.identity); newExplosion.transform.localScale = new Vector3(4, 4, 4); Destroy(newExplosion, 5f); transform.gameObject.SetActive(false); }
public void changeMode(AiMode nmode, bool silent = false) { if (!silent) { cwrite("Changing AI mode from " + modeCurrent.ToString() + " to: " + nmode.ToString()); } modeCurrent = nmode; switch (modeCurrent) { case AiMode.ANALYTIC: { mainModule = analyticModule; break; } case AiMode.RANDOM: { mainModule = randomModule; break; } case AiMode.BIAS: { mainModule = biasedModule; break; } } }
public void ChangeRobot(NetworkAction action) { JsonData data = JsonMapper.ToObject(action.data); JsonData robotStructure = data["robot"]; Debug.Log("RoboStruct : " + robotStructure.ToString()); if (robotStructure != null) { int newAiMode = Int32.Parse(robotStructure["TOP"].ToString()); switch (newAiMode) { case 0: aiMode = AiMode.Aggressive; break; case 1: aiMode = AiMode.Flanking; break; case 2: aiMode = AiMode.Objective; break; } } }
public TicTacToeGame(IPlayer player1, AiMode aiMode = AiMode.Easy) { GameGrid = new GameGrid(); Player1 = player1; Player2 = new AiPlayer(aiMode, GameGrid); Player1Symbol = (Symbols) new Random().Next(0, 2); Player2Symbol = Player1Symbol == Symbols.O ? Symbols.X : Symbols.O; }
public static IAiStrategy CreateStrategy(AiMode mode, SticksGame game) { return(mode switch { AiMode.Easy => new EasyAiStrategy(game), AiMode.Medium => throw new NotImplementedException(), AiMode.Hard => throw new NotImplementedException(), _ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null) });
public Settings(int numberOfPlayers, int stackSize, int blindSize, string playerName, int maxBetsPerRound, AiMode evalStyle) { NumberOfPlayers = numberOfPlayers; StackSize = stackSize; BlindSize = blindSize; PlayerName = playerName; MaxBetsPerRound = maxBetsPerRound; BetSize = 2 * BlindSize; EvaluationStyle = evalStyle; }
public void InitEquipment(int top, int bottom, int left, int right) { weapon_left = weaponLeft(left); weapon_right = weaponRight(right); aiMode = aiFor(top); /*if (aiMode == AiMode.Aggressive || aiMode == AiMode.Flanking) * { * GetComponent<WatcherRobotMovement>().SetMovementTarget(GameObject.FindGameObjectWithTag("Player").transform); * } */ //movement setupWheels(bottom); }
public Bot(BotConsole c) { this.c = c; isRunning = false; //activeState = State.IDLE; modeCurrent = AiMode.RANDOM; Global.pokedex = new Dictionary <string, Pokemon>(); options = new Dictionary <string, string>(); ReadFile(); Global.setupTypes(); BuildPokedex(); Global.moves = new Dictionary <string, Move>(); movelist = new Movelist(); movelist.initialize(); }
public Bot(Consol c) { this.c = c; isRunning = false; //activeState = State.IDLE; modeCurrent = AiMode.RANDOM; //TODO: set default in config to be read Global.pokedex = new Dictionary<string, Pokemon>(); ReadFile(); Global.setupTypes(); BuildPokedex(); Global.moves = new Dictionary<string,Move>(); movelist = new Movelist(); movelist.initialize(); cwrite("Ready for input!", COLOR_OK); }
//////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// void SelectBehavior() { int randomNumber = Random.Range(0, 2); switch (randomNumber) { case 0: case 1: currentAiMode = AiMode.ChaseEnemy; targetEnemy = GameManager.Instance.SelectTarget(); break; case 2: default: currentAiMode = AiMode.RoamAround; break; } }
public AiPlayer(AiMode aiMode, GameGrid gameGrid) { _gameGrid = gameGrid; _strategy = StrategiesFactory.CreateStrategy(aiMode, gameGrid); Login = $"{aiMode}Robot"; }
// Update is called once per frame void Update() { //Checking the state, and performing certain tasks like Searching, Walking or Moving //Debug.Log ("Current State: " + agentState); //Debug.Log ("Path Status: " + agent.pathStatus); //Debug.Log ("Remaining Distance " + agent.remainingDistance); //Debug.Log ("Stopping Distance" + agent.stoppingDistance); if (agentState == AiMode.Searching) { //Check if path is pending //Check if remaining distance is less than stopping distance //Send Player back to cell //Set Mode to returning playerTransform = playerObject.GetComponent <Transform>(); animator.SetBool("Idle", false); animator.SetBool("Walk", true); agent.SetDestination(playerTransform.position); if (!agent.pathPending) { if (agent.remainingDistance <= agent.stoppingDistance) { if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f) { //Black out Player Screen and Reset SteamVR transform playerTransform.parent.transform.position = new Vector3(16f, 0.5f, -10f); playerInCell = true; playerInMedRoom = playerObject.GetComponent <Player>().playerInMedRoom; playerInStorageRoom = playerObject.GetComponent <Player>().playerInStorageRoom; playerInRecRoom = playerObject.GetComponent <Player>().playerInRecRoom; playerInBathroom = playerObject.GetComponent <Player>().playerInBathroom; playerInMedRoom = false; playerInStorageRoom = false; playerInRecRoom = false; playerInBathroom = false; agentState = AiMode.Returning; } } } } else if (agentState == AiMode.Walking) { //Play Walking Noise (Combine with Animation) //Check if path is pending //Check if remaining distance is less than stopping distance //Check if player is in cell ? WaitingToReturn : Searching animator.SetBool("Idle", false); animator.SetBool("Walk", true); agent.SetDestination(cellDoorTransform.position); if (!agent.pathPending) { if (agent.remainingDistance <= agent.stoppingDistance) { if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f) { playerInCell = playerObject.GetComponent <Player> ().playerInCell; if (playerInCell) { animator.SetBool("Idle", true); animator.SetBool("Walk", false); lastWalkTime = Time.time; agentState = AiMode.WaitingToReturn; } else { animator.SetBool("Idle", false); animator.SetBool("Walk", true); lastWalkTime = Time.time; agentState = AiMode.SearchingStorage; } } } } } else if (agentState == AiMode.Returning) { //Check if path is pending //Check if remaining distance is less than stopping distance //Set Mode to WaitingToWalk animator.SetBool("Idle", false); animator.SetBool("Walk", true); agent.SetDestination(stairsTransform.position); if (!agent.pathPending) { if (agent.remainingDistance <= agent.stoppingDistance) { if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f) { lastWalkTime = Time.time; agentState = AiMode.WaitingToWalk; } } } } else if (agentState == AiMode.WaitingToWalk) { //Wait to start walking again. if (Time.time > lastWalkTime + walkWaitTime) { //Play RETURN TO CELL NOISE agentState = AiMode.Walking; lastWalkTime = Time.time; } return; } else if (agentState == AiMode.WaitingToReturn) { //Wait to return from cell. if (Time.time > lastWalkTime + returnWaitTime) { agentState = AiMode.Returning; lastWalkTime = Time.time; } return; } else if (agentState == AiMode.SearchingStorage) { agent.SetDestination(storageTransform.position); if (!agent.pathPending) { if (agent.remainingDistance <= agent.stoppingDistance) { if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f) { animator.SetBool("Idle", true); animator.SetBool("Walk", false); if (Time.time > lastWalkTime + searchWaitTime) { playerInStorageRoom = playerObject.GetComponent <Player> ().playerInStorageRoom; if (playerInStorageRoom) { animator.SetBool("Idle", false); animator.SetBool("Walk", true); agentState = AiMode.Searching; } else { animator.SetBool("Idle", false); animator.SetBool("Walk", true); agentState = AiMode.SearchingMedRoom; } lastWalkTime = Time.time; } } } } } else if (agentState == AiMode.SearchingMedRoom) { animator.SetBool("Idle", false); animator.SetBool("Walk", true); agent.SetDestination(medRoomTransform.position); if (!agent.pathPending) { if (agent.remainingDistance <= agent.stoppingDistance) { if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f) { animator.SetBool("Idle", true); animator.SetBool("Walk", false); if (Time.time > lastWalkTime + searchWaitTime) { playerInMedRoom = playerObject.GetComponent <Player> ().playerInMedRoom; if (playerInMedRoom) { animator.SetBool("Idle", false); animator.SetBool("Walk", true); agentState = AiMode.Searching; } else { animator.SetBool("Idle", false); animator.SetBool("Walk", true); agentState = AiMode.SearchingRecRoom; } lastWalkTime = Time.time; } } } } } else if (agentState == AiMode.SearchingRecRoom) { animator.SetBool("Idle", false); animator.SetBool("Walk", true); agent.SetDestination(recRoomTransform.position); if (!agent.pathPending) { if (agent.remainingDistance <= agent.stoppingDistance) { if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f) { animator.SetBool("Idle", true); animator.SetBool("Walk", false); if (Time.time > lastWalkTime + searchWaitTime) { playerInRecRoom = playerObject.GetComponent <Player> ().playerInRecRoom; if (playerInRecRoom) { animator.SetBool("Idle", false); animator.SetBool("Walk", true); agentState = AiMode.Searching; } else { animator.SetBool("Idle", false); animator.SetBool("Walk", true); agentState = AiMode.SearchingBathroom; } lastWalkTime = Time.time; } } } } } else if (agentState == AiMode.SearchingBathroom) { animator.SetBool("Idle", false); animator.SetBool("Walk", true); agent.SetDestination(bathroomTransform.position); if (!agent.pathPending) { if (agent.remainingDistance <= agent.stoppingDistance) { if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f) { animator.SetBool("Idle", true); animator.SetBool("Walk", false); if (Time.time > lastWalkTime + searchWaitTime) { playerInBathroom = playerObject.GetComponent <Player> ().playerInBathroom; if (playerInBathroom) { animator.SetBool("Idle", false); animator.SetBool("Walk", true); agentState = AiMode.Searching; } else { animator.SetBool("Idle", false); animator.SetBool("Walk", true); agentState = AiMode.Returning; //Adjust Walk Wait Time to Speed up Enemy's searching } lastWalkTime = Time.time; } } } } } else { return; } }
public AiPlayer(AiMode aiMode, SticksGame game) { _game = game; _strategy = StrategiesFactory.CreateStrategy(aiMode, _game); Login = $"{aiMode}Robot"; }
public void changeMode(AiMode nmode) { cwrite("Changing AI mode from " + modeCurrent.ToString() + " to: " + nmode.ToString()); modeCurrent = nmode; switch (modeCurrent) { case AiMode.ANALYTIC: { mainModule = analyticModule; break; } case AiMode.RANDOM: { mainModule = randomModule; break; } case AiMode.BIAS: { mainModule = biasedModule; break; } } }
//////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// void Update() { if (currentAiMode == AiMode.ChasePlayer) { distanceToTarget = Vector3.Distance(transform.position, GameManager.Instance.playerShip.transform.position); Vector3 targetDir = GameManager.Instance.playerShip.transform.position - transform.position; float angle = Vector3.Angle(targetDir, transform.forward); if (stunCycleTimer < stunTime) // Enemy pilot is stoned { turnInput = 0; } else // Rotate towards player { Vector3 relativePoint = transform.InverseTransformPoint(GameManager.Instance.playerShip.transform.position); if (relativePoint.x < -0.0 && turnInput < 1) // Object is to the left { turnInput -= turnSpeed; } else if (relativePoint.x > 0.0 && turnInput > -1) // Object is to the right { turnInput += turnSpeed; } if (angle < aheadAngle) // Enemy facing player { turnInput = 0; int shootRollDice = Random.Range(0, 100); if (shootRollDice < 5 && distanceToTarget < 300) { Shoot(GameManager.Instance.playerShip); } } } } // Chase Wingman if (currentAiMode == AiMode.ChaseWingman) { if (assignedTargetWingman == null || !assignedTargetWingman.activeSelf) { currentAiMode = AiMode.RoamAround; } distanceToTarget = Vector3.Distance(transform.position, assignedTargetWingman.transform.position); Vector3 targetDir = assignedTargetWingman.transform.position - transform.position; float angle = Vector3.Angle(targetDir, transform.forward); if (stunCycleTimer < stunTime) // Enemy pilot is stoned { turnInput = 0; } else // Rotate towards target { Vector3 relativePoint = transform.InverseTransformPoint(assignedTargetWingman.transform.position); if (relativePoint.x < -0.0 && turnInput < 1) // Object is to the left { turnInput -= turnSpeed; } else if (relativePoint.x > 0.0 && turnInput > -1) // Object is to the right { turnInput += turnSpeed; } if (angle < aheadAngle) // Enemy facing target { turnInput = 0; int shootRollDice = Random.Range(0, 100); if (shootRollDice < 5 && distanceToTarget < 300) { Shoot(assignedTargetWingman); } } } } // Roam Around if (currentAiMode == AiMode.RoamAround) { Vector3 targetDir = randomDestination - transform.position; float angle = Vector3.Angle(targetDir, transform.forward); if (stunCycleTimer < stunTime) // Enemy pilot is stoned { turnInput = 0; } else // Rotate towards target { Vector3 relativePoint = transform.InverseTransformPoint(GameManager.Instance.playerShip.transform.position); if (relativePoint.x < -0.0 && turnInput < 1) // Object is to the left { turnInput -= turnSpeed; } else if (relativePoint.x > 0.0 && turnInput > -1) // Object is to the right { turnInput += turnSpeed; } } if (angle < aheadAngle) // Enemy facing target { turnInput = 0; } } if (currentAiMode == AiMode.isDead) { // Nothing here } // Change speed arbitrarily speedTimer -= 1 * Time.deltaTime; if (speedTimer < 0) { speed = setRandomSpeed(); speedTimer = Random.Range(3, 10); } speed += powerInput; if (speed > maxSpeed) { speed = maxSpeed; } ; if (speed < minSpeed) { speed = minSpeed; } ; // Change stun pause arbitrarily stunCycleTimer -= 1 * Time.deltaTime; if (stunCycleTimer < 0) { stunCycleTimer = Random.Range(stunCycleMinTime, stunCycleMaxTime); randomDestination = setRandomDestination(); //Debug.Log("enemy player stunned for: " + stunCycleTimer.ToString() + " seconds"); } // Die if (healthPoints < 0 && currentAiMode != AiMode.isDead) { StartCoroutine("DieSequence"); } // if (targetPointer.activeSelf) { targetPointer.transform.LookAt(GameManager.Instance.mainCamera.transform); } }