/// <summary> /// Spawns guard at a random guard spawn tile /// </summary> /// <param name="potentialSpawnTiles"></param> /// <param name="gameParams"></param> private void MoveGuardAgents(List <IEnvTile> potentialSpawnTiles, Dictionary <GameParam, int> gameParams) { if (trainingScenario == TrainingScenario.SpyEvade) { if (Guards.Any(guard => guard.CompareTag("alertguard"))) { SwapAgents(); } } if (potentialSpawnTiles.Count < Guards.Count) { throw new MapCreationException("Number of guards has exceeded the number of spawn places"); } var indexes = RandomHelper.GetUniqueRandomList( MaxNumberOfGuards(gameParams[GameParam.GuardAgentCount], gameParams[GameParam.ExitCount]), potentialSpawnTiles.Count); for (var i = 0; i < Guards.Count; i++) { if (trainingScenario != TrainingScenario.GuardAlert) { Guards[i].transform.position = potentialSpawnTiles[indexes[i]].Position; Guards[i].GetComponent <Rigidbody>().velocity = Vector3.zero; } else { var freeTiles = TileDict[TileType.GuardTiles] .Concat(TileDict[TileType.FreeTiles]) .Where(tile => tile.OnPath) .ToList(); var maxNumOfGuard = MaxNumberOfGuards(gameParams[GameParam.GuardAgentCount], gameParams[GameParam.ExitCount]); var agentIndex = RandomHelper.GetUniqueRandomList(maxNumOfGuard, freeTiles.Count); Guards[i].transform.position = freeTiles[agentIndex[i]].Position; Guards[i].GetComponent <Rigidbody>().velocity = Vector3.zero; } } }