public Type Draw() { List <RouletteItem> roulette = new List <RouletteItem>(); float ratio = 1.0f; float total = 0.0f; foreach (RouletteItem item in items) { total += item.chance * ratio; roulette.Add(new RouletteItem(item.value, total)); ratio *= decrease; } float r = Random.Range(0.0f, total); for (int i = 0, n = roulette.Count - 1; i < n; ++i) { if (roulette[i].chance > r) { RouletteItem item = roulette[i]; items.RemoveAt(i); items.Add(item); return(item.value); } } return(roulette[roulette.Count - 1].value); }
public void Shuffle() { for (int i = items.Count - 1; i > 0; --i) { int j = Random.Range(0, i + 1); RouletteItem value = items[j]; items[j] = items[i]; items[i] = value; } }
private List <RouletteItem> GetRouletteItems(List <BinaryChromosome> chromosomes, Range range, double bitsInChromosome) { var resultsList = new List <RouletteItem>(); for (int i = 0; i < chromosomes.Count; i += 2) { var item = new RouletteItem(); item.BinaryChromosomes = new List <BinaryChromosome>() { chromosomes[i], chromosomes[i + 1] }; item.FunctionResult = CalculateFunctionValue(item.BinaryChromosomes, range, bitsInChromosome); resultsList.Add(item); } return(resultsList); }
private void initItemSpeed() { listPosi = new List <RouletteItem>(); //string strXY = "" ; count = (int)(time / timeDelay); float valuex = 0; float valuey = 0; for (int i = 0; i < listSP.Count; i++) { valuex = -(listSP[i].transform.localPosition.x / count); valuey = -(listSP[i].transform.localPosition.y / count); RouletteItem ri = new RouletteItem(); ri.valueX = valuex; ri.valueY = valuey; listPosi.Add(ri); } }
public override void OnEnter() { base.OnEnter(); roulette = Owner.GetComponent <RouletteItem>(); }