private float CountThrustMultiplayer() { float ThrustMultiplayer = RandomFromDistribution.RandomChoiceFollowingDistribution(probabilities); ThrustMultiplayer = ThrustMultiplayer + 1; return(ThrustMultiplayer); }
// 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); } }
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))); }
//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](); } }
protected float GetRandomNumber() { return((float)RandomFromDistribution.RandomChoiceFollowingDistribution(new List <float>(distribution))); }