private void SampleRandom() { Debug.Log("GENERATING RANDOM " + _randomType + " WITH SEED: " + seed); UnityRandom urand = new UnityRandom(seed); if (randomList == null) { randomList = new ArrayList(); } randomList.Clear(); switch (_randomType) { case RandomType.NUMBER: SampleNumber(ref urand); break; case RandomType.VECTOR_2D: SampleVector2D(ref urand); break; case RandomType.VECTOR_3D: SampleVector3D(ref urand); break; case RandomType.COLOR: SampleColor(ref urand); break; case RandomType.DICE: SampleDice(ref urand); break; case RandomType.SHUFFLEBAG: SampleShuffle(ref urand); break; case RandomType.WEIGHTEDBAG: SampleWShuffle(ref urand); break; default: SampleNumber(ref urand); break; } this.Repaint(); }
private void SampleDice(ref UnityRandom _urand) { for (int i = 0; i < samplig_size; i++) { randomList.Add(_urand.RollDice(nroll, dice)); } }
////////////////////////////////////////////////////////////////////////// public void Pretend() { // preform grid pretends for (var r = Grid.Instance.m_Column - 1; r >= 0; r--) { foreach (var slot in Grid.Instance.GetRow(r, true)) { slot.m_Actor?.Pretend(); } } // randomize reserve order UnityRandom.RandomizeList(m_ReserveActors); // preform reserve pretends foreach (var actor in m_ReserveActors.ToList()) { actor.Pretend(); } // implement moves foreach (var actor in m_ReserveActors) { actor.ImplementMove(); } foreach (var actor in m_BoardActors) { actor.ImplementMove(); } }
public string GetNextRandomName(ICollection <NameElement> tokens) { if (tokens == null) { return(GetNextRandomName()); } var result = ""; var rule = UnityRandom.RandomFromList(m_RulesList.List); foreach (var token in rule) { if (UnityRandom.Bool(token.Value)) { var tokenChoise = m_SyllableDictionary[token.Key]; var syllable = tokenChoise.GetSyllable(); result += syllable; tokens.Add(new NameElement() { m_Tag = token.Key, m_Syllable = syllable }); } } return(result); }
public Vector3 KillMostWeakCharacter() { int minHp = int.MaxValue; var candidates = new List <Character>(); foreach (var n in Tribe.Instance.m_CharacterList) { if (n.m_Health < minHp) { minHp = n.m_Health; candidates.Clear(); candidates.Add(n); } else if (n.m_Health == minHp) { candidates.Add(n); } } var deadMan = UnityRandom.RandomFromList(Tribe.Instance.m_CharacterList, null); if (deadMan != null) { deadMan.Dead(); return(deadMan.transform.position); } return(Vector3.zero); }
public void Dead() { if (m_State == CharacterState.Dead) { return; } SoundManager.Instance.Play("Dead"); Destroy(GetComponent <Collider2D>()); transform.rotation = Quaternion.Euler(0.0f, 0.0f, (UnityRandom.Bool() ? 1: -1) * UnityEngine.Random.Range(45.0f, 135.0f)); if (implIsNative()) { m_CurrentHub.DefenderIsDead(this); } else { Tribe.Instance.CharacterIsDead(this); } if (m_State == CharacterState.Travel) { SwarmManager.Instance.Initialize(); } m_Animator.enabled = false; m_State = CharacterState.Dead; }
////////////////////////////////////////////////////////////////////////// public Sprite Roll() { if (m_WeightedBag == null) { m_WeightedBag = UnityRandom.CreateWeightedBag(m_Data.Select(n => n.m_Sprite), m_Data.Select(n => n.m_Chanse)); } return(m_WeightedBag.Next()); }
public void ImplementMove() { if (m_Slot != null) { m_MoveTween.Cancel(); m_MoveTween.MovePosition = m_Slot.transform.position + UnityRandom.Vector2(PlayerEntity.Instance.m_PositionRandomization).To3DXY(); m_MoveTween.Start(); } }
public void RemoveArmor() { var slot = UnityRandom.RandomFromList(m_ArmorList.Where((s) => !s.m_EmptySlot).ToList(), null); if (slot != null) { slot.TakeOff(); } }
// Use this for initialization void Start() { UnityRandom urand = new UnityRandom(); float val = urand.Possion(035.6f); float val2 = urand.Possion(3.0f); Debug.Log(val); Debug.Log(val2); }
public void KillRandomCharacter() { var deadMan = UnityRandom.RandomFromList(Tribe.Instance.m_CharacterList, null); if (deadMan != null) { deadMan.Dead(); } }
private void implDead() { m_Animate.enabled = false; m_Rotate.enabled = false; m_Translate.enabled = false; Destroy(GetComponent <Collider2D>()); transform.rotation = Quaternion.Euler(0.0f, 0.0f, (UnityRandom.Bool() ? 1 : -1) * UnityEngine.Random.Range(45.0f, 135.0f)); }
private void SampleShuffle(ref UnityRandom _urand) { ShuffleBagCollection <float> thebag = _urand.ShuffleBag(shufflebag); for (int m = 0; m < samplig_size; m++) { randomList.Add(thebag.Next()); } randomList.Sort(); }
////////////////////////////////////////////////////////////////////////// public GameObject Roll(float scale) { if (m_WeightedBag == null) { m_WeightedBag = UnityRandom.CreateWeightedBag(m_Data.Select(n => n.m_Prefab), m_Data.Select(n => n.m_Chanse.Evaluate(scale))); } var result = m_WeightedBag.Next(); return(result); }
////////////////////////////////////////////////////////////////////////// public override void iProceedTurn() { if (UnityRandom.Bool(m_PhotoChanse)) { PlayerEntity.Instance.m_ActionSequence.Add(new Actor.ActionPhoto() { m_Delay = Random.Range(m_PhotoDelay.x, m_PhotoDelay.y), Master = Master }); } }
public void AddArmor() { var slot = UnityRandom.RandomFromList(m_ArmorList.Where((s) => s.m_EmptySlot).ToList(), null); if (slot != null) { slot.Wear(); } PlayerManager.Instance.AddArmor(transform.position); m_Health++; }
void Start() { waitingTimes.Add("Farmacia", 0); waitingTimes.Add("Salchichas", 0); waitingTimes.Add("Atencion_Cliente", 0); waitingTimes.Add("Carnes", 0); waitingTimes.Add("Compras", 0); waitingTimes.Add("Caja", 0); waitingTimes.Add("Embolsadora", 0); numberOfTransitions = 0; done = false; numberOfItems = 0; nextTargetString = ""; nextTarget = null; manager = VariableManager.instance; id = manager.asignNewId(); urand = new UnityRandom(); waitingTime = 0; float Farmacia = urand.Value(); float Salchichas = urand.Value(); float AtencionCliente = urand.Value(); float Carnes = urand.Value(); float Compra = urand.Value(); if (Farmacia <= manager.ProbabilidadFarmacia) { FarmaciaBool = true; places.Add("Farmacia"); } if (Salchichas <= manager.ProbabilidadSalchichoneria) { SalchichasBool = true; places.Add("Salchichas"); } if (AtencionCliente <= manager.ProbabilidadServicioCliente) { AtencionClienteBool = true; places.Add("Atencion_Cliente"); } if (Carnes <= manager.ProbabilidadCarnes) { CarnesBool = true; places.Add("Carnes"); } if (Compra <= manager.ProbabilidadCompras) { CompraBool = true; numberOfItems = manager.getNormalDistribution("Compra"); } transform.GetChild(0).GetComponent <Text>().text = id.ToString(); makeDecision(); }
public T GetData(UnityRandom rand) { UpdatePriority(); var urand = RandomUtil.Urand; RandomUtil.SetUnityRandom(rand); int index = RandomUtil.GetUnityRandomIndexWithWeight(priorityArray); RandomUtil.SetUnityRandom(urand); return(elements[index].Data); }
void OnLevelWasLoaded() { if (SceneManager.GetActiveScene().name == "Grid") { manager = GameObject.Find("Compras").GetComponent <AreaManager>(); cleaningText = GameObject.Find("Compras").transform.GetChild(3).GetComponent <Text>(); cleaningText.gameObject.SetActive(false); endSeconds = 0; startSeconds = VariableManager.instance.secondsElapsed; urand = new UnityRandom(); cleaning = false; } }
public void Detained() { var bodyguard = PlayerEntity.Instance.GetBodyguard(); if (bodyguard == null) { SoundManager.Instance.PlaySound("Ban"); return; } if (m_Slot != null) { m_Slot.m_Actor = null; m_Slot = null; } // play sound SoundManager.Instance.PlaySound("Detain"); // disable colliders foreach (var collider in GetComponentsInChildren <Collider2D>()) { collider.enabled = false; } PlayerEntity.Instance.m_BoardActors.Remove(this); PlayerEntity.Instance.m_ReserveActors.Remove(this); var closestDetainedBounds = Vector3.Distance(PlayerEntity.Instance.m_ZoneDetaindLeft.ClosestPoint(transform.position), transform.position) < Vector3.Distance(PlayerEntity.Instance.m_ZoneDetaindRight.ClosestPoint(transform.position), transform.position) ? PlayerEntity.Instance.m_ZoneDetaindLeft : PlayerEntity.Instance.m_ZoneDetaindRight; // play move animation m_DetainedTween.MovePosition = UnityRandom.BoundPoint(closestDetainedBounds); m_DetainedTween .Start() .setDelay(bodyguard.Detain(this, out var model)) .setOnStart(() => { // link model model.transform.SetParent(transform, false); model.transform.localPosition = UnityRandom.Vector2(PlayerEntity.Instance.m_PositionRandomization).WithY(-0.1f); }) .setOnComplete(() => { Destroy(model); Destroy(gameObject); }); }
public List <Slot> GetTransitions(Direction requireFlags, bool randomize) { var result = m_TransitionDictionary .Where(n => n.Key.HasFlag(requireFlags)) .Select(n => n.Value) .ToList(); if (randomize) { UnityRandom.RandomizeList(result); } return(result); }
private void SampleColor(ref UnityRandom _urand) { for (int i = 0; i < samplig_size; i++) { if (transform) { randomList.Add(_urand.Rainbow(normalization, temperature)); } else { randomList.Add(_urand.Rainbow()); } } }
private void SampleVector3D(ref UnityRandom _urand) { for (int i = 0; i < samplig_size; i++) { switch (_randomVector3DType) { case RandomVector3DType.INCUBE: if (transform) { randomList.Add(_urand.PointInACube(normalization, temperature)); } else { randomList.Add(_urand.PointInACube()); } break; case RandomVector3DType.ONCUBE: if (transform) { randomList.Add(_urand.PointOnACube(normalization, temperature)); } else { randomList.Add(_urand.PointOnACube()); } break; case RandomVector3DType.INSPHERE: randomList.Add(_urand.PointInASphere()); break; case RandomVector3DType.ONSPHERE: randomList.Add(_urand.PointOnASphere()); break; case RandomVector3DType.ONCAP: randomList.Add(_urand.PointOnCap(spotAngle)); break; case RandomVector3DType.ONRING: randomList.Add(_urand.PointOnRing(innerAngle, outerAngle)); break; default: break; } } }
public int getNormalDistribution(string Area) { UnityRandom urand = new UnityRandom(); switch (Area) { case "Compra": { return((int)urand.Range(1, _numberOfItems, UnityRandom.Normalization.STDNORMAL, 1.0f)); break; } } return(0); }
public void Apply(float force) { switch (m_Method) { case Method.Random: GetComponent <Rigidbody2D>().AddForce(UnityRandom.Normal2D() * force, m_Mode); break; case Method.Vector: Apply(m_Vector * force, m_Force); break; default: throw new ArgumentOutOfRangeException(); } }
private void SampleNumber(ref UnityRandom _urand) { for (int i = 0; i < samplig_size; i++) { switch (_randomNumberType) { case RandomNumberType.VALUE: if (transform) { randomList.Add(_urand.Value(normalization, temperature)); } else { randomList.Add(_urand.Value()); } break; case RandomNumberType.RANGE: if (transform) { randomList.Add(_urand.Range(_range_min, _range_max, normalization, temperature)); } else { randomList.Add(_urand.Range(_range_min, _range_max)); } break; case RandomNumberType.POISSON: randomList.Add(_urand.Possion(temperature)); break; case RandomNumberType.EXPONENTIAL: randomList.Add(_urand.Exponential(temperature)); break; case RandomNumberType.GAMMA: randomList.Add(_urand.Gamma(temperature)); break; default: break; } } randomList.Sort(); }
public List <Slot> GetRow(int index, bool randomize) { if (index >= m_SlotList.Count) { return(null); } var result = m_SlotList[index]; if (randomize) { result = result.ToList(); UnityRandom.RandomizeList(result); } return(result); }
public static Vector2 Circle( ref NPack.MersenneTwister _rand, UnityRandom.Normalization n, float t ) { float r; switch (n) { case UnityRandom.Normalization.STDNORMAL: r = SpecialFunctions.ScaleFloatToRange( (float) NormalDistribution.Normalize(_rand.NextSingle(true), t), 0, Int32.MaxValue, 0, 1); break; case UnityRandom.Normalization.POWERLAW: r = (float) PowerLaw.Normalize(_rand.NextSingle(true), t, 0, Int32.MaxValue); break; default: r = (float) _rand.Next(); break; } float _2pi = (float) Math.PI * 2; float a = SpecialFunctions.ScaleFloatToRange(r, 0, _2pi, 0, Int32.MaxValue); return new Vector2( (float) Math.Cos(a) , (float) Math.Sin(a)); }
private void SampleVector2D(ref UnityRandom _urand) { for (int i = 0; i < samplig_size; i++) { switch (_randomVector2DType) { case RandomVector2DType.SQUARE: if (transform) { randomList.Add(_urand.PointInASquare(normalization, temperature)); } else { randomList.Add(_urand.PointInASquare()); } break; case RandomVector2DType.CIRCLE: if (transform) { randomList.Add(_urand.PointInACircle(normalization, temperature)); } else { randomList.Add(_urand.PointInACircle()); } break; case RandomVector2DType.DISK: if (transform) { randomList.Add(_urand.PointInADisk(normalization, temperature)); } else { randomList.Add(_urand.PointInADisk()); } break; default: break; } } }
public void Leave() { if (m_Slot != null) { m_Slot.m_Actor = null; m_Slot = null; } PlayerEntity.Instance.m_BoardActors.Remove(this); PlayerEntity.Instance.m_ReserveActors.Remove(this); m_LeaveTween.MovePosition = UnityRandom.BoundPoint(PlayerEntity.Instance.m_ZoneLeave); m_LeaveTween .Start() .setOnComplete(() => { Destroy(gameObject); }); }
public string GetNextRandomName() { var result = ""; // get random token combination var rule = UnityRandom.RandomFromList(m_RulesList.List); foreach (var token in rule) { // roll token chance if (UnityRandom.Bool(token.Value)) { var tokenChoise = m_SyllableDictionary[token.Key]; result += tokenChoise.GetSyllable(); } } return(result); }
public static Vector2 Disk( ref NPack.MersenneTwister _rand, UnityRandom.Normalization n, float temp ) { double t, theta; switch (n) { case UnityRandom.Normalization.STDNORMAL: t = NormalDistribution.Normalize(_rand.NextSingle(true), temp); theta = NormalDistribution.Normalize(_rand.NextSingle(true), temp) * 2 * Math.PI; break; case UnityRandom.Normalization.POWERLAW: t = PowerLaw.Normalize(_rand.NextSingle(true), temp, 0, 1); theta = PowerLaw.Normalize(_rand.NextSingle(true), temp, 0, 1) * 2 * Math.PI; break; default: t = (float) _rand.NextSingle(true); theta = _rand.NextSingle(false) * 2 * Math.PI; break; } return new Vector2( (float) (Math.Sqrt(t) * Math.Cos(theta)), (float) (Math.Sqrt(t) * Math.Sin(theta)) ); }
public static Vector2 Area( ref NPack.MersenneTwister _rand, UnityRandom.Normalization n, float t ) { float x,y; x = y = 0; switch (n) { case UnityRandom.Normalization.STDNORMAL: x = (float) NormalDistribution.Normalize(_rand.NextSingle(true), t); y = (float) NormalDistribution.Normalize(_rand.NextSingle(true), t); break; case UnityRandom.Normalization.POWERLAW: x = (float) PowerLaw.Normalize(_rand.NextSingle(true), t, 0, 1); y = (float) PowerLaw.Normalize(_rand.NextSingle(true), t, 0, 1); break; default: x = _rand.NextSingle(true); y = _rand.NextSingle(true); break; } // Move to -1, 1 space as for CIRCLE and SPHERE return new Vector2((2*x - 1), (2*y - 1)); }
public static Vector3 Surface(ref NPack.MersenneTwister _rand, UnityRandom.Normalization n, float t) { Vector3 pos = new Vector3(); switch (n) { case UnityRandom.Normalization.STDNORMAL: pos = GetPointOnCubeSurface( (float) NormalDistribution.Normalize(_rand.NextSingle(true), t), (float) NormalDistribution.Normalize(_rand.NextSingle(true), t), _rand.Next(5)); break; case UnityRandom.Normalization.POWERLAW: pos = GetPointOnCubeSurface( (float) PowerLaw.Normalize(_rand.NextSingle(true), t, 0, 1), (float) PowerLaw.Normalize(_rand.NextSingle(true), t, 0, 1), _rand.Next(5)); break; default: pos = GetPointOnCubeSurface(_rand.NextSingle(true),_rand.NextSingle(true),_rand.Next(5)); break; } // Move to -1, 1 space as for CIRCLE and SPHERE return new Vector3((2*pos.x)-1, (2*pos.y)-1, (2*pos.z)-1); }
private void SampleShuffle(ref UnityRandom _urand) { ShuffleBagCollection<float> thebag = _urand.ShuffleBag(shufflebag); for (int m = 0; m < samplig_size; m++) { randomList.Add(thebag.Next()); } randomList.Sort(); }
public PRNG(int seed) { urand = new UnityRandom(seed); }
public static UnityRandom initialize_seed(string key, int seed = 0){ channels[key] = new UnityRandom(seed); return channels[key]; }
// INIT a new UnityRandom object with a random seed private void InitRandom() { urand = new UnityRandom(seed); }
private void SampleVector3D(ref UnityRandom _urand) { for (int i = 0; i < samplig_size; i++) { switch (_randomVector3DType) { case RandomVector3DType.INCUBE: if (transform) { randomList.Add(_urand.PointInACube(normalization,temperature)); } else { randomList.Add(_urand.PointInACube()); } break; case RandomVector3DType.ONCUBE: if (transform) { randomList.Add(_urand.PointOnACube(normalization,temperature)); } else { randomList.Add(_urand.PointOnACube()); } break; case RandomVector3DType.INSPHERE: randomList.Add(_urand.PointInASphere()); break; case RandomVector3DType.ONSPHERE: randomList.Add(_urand.PointOnASphere()); break; case RandomVector3DType.ONCAP: randomList.Add(_urand.PointOnCap(spotAngle)); break; case RandomVector3DType.ONRING: randomList.Add(_urand.PointOnRing(innerAngle,outerAngle)); break; default: break; } } }
// Really no time to make it better (FIXME) private void SampleWShuffle(ref UnityRandom _urand) { wshufflebag = new Dictionary<float,int>(); // fill the wshufflebag wshufflebag[1] = 5; wshufflebag[2] = 10; wshufflebag[3] = 10; wshufflebag[4] = 25; wshufflebag[5] = 25; wshufflebag[6] = 10; wshufflebag[7] = 5; wshufflebag[8] = 5; wshufflebag[9] = 3; wshufflebag[10] = 2; ShuffleBagCollection<float> thebag = _urand.ShuffleBag(wshufflebag); for (int m = 0; m < samplig_size; m++) { randomList.Add(thebag.Next()); } randomList.Sort(); }
public PRNG() { var r = new System.Random(); var seed = r.Next(); urand = new UnityRandom(seed); }
private void SampleVector2D(ref UnityRandom _urand) { for (int i = 0; i < samplig_size; i++) { switch (_randomVector2DType) { case RandomVector2DType.SQUARE: if (transform) { randomList.Add(_urand.PointInASquare(normalization,temperature)); } else { randomList.Add(_urand.PointInASquare()); } break; case RandomVector2DType.CIRCLE: if (transform) { randomList.Add(_urand.PointInACircle(normalization,temperature)); } else { randomList.Add(_urand.PointInACircle()); } break; case RandomVector2DType.DISK: if (transform) { randomList.Add(_urand.PointInADisk(normalization,temperature)); } else { randomList.Add(_urand.PointInADisk()); } break; default: break; } } }
private void SampleRandom() { Debug.Log("GENERATING RANDOM " + _randomType + " WITH SEED: " + seed); UnityRandom urand = new UnityRandom(seed); if (randomList == null) randomList = new ArrayList(); randomList.Clear(); switch (_randomType) { case RandomType.NUMBER: SampleNumber(ref urand); break; case RandomType.VECTOR_2D: SampleVector2D(ref urand); break; case RandomType.VECTOR_3D: SampleVector3D(ref urand); break; case RandomType.COLOR: SampleColor(ref urand); break; case RandomType.DICE: SampleDice(ref urand); break; case RandomType.SHUFFLEBAG: SampleShuffle(ref urand); break; case RandomType.WEIGHTEDBAG: SampleWShuffle(ref urand); break; default: SampleNumber(ref urand); break; } this.Repaint(); }
private void SampleNumber(ref UnityRandom _urand) { for (int i = 0; i < samplig_size; i++) { switch (_randomNumberType) { case RandomNumberType.VALUE: if (transform) { randomList.Add(_urand.Value( normalization, temperature )); } else { randomList.Add(_urand.Value()); } break; case RandomNumberType.RANGE: if (transform) { randomList.Add(_urand.Range(_range_min, _range_max, normalization, temperature )); } else { randomList.Add(_urand.Range(_range_min, _range_max)); } break; case RandomNumberType.POISSON: randomList.Add(_urand.Possion(temperature)); break; case RandomNumberType.EXPONENTIAL: randomList.Add(_urand.Exponential(temperature)); break; case RandomNumberType.GAMMA: randomList.Add(_urand.Gamma(temperature)); break; default: break; } } randomList.Sort(); }
private void SampleDice(ref UnityRandom _urand) { for (int i = 0; i < samplig_size; i++) { randomList.Add( _urand.RollDice(nroll, dice)); } }
private void SampleColor(ref UnityRandom _urand) { for (int i = 0; i < samplig_size; i++) { if (transform) { randomList.Add(_urand.Rainbow(normalization,temperature)); } else { randomList.Add(_urand.Rainbow()); } } }
public static UnityRandom get_channel(string key){ if (!channels.ContainsKey(key)){ channels[key] = new UnityRandom(); } return channels[key]; }