// Update is called once per frame void Update() { instantiationTimer -= Time.deltaTime; //controller.GetComponent<Controller>().getNumPlanesOfLvl(3) < 12 if (instantiationTimer <= 0 && controller.GetComponent <Controller>().getFlyingPlanes() < 10) { createPlane(); instantiationTimer = RandomFromDistribution.RandomRangeExponential(5, 8, 2, direction); } }
private Vector2 RandomCirclePosition() { //calculate random offset form orbit //float offset = Random.Range(-orbitOffset, orbitOffset); float offset = RandomFromDistribution.RandomNormalDistribution(0, orbitOffset); float orbit = rotationRadius + offset; float randomAngle = Random.Range(0f, 360f); float posX = center.position.x + Mathf.Cos(randomAngle * Mathf.Deg2Rad) * orbit; float posY = center.position.y + Mathf.Sin(randomAngle * Mathf.Deg2Rad) * orbit; return(new Vector2(posX, posY)); }
//How long it took for Action() to be completed //Action() must first be completed, otherwise an exception will be thrown public int TimeTaken() { if (!actionCompleted) { throw new System.Exception(actionCalled ? "Although Action() has been called, it has not been completed" : "Action() must first be completed"); } float variation = RandomFromDistribution.RandomRangeNormalDistribution( -3 * ExpectedTimeStdDev, 3 * ExpectedTimeStdDev, RandomFromDistribution.ConfidenceLevel_e._998); return(ExpectedTime + (int)variation); }
void generateMaze(float x_min, float x_max, float y_min, float y_max, int lastRandom) { float x_length = x_max - x_min; float y_length = y_max - y_min; if (x_length <= 1 || y_length <= 1) // return if the area is too small to create a new wall. { return; } else { int random1; // 0 = horizontal wall. 1 = vertical wall. Value alternates on recursive calls. if (lastRandom == 0) { random1 = 1; } else if (lastRandom > 0) { random1 = 0; } else { random1 = (int)(Random.value * 2); // 0 or 1. } float random2; if (random1 == 0) // horizontal wall // random using normal distribution makes it more likely that the wall will be placed near the center of the given area. { random2 = (float)((int)(RandomFromDistribution.RandomRangeNormalDistribution(y_min + 1, y_min + y_length - 1, RandomFromDistribution.ConfidenceLevel_e._95))); float x_center = (x_min + x_max) / 2; // x coordinate of the center of the area createWallHorizontal(x_length, x_center, random2); // create wall // recursively call function for the area on either side of the newly created wall generateMaze(x_min, x_max, y_min, random2, random1); generateMaze(x_min, x_max, random2, y_max, random1); } else // vertical wall // random using normal distribution makes it more likely that the wall will be placed near the center of the given area. { random2 = (float)((int)(RandomFromDistribution.RandomRangeNormalDistribution(x_min + 1, x_min + x_length - 1, RandomFromDistribution.ConfidenceLevel_e._95))); float y_center = (y_min + y_max) / 2; // y coordinate of the center of the area createWallVertical(y_length, random2, y_center); // create wall // recursively call function for the area on either side of the newly created wall generateMaze(x_min, random2, y_min, y_max, random1); generateMaze(random2, x_max, y_min, y_max, random1); } } return; }
// Update is called once per frame void Update() { if (player.transform.position.z < 0 & numTraversalsLocal != sp.numTraversals) { numTraversalsLocal++; if (numTraversalsLocal >= (numBaselineTrials + numTrainingTrials)) { if (nextMorphTrial < 0) { nextMorphTrial = numTraversalsLocal + (int)RandomFromDistribution.RandomRangeExponential(0f, 8f, morphExp, RandomFromDistribution.Direction_e.Right); } if (numTraversalsLocal == nextMorphTrial) { nextMorphTrial = -1; sp.morph = morphTrials[morphCounter]; morphCounter++; } else { sp.morph = NextTrial(); trialHistory.Add(sp.morph); } } else if (numTraversalsLocal >= numBaselineTrials) { sp.morph = NextTrial(); trialHistory.Add(sp.morph); } else { sp.morph = baselineTrials[numTraversalsLocal]; } if (UnityEngine.Random.value < .5) { sp.BlockWalls = true; } else { sp.BlockWalls = false; } if (trialHistory.Count > 40) { trialHistory.RemoveAt(0); } } }
private void CreateSprayRotation(float sprayMultiplier) { Vector2 dirDiflection = UnityEngine.Random.insideUnitCircle; Vector3 dirDisplacementVector = new Vector3(dirDiflection.x, dirDiflection.y, 0); var randomMultiplier = RandomFromDistribution.RandomFromStandardNormalDistribution(); //we use standardDistribution to simulate real-shooting var absInputMultyplier = (Mathf.Abs(playerInput.Hinput) + 1) * (Mathf.Abs(playerInput.Vinput) + 1); absInputMultyplier = Mathf.Clamp(absInputMultyplier, absInputMultyplier, 2); //clamp input to make spray independent from moving direction dirDisplacementVector *= randomMultiplier * absInputMultyplier * sprayMultiplier; shootingPoint.transform.Rotate(dirDisplacementVector.x, dirDisplacementVector.y, 0); //take current rotation and change it based on offset vec }
// Update is called once per frame void Update() { if (currNumMonsters < maxNumMonsters) { int index = RandomFromDistribution.RandomChoiceFollowingDistribution(frequencies); GameObject monster = Instantiate(monsters[index]) as GameObject; currNumMonsters++; // Randomize position float x = RandomFromDistribution.RandomRangeNormalDistribution(-5, 5, RandomFromDistribution.ConfidenceLevel_e._90); float y = RandomFromDistribution.RandomRangeNormalDistribution(-5, 5, RandomFromDistribution.ConfidenceLevel_e._90); monster.transform.position = new Vector3(x, y, 0); } }
void Awake() { clouds = new SpriteRenderer[numberOfClouds]; speeds = new float[numberOfClouds]; int cloudMaxIndex = cloudSprites.Length - 1; int index; Vector3 position; for (int i = 0; i < numberOfClouds; i++) { index = Random.Range(0, cloudMaxIndex); position = new Vector3(Random.Range(-1.0f * xLimit, xLimit), RandomFromDistribution.RandomNormalDistribution(yLimit, yLimit / spread), 0.0f); clouds[i] = Instantiate(cloudSprites[index], position, Quaternion.identity); speeds[i] = Random.Range(-10.0f, 10.0f); } }
Vector2Int ChooseWayPoint(FieldTile[,] map, Vector2Int from) { GameObject[] anotherPlayers = GameObject.FindGameObjectsWithTag("Player"); float[,] cellsGoodness = new float[map.GetLength(0), map.GetLength(1)]; float sum = 0; for (int i = 1; i < map.GetLength(0) - 1; i++) { for (int g = 1; g < map.GetLength(1) - 1; g++) { cellsGoodness[i, g] = cellGoodNess(map[i, g]); cellsGoodness[i, g] += cellGoodNess(map[i - 1, g - 1]); cellsGoodness[i, g] += cellGoodNess(map[i - 1, g]); cellsGoodness[i, g] += cellGoodNess(map[i - 1, g + 1]); cellsGoodness[i, g] += cellGoodNess(map[i, g - 1]); cellsGoodness[i, g] += cellGoodNess(map[i, g + 1]); cellsGoodness[i, g] += cellGoodNess(map[i + 1, g - 1]); cellsGoodness[i, g] += cellGoodNess(map[i + 1, g]); cellsGoodness[i, g] += cellGoodNess(map[i + 1, g + 1]); if (Math.Abs(from.x - i) > 0.01f && Math.Abs(from.y - g) > 0.01f) { cellsGoodness[i, g] /= Vector2.Distance(from, new Vector2(i, g)); } sum += cellsGoodness[i, g]; } } List <float> probabilities = new List <float>(map.GetLength(0) * map.GetLength(1)); for (int i = 0; i < map.GetLength(0); i++) { for (int g = 0; g < map.GetLength(1); g++) { cellsGoodness[i, g] /= sum; probabilities.Add(cellsGoodness[i, g]); } } int result = RandomFromDistribution.RandomChoiceFollowingDistribution(probabilities); return(new Vector2Int(result % cellsGoodness.GetLength(0), result / cellsGoodness.GetLength(0))); }
//connect the points to form roads, and store the neighbours List <Vector3> returnNeighbours(Vector3 point) { //returns neighours of the given point List <Vector3> neighbours = new List <Vector3> (); for (int i = 0; i < vertices.Count; i++) { float distance = (point - vertices[i]).magnitude; mean = 6f; std_dev = 2f; //generate a number from the random distribution with mean and std deviation and use that as a metric to decide float radius = RandomFromDistribution.RandomNormalDistribution(mean, std_dev); Console.WriteLine(distance); if (distance < radius) { neighbours.Add(vertices[i]); } } return(neighbours); }
IEnumerator landRoutine() { if (!collision && !fuelEnd) { gameObject.transform.GetChild(0).GetComponent <SpriteRenderer>().sprite = planeLanding; } console.text = "Preparing Landing" + "\n"; yield return(new WaitForSeconds(RandomFromDistribution.RandomRangeNormalDistribution(1, 3, conf_level))); console.text = console.text + "\n" + "Seatbells - CHECK"; yield return(new WaitForSeconds(RandomFromDistribution.RandomRangeNormalDistribution(1, 3, conf_level))); console.text = console.text + "\n" + "Security - CHECK"; yield return(new WaitForSeconds(RandomFromDistribution.RandomRangeNormalDistribution(1, 3, conf_level))); console.text = console.text + "\n" + "Spoilers - CHECK"; yield return(new WaitForSeconds(RandomFromDistribution.RandomRangeNormalDistribution(1, 3, conf_level))); console.text = console.text + "\n" + "Wheels - CHECK" + "\n"; console.text = console.text + "\n" + "Start Landing"; StartCoroutine(MoveToPosition(new Vector3(0, 0, 0), 5.0f)); }
void CreateCells() { RandomFromDistribution.ConfidenceLevel_e conf_level = RandomFromDistribution.ConfidenceLevel_e._80; int numberOfCells = levelStats.numberOfCells; float roomCircleRadius = levelStats.roomCircleRadius; percFromGraphToPaths = levelStats.percFromGraphToPaths; mainRoomMeanCutoff = levelStats.mainRoomCutoff; float cellMinWidth = levelStats.cellMinWidth; float cellMaxWidth = levelStats.cellMaxWidth; float cellMinHeight = levelStats.cellMinHeight; float cellMaxHeight = levelStats.cellMaxHeight; for (int i = 0; i < numberOfCells; i++) { float minWidthScalar = cellMinWidth; float maxWidthScalar = cellMaxWidth; float minHeightScalar = cellMinHeight; float maxHeightScalar = cellMaxHeight; GeneratorCell cell = new GeneratorCell(); cell.width = Mathf.RoundToInt(RandomFromDistribution.RandomRangeNormalDistribution(minWidthScalar, maxWidthScalar, conf_level)); cell.height = Mathf.RoundToInt(RandomFromDistribution.RandomRangeNormalDistribution(minHeightScalar, maxHeightScalar, conf_level)); Vector2 pos = GetRandomPointInCirlce(roomCircleRadius); cell.posX = Mathf.RoundToInt(pos.x); cell.posY = Mathf.RoundToInt(pos.y); cell.index = i; cells.Add(cell); widthAvg += cell.width; heightAvg += cell.height; } widthAvg /= cells.Count; heightAvg /= cells.Count; }
private void SpawnAsteroids() { deleted = 0; int spawned = 0; errorCounter = 0; while (errorCounter < 10000 && spawned <= numOfAsteroids) { //Choose a random asteroid from list GameObject rndAsteroid = asteroids[Random.Range((int)0, (int)asteroids.Count)]; Vector2 pos = RandomCirclePosition(); GameObject newAsteroid = Instantiate(rndAsteroid, pos, Quaternion.identity); float scale = RandomFromDistribution.RandomNormalDistribution(averageScale, stdDeviation); if (scale < minScale) { scale = minScale; } if (scale > maxScale) { scale = maxScale; } newAsteroid.transform.localScale = new Vector3(scale, scale, 1); Collider2D[] contacts = new Collider2D[1]; if (Physics2D.OverlapBoxAll(pos, newAsteroid.transform.localScale * 5f, 0).Length > 1) { DestroyImmediate(newAsteroid); deleted++; } else { newAsteroid.transform.parent = transform; newAsteroid.transform.rotation = quaternion.Euler(0, 0, Random.Range(0f, 360f)); spawned++; } errorCounter++; } }
//Generats a level public void GenerateLevel() { DestroyAllChildren(); SetupGeneration(); //Reset "last parent" to the level generator so offsetting is reset lastParent = gameObject.transform; //Column Placement var numRows = 100; int tillNextToggle = 0; int generationType = 0; for (int rowPlacement = 0; rowPlacement < numRows; rowPlacement++) { --tillNextToggle; if (tillNextToggle <= 0) { tillNextToggle = RandomFromDistribution.RandomChoiceFollowingDistribution(prob_repeatRowType) + 1; var potentialGenType = RandomFromDistribution.RandomChoiceFollowingDistribution(generationProbabilityTable.Values.ToList()); if (potentialGenType == generationType) { generationType = (generationType + 1) % generationProbabilityTable.Keys.Count; } else { generationType = potentialGenType; } } generationProbabilityTable.Keys.ToList()[generationType](); } }
// Update is called once per frame void Update() { if (Time.time >= nextSpawnTime) { float secondsBetweenSpawn = Mathf.Lerp(secondsBetweenSpawnMinMax.y, secondsBetweenSpawnMinMax.x, DifficultyManager.getCurrentDifficulty()); float spawnSize = Random.Range(spawnSizeMinMax.x, spawnSizeMinMax.y); float spawnAngle = Random.Range(-spawnAngleMax, spawnAngleMax); Vector2 spawnPosition = new Vector2(Random.Range(-screenHalfSize.x, screenHalfSize.x), screenHalfSize.y + spawnSize * fallingRockPrefab.transform.localScale.y); GameObject newRock = (GameObject)Instantiate(fallingRockPrefab, spawnPosition, Quaternion.Euler(Vector3.forward * spawnAngle)); newRock.transform.localScale = Vector2.one * spawnSize; nextSpawnTime = Time.time + secondsBetweenSpawn; } if (Time.time >= nextPowerUpTime) { float spawnAngle = Random.Range(-spawnAngleMax / 2, spawnAngleMax / 2); GameObject powerupPrefab = powerups[Mathf.CeilToInt(Random.Range(0, powerups.Length))]; Vector2 spawnPosition = new Vector2(Random.Range( -screenHalfSize.x + powerupPrefab.transform.localScale.x, screenHalfSize.x - powerupPrefab.transform.localScale.x), screenHalfSize.y + powerupPrefab.transform.localScale.y); Instantiate(powerupPrefab, spawnPosition, Quaternion.Euler(Vector3.forward * spawnAngle)); nextPowerUpTime = Time.time + RandomFromDistribution.RandomRangeNormalDistribution(powerUpDelay.x, powerUpDelay.y, RandomFromDistribution.ConfidenceLevel_e._95); } }
public override float GetRandomNumber(float min, float max) { return(RandomFromDistribution.RandomRangeExponential(min, max, exponent, direction)); }
// Start is called before the first frame update void Start() { instantiationTimer = RandomFromDistribution.RandomRangeExponential(5, 8, 2, direction); }
/// <summary> /// Generates the environment for the experiments. /// </summary> private void GenerateEnvironment() { // delete old obstacles if (obstaclesList.Count > 0) { foreach (GameObject obj in obstaclesList) { obj.SetActive(false); Destroy(obj.gameObject); } obstaclesList.Clear(); } // set new track width grid.gridWorldSize = new Vector2(Random.Range(12, 20), grid.gridWorldSize.y); Vector2 gS = grid.gridWorldSize; // place detectable obstacles on the sidelines for (int i = 0; i < sideObstacleCount; i++) { // calculate coordinates float x = RandomFromDistribution.RandomRangeNormalDistribution(-3f, 4f, RandomFromDistribution.ConfidenceLevel_e._99) + gS.x / 2; float z = Mathf.Lerp(-gS.y / 2, gS.y / 2, (float)i / (float)sideObstacleCount); // objects on the right GameObject obsToBuild = loadedObstacles[Random.Range(0, loadedObstacles.Length)]; Vector3 obsSize = obsToBuild.GetComponentInChildren <Renderer>().bounds.size; float maxSize = Mathf.Max(obsSize.x, obsSize.y); Vector3 newPos = new Vector3(x + maxSize / 3, 0f, z); Quaternion newRot = Quaternion.Euler(Random.Range(-5f, 5f), Random.Range(0f, 360f), Random.Range(-5f, 5f)); GameObject newObs = Instantiate(obsToBuild, newPos, newRot) as GameObject; newObs.GetComponentInChildren <MeshRenderer>().material = ObstacleMat; newObs.layer = 8; obstaclesList.Add(newObs); // objects on the left obsToBuild = loadedObstacles[Random.Range(0, loadedObstacles.Length)]; obsSize = obsToBuild.GetComponentInChildren <Renderer>().bounds.size; maxSize = Mathf.Max(obsSize.x, obsSize.y); newPos = new Vector3(-x - maxSize / 3, 0f, z); newRot = Quaternion.Euler(Random.Range(-5f, 5f), Random.Range(0f, 360f), Random.Range(-5f, 5f)); newObs = Instantiate(obsToBuild, newPos, newRot) as GameObject; newObs.GetComponentInChildren <MeshRenderer>().material = ObstacleMat; newObs.layer = 8; obstaclesList.Add(newObs); } // update current obstacle ID if not set to fixed if (!fixedObstacle) { if (currentObstacleID < loadedObstacles.Length - 1) { currentObstacleID++; } else { Debug.Log("Epoch: " + currentEpoch++); currentObstacleID = 0; } } // load central obstacle to avoid GameObject otb = loadedObstacles[currentObstacleID]; Vector3 oS = otb.GetComponentInChildren <Renderer>().bounds.size; // make sure it's not too big float mS = Mathf.Max(oS.x, oS.y); while (mS > grid.gridWorldSize.x / 2f) { otb = loadedObstacles[Random.Range(0, loadedObstacles.Length)]; oS = otb.GetComponentInChildren <Renderer>().bounds.size; mS = Mathf.Max(oS.x, oS.y); } // place it Vector3 nP = new Vector3(Random.value - 0.5f, Random.value - 0.25f, 0f); Quaternion nR = Quaternion.Euler(Random.Range(-5f, 5f), Random.Range(0f, 360f), Random.Range(-5f, 5f)); currentObstacle = Instantiate(otb, nP, nR) as GameObject; obstaclesList.Add(currentObstacle); // make obstacle undetectable in x % of the cases to force crashes if (Random.value < crashChance) { currentObstacle.layer = 9; currentObstacle.GetComponentInChildren <MeshRenderer>().material = CrashObjMat; isSteeringData = false; } else { currentObstacle.layer = 8; currentObstacle.GetComponentInChildren <MeshRenderer>().material = ObstacleMat; isSteeringData = true; } grid.Awake(); }
public override float GetRandomNumber(float min, float max) { return(RandomFromDistribution.RandomRangeNormalDistribution(min, max, conf_level)); }
// Update is called once per frame void Update() { if (player.transform.position.z < 0 & numTraversalsLocal != sp.numTraversals) { numTraversalsLocal++; if (numTraversalsLocal >= (numBaselineTrials + numTrainingTrials)) { if (nextMorphTrial < 0) { nextMorphTrial = numTraversalsLocal + (int)UnityEngine.Mathf.Round(RandomFromDistribution.RandomRangeLinear(-.5f, 3f, 0f)); Debug.Log("next morph" + nextMorphTrial.ToString()); } if (numTraversalsLocal == nextMorphTrial) { nextMorphTrial = -1; sp.morph = morphTrials[morphCounter]; morphCounter++; } else { sp.morph = NextTrial(); trialHistory.Add(sp.morph); } } else if (numTraversalsLocal >= numBaselineTrials) { sp.morph = NextTrial(); trialHistory.Add(sp.morph); } else { sp.morph = baselineTrials[numTraversalsLocal]; } if (trialHistory.Count > 40) { trialHistory.RemoveAt(0); } } }
protected float GetRandomNumber() { return((float)RandomFromDistribution.RandomChoiceFollowingDistribution(new List <float>(distribution))); }
// Update is called once per frame void FixedUpdate() { float shootRandomDirection = RandomFromDistribution.RandomNormalDistribution(0, 0.5f); Player[] players = GameObject.FindObjectsOfType <Player>(); List <Player> playersWithoutMe = new List <Player>(); Player me = null; int currentId = gameObject.GetInstanceID(); for (int i = 0; i < players.Length; i++) { if (players[i].gameObject.GetInstanceID() != currentId) { playersWithoutMe.Add(players[i]); } else { me = players[i]; } } Player nearestPlayer = null; float nearestPlayerDist = 10000; if (me != null) { for (int i = 0; i < playersWithoutMe.Count; i++) { float dist = Vector3.Distance(playersWithoutMe[i].gameObject.transform.position, me.gameObject.transform.position); if (dist < nearestPlayerDist) { nearestPlayerDist = dist; nearestPlayer = playersWithoutMe[i]; } } } if (nearestPlayer != null) { Player.Shoot(new Vector3(nearestPlayer.transform.position.x + shootRandomDirection, nearestPlayer.transform.position.y + shootRandomDirection, 0)); } Vector3Int bufPos; if ((currentWaypoint.x != 0 && currentWaypoint.y != 0) && (Math.Abs(currentWaypoint.x - transform.position.x) > 1.1 || Math.Abs(currentWaypoint.y - transform.position.y) > 1.1)) { bufPos = gridLayout.WorldToCell(new Vector3(transform.position.x, transform.position.y, 0)); Vector2 direction = gridLayout.CellToWorld(new Vector3Int(currentWaypoint.x, currentWaypoint.y, 0)); direction = direction - new Vector2(bufPos.x, bufPos.y); direction = direction.normalized; Player.Move(direction); return; } bufPos = gridLayout.WorldToCell(new Vector3(transform.position.x, transform.position.y, 0)); Vector2Int from = new Vector2Int(bufPos.x, bufPos.y); FieldTile[,] map = gameManager._field.getArray(); currentWaypoint = ChooseWayPoint(map, from); Debug.Log(currentWaypoint); Vector2Int[] path = FloodFill.GetPath(map, from, currentWaypoint, 3); if (path != null) { if (path.GetLength(0) > 1) { currentWaypoint = path[1]; } else { if (path.GetLength(0) > 0) { currentWaypoint = path[0]; } else { return; } } Vector2 direction = gridLayout.CellToWorld(new Vector3Int(currentWaypoint.x, currentWaypoint.y, 0)); direction = direction - new Vector2(bufPos.x, bufPos.y); direction = direction.normalized; Player.Move(direction * Velocity); } }
void Awake() { int numClusters = Random.Range(numClustersLB, numClustersUB); float xcoord; float ycoord; float zcoord; float magnitude; using (System.IO.StreamWriter file = new System.IO.StreamWriter(Directory.GetCurrentDirectory() + @"\\Assets\\StreamingAssets\\DxRData\\GenPlot.json")) { file.Write("["); for (int i = 0; i < numClusters; ++i) { int pointsInCluster = Random.Range(numPointsLB, numPointsUB); int centerXCoord = Random.Range(XCenterLB, XCenterUB); int centerYCoord = Random.Range(YCenterLB, YCenterUB); int centerZCoord = Random.Range(ZCenterLB, ZCenterUB); if (normalizedDistribution) { xDist = RandomFromDistribution.RandomRangeNormalDistribution(xDistLB, xDist, confLevel); yDist = RandomFromDistribution.RandomRangeNormalDistribution(yDistLB, yDist, confLevel); zDist = RandomFromDistribution.RandomRangeNormalDistribution(zDistLB, zDist, confLevel); } else { xDist = Random.Range(xDistLB, xDist); yDist = Random.Range(yDistLB, yDist); zDist = Random.Range(zDistLB, zDist); } xyRotDeg = RandomFromDistribution.RandomRangeNormalDistribution(0, xyRotDeg, confLevel); yzRotDeg = RandomFromDistribution.RandomRangeNormalDistribution(0, yzRotDeg, confLevel); xzRotDeg = RandomFromDistribution.RandomRangeNormalDistribution(0, xzRotDeg, confLevel); for (int j = 0; j < pointsInCluster; ++j) { if (randomFromDist) { xcoord = RandomFromDistribution.RandomRangeNormalDistribution(-xDist, xDist, confLevel); ycoord = RandomFromDistribution.RandomRangeNormalDistribution(-yDist, yDist, confLevel); zcoord = RandomFromDistribution.RandomRangeNormalDistribution(-zDist, zDist, confLevel); if (isSphere) { magnitude = (float)System.Math.Sqrt(xcoord * xcoord + ycoord * ycoord + zcoord * zcoord); xcoord = xDist * (xcoord / magnitude); ycoord = yDist * (ycoord / magnitude); zcoord = zDist * (zcoord / magnitude); // xy plane rotation xcoord = xcoord * Mathf.Cos(0.0174533f * xyRotDeg) - ycoord * Mathf.Sin(0.0174533f * xyRotDeg); ycoord = xcoord * Mathf.Sin(0.0174533f * xyRotDeg) + ycoord * Mathf.Cos(0.0174533f * xyRotDeg); // yz plane rotation ycoord = ycoord * Mathf.Cos(Mathf.Deg2Rad * yzRotDeg) - zcoord * Mathf.Sin(Mathf.Deg2Rad * yzRotDeg); zcoord = ycoord * Mathf.Sin(Mathf.Deg2Rad * yzRotDeg) + zcoord * Mathf.Cos(Mathf.Deg2Rad * yzRotDeg); // xz rotation xcoord = xcoord * Mathf.Cos(Mathf.Deg2Rad * xzRotDeg) - zcoord * Mathf.Sin(Mathf.Deg2Rad * xzRotDeg); zcoord = xcoord * Mathf.Sin(Mathf.Deg2Rad * xzRotDeg) + zcoord * Mathf.Cos(Mathf.Deg2Rad * xzRotDeg); xcoord += centerXCoord; ycoord += centerYCoord; zcoord += centerZCoord; } else { xcoord += centerXCoord; ycoord += centerYCoord; zcoord += centerZCoord; } } else { xcoord = Random.Range(xDistLB, xDist + 1); ycoord = Random.Range(yDistLB, yDist + 1); zcoord = Random.Range(zDistLB, zDist + 1); if (isSphere) { magnitude = (float)System.Math.Sqrt(xcoord * xcoord + ycoord * ycoord + zcoord * zcoord); xcoord = xDist * (xcoord / magnitude); ycoord = yDist * (ycoord / magnitude); zcoord = zDist * (zcoord / magnitude); // xy plane rotation xcoord = xcoord * Mathf.Cos(0.0174533f * xyRotDeg) - ycoord * Mathf.Sin(0.0174533f * xyRotDeg); ycoord = xcoord * Mathf.Sin(0.0174533f * xyRotDeg) + ycoord * Mathf.Cos(0.0174533f * xyRotDeg); // yz plane rotation //ycoord = ycoord * Mathf.Cos(Mathf.Deg2Rad * yzRotDeg) - zcoord * Mathf.Sin(Mathf.Deg2Rad * yzRotDeg); //zcoord = ycoord * Mathf.Sin(Mathf.Deg2Rad * yzRotDeg) + zcoord * Mathf.Cos(Mathf.Deg2Rad * yzRotDeg); // xz rotation //xcoord = xcoord * Mathf.Cos(Mathf.Deg2Rad * xzRotDeg) - zcoord * Mathf.Sin(Mathf.Deg2Rad * xzRotDeg); //zcoord = xcoord * Mathf.Sin(Mathf.Deg2Rad * xzRotDeg) + zcoord * Mathf.Cos(Mathf.Deg2Rad * xzRotDeg); xcoord += centerXCoord; ycoord += centerYCoord; zcoord += centerZCoord; } else { xcoord += centerXCoord; ycoord += centerYCoord; zcoord += centerZCoord; } } int color = i; // need x, y, z, color file.Write("\n\t{ \n \t\t \"Xcoord\": " + xcoord + ","); file.Write("\n\t\t \"Ycoord\": " + ycoord + ","); file.Write("\n\t\t \"Zcoord\": " + zcoord + ","); file.Write("\n\t\t \"Color\": " + color + "\n\t}"); if (j != pointsInCluster - 1 && i != numClusters - 1) { file.Write(","); } } } file.Write("]"); } }
protected override float GetRandomNumber(float min, float max) { return(RandomFromDistribution.RandomRangeExponential(min, max, exponent, direction)); //Debug.Log(RandomFromDistribution.RandomRangeExponential(min, max, exponent, direction)); }
float NextTrial() { float e0 = 0f; float e1 = 0f; int i = 0; while (pc.LickHistory.Count > 40) { pc.LickHistory.RemoveAt(0); } //int i; Debug.Log(i); Debug.Log(pc.LickHistory.Count); if (pc.LickHistory.Count < 40) { for (int j = 0; j < 40 - pc.LickHistory.Count; j++) { e1 = e1 + .5f * Pr_vec[j]; e0 = e0 + .5f * Pr_vec[j]; } i = 40 - pc.LickHistory.Count; } else { i = 0; } foreach (float j in pc.LickHistory) { //Debug.Log(i); if (j == -1) { Debug.Log(i); e1 = e1 + Pr_vec[i]; } else if (j == 1) { Debug.Log(i); e0 = e0 + Pr_vec[i]; } i++; } float p1; if (e0 + e1 == 0f) { p1 = .5f; } else { p1 = Mathf.Sqrt(e1) / (Mathf.Sqrt(e1) + Mathf.Sqrt(e0)); } if (p1 > .85f) { p1 = .85f; } else if (p1 < .15f) { p1 = .15f; } ; Debug.Log(p1); float sum = 0; int k = 0; foreach (float j in trialHistory) { sum = sum + j * P_corrector_vec[k]; k++; } float emp_p1 = sum / (float)trialHistory.Count; float thresh; if (p1 > emp_p1) { thresh = .5f * p1; } else { thresh = .5f * (1 + p1); } if (RandomFromDistribution.RandomRangeLinear(0f, 1f, 0f) < p1) { return(1f); } else { return(0f); } }
// Start is called before the first frame update void Start() { nextPowerUpTime = Time.time + RandomFromDistribution.RandomRangeNormalDistribution(powerUpDelay.x, powerUpDelay.y, RandomFromDistribution.ConfidenceLevel_e._95); screenHalfSize = new Vector2(Camera.main.aspect * Camera.main.orthographicSize, Camera.main.orthographicSize); }
protected override float GetRandomNumber(float min, float max) { return(RandomFromDistribution.RandomRangeLinear(min, max, slope)); }
protected override float GetRandomNumber(float min, float max) { return(RandomFromDistribution.RandomRangeSlope(min, max, skew, direction)); }
/* Immigration */ void ResetCitizenSpawnCooldown() { TravelerCooldown = 4f; // Cooldown Minimum TravelerCooldown += Mathf.Abs(RandomFromDistribution.RandomFromStandardNormalDistribution()) * 2.0f; // Random contributon, typically close to 1.0f TravelerCooldown += Threat * 5.0f; // Spawn less often when threat is high }
public float GetRandomFloat() { return(RandomFromDistribution.RandomNormalDistribution(mean, standardDeviation)); }