//returns the large unit at a specified su, creates one if it does not exist(every large unit will exist) public TULarge getLarge(SurfaceUnit su) { //quick hopefully temporary check, see getMid for details if (su.u < -halfgtuw || su.u >= halfgtuw || su.v < -halfgtuw || su.v >= halfgtuw) { return(null); } TULarge lu = null; //if it is in the list, return it if (largeTUs.TryGetValue(su, out lu)) { return(lu); } //if not, build one and return it TULarge tu = new TULarge(); //get this large unit's rng tu.rng = RandomHandler.transportRandom(su, TLev.LARGE); tu.conPoint = new Vector2((su.u + (float)tu.rng.NextDouble()) * sideLengthLarge, (su.v + (float)tu.rng.NextDouble()) * sideLengthLarge); tu.conUp = true; tu.conRight = true; tu.indexI = su.u; tu.indexJ = su.v; largeTUs.Add(su, tu); return(tu); }
public override void RunEffect(int seed = -1, int _duration = -1) { base.RunEffect(seed, _duration); SendEffectToGame("set_seed", seed == -1 ? RandomHandler.Next(9999999).ToString() : seed.ToString()); SendEffectToGame(type, function, (_duration == -1 ? Duration : _duration), ""); }
public void InitGame() { _world = new WorldHandler(); _tile = new TileHandler(); _random = new RandomHandler(); _hero = new HeroHandler(); _generation = new GenerationHandler(); _spawn = new Spawner(); _item = new ItemHandler(); }
//Calculate Odds of a particular event public float CalculateOdds(string handler_name, string entry_name) { RandomHandler handler = GetHandler(handler_name); Entry entry = handler.GetEntry(entry_name); //The Chance float chance = (entry.weight / handler.Sum()) * 100f; return(chance); }
public static AbstractEffect GetRandomEffect(bool onlyEnabled = false) { List <AbstractEffect> effects = (onlyEnabled ? EnabledEffects : Effects); if (effects.Count == 0) { return(null); } return(effects[RandomHandler.Next(effects.Count)]); }
public override void RunEffect(int seed = -1, int _duration = -1) { SendEffectToGame("set_seed", seed == -1 ? RandomHandler.Next(9999999).ToString() : seed.ToString()); SendEffectToGame(type, function, (_duration == -1 ? Duration : _duration), ""); if (!string.IsNullOrEmpty(GetAudioPath()) && Config.Instance().PlayAudioForEffects) { AudioPlayer.PlayAudio(GetAudioPath()); } }
static void Main(string[] args) { var yourNumber = 10; var delarray = new RandomHandler[yourNumber].Select(x => new RandomHandler(GiveMeSomeRandomNumber)).ToArray(); var ah = new AverageHandler(AverageOfDelegateMassive); Console.WriteLine(ah.Invoke(delarray)); Console.ReadKey(); }
public override void RunEffect() { int actualID = vehicleID; if (actualID == -1) { actualID = RandomHandler.Next(400, 611); } string spawnString = $"Spawn {VehicleNames.GetVehicleName(actualID)}"; SendEffectToGame("spawn_vehicle", actualID.ToString(), -1, spawnString); }
public override void RunEffect(int seed = -1, int _duration = -1) { base.RunEffect(seed, _duration); int actualID = vehicleID; if (actualID == -1) { actualID = RandomHandler.Next(400, 611); } string spawnString = $"Spawn {VehicleNames.GetVehicleName(actualID)}"; SendEffectToGame("spawn_vehicle", actualID.ToString(), (_duration == -1 ? -1 : _duration), spawnString); }
static void Main(string[] args) { List <ActionWithChance> list = new List <ActionWithChance>() { new ActionWithChance("1", 100), new ActionWithChance("2", 100), new ActionWithChance("3", 100), new ActionWithChance("4", 100), new ActionWithChance("5", 100) }; for (int i = 0; i < 10; i++) { RandomHandler.CreateIntervals(list); RandomHandler.GetRandom(list); } }
private void TryLoadConfig() { try { JsonSerializer serializer = new JsonSerializer(); using (StreamReader streamReader = new StreamReader(configPath)) using (JsonReader reader = new JsonTextReader(streamReader)) { Config.SetInstance(serializer.Deserialize <Config>(reader)); RandomHandler.SetSeed(Config.Instance().Seed); } LoadPreset(Config.Instance().EnabledEffects); UpdateInterface(); } catch (Exception) { } }
private void TryLoadConfig() { try { JsonSerializer serializer = new JsonSerializer(); using (StreamReader sr = new StreamReader(ConfigPath)) using (JsonReader reader = new JsonTextReader(sr)) { Config.Instance = serializer.Deserialize <Config>(reader); RandomHandler.SetSeed(Config.Instance.Seed); UpdateInterface(); } } catch (Exception) { } }
public void Start() { gm = GameManager.instance; entropy = Entropy.instance; handler = entropy.GetHandler("dungeon"); Debug.Log(handler.rand_seed); //Randomize Dungeon Size dungeonSize = entropy.GetHandler("dungeon").randomValue(minSize, maxSize); handler.OverridePool(exit_table); startRoom = Instantiate(handler.Randomize(), transform.position, transform.rotation); startRoom.transform.SetParent(transform); //Make the dungeon StartCoroutine("CreateDungeon"); }
//Drop all the loot before dying. public override void Die() { RandomHandler handler = Entropy.instance.GetHandler("enemy"); handler.OverridePool(table.entries); int amount = handler.randomValue(table.rolls[0], table.rolls[1]); for (int i = 0; i < amount; i++) { GameObject result = handler.Randomize(); Instantiate(result, transform.position, transform.rotation); } //Charge the player's active item GameObject player = GameObject.FindGameObjectWithTag("player"); player.SendMessage("GainCharge", 0.2f, SendMessageOptions.DontRequireReceiver); base.Die(); }
public override void RunEffect() { SendEffectToGame("set_seed", RandomHandler.Next(9999999).ToString()); SendEffectToGame(type, function, duration, "", multiplier); }
public void Start() { handler = Entropy.instance.GetHandler("arcade"); LoadWorlds(); }
public IActionResult Random(int Amount, int leftSum, int rightSum, int leftAmount, int rightAmount) { FrankWolf frank = new FrankWolf(); Random random = new Random(); if (leftSum > rightSum || leftAmount > rightAmount || leftSum < 0 || rightAmount < 0 || rightAmount < 0 || leftAmount < 0) { return(RedirectToAction(nameof(ChooseAmount))); } Order order = RandomHandler.GetRandomizedOrder(Amount, leftSum, rightSum, leftAmount, rightAmount); ViewBag.Order = order; List <OrderProduct> changedFrank = new List <OrderProduct>(); List <OrderProduct> changedAnnealing = new List <OrderProduct>(); List <OrderProduct> changedGenetic = new List <OrderProduct>(); if (order.OrdersProducts.Count() != 0) { var xNew = frank.FrankWolfMethod(order, order.OrdersProducts).ToList(); changedFrank = BetterPrices(changedFrank, order.OrdersProducts.ToList(), xNew); int[] q = new int[Amount]; int[] s = new int[Amount]; int i = 0; foreach (var op in order.OrdersProducts) { s[i] = op.WriteOffSum; q[i] = op.Amount; i++; } Methods.Task task = new Methods.Task(q, s, order.AllWriteOffSum); SimulatedAnnealing simulatedAnnealing = new SimulatedAnnealing(task, 200, 100); TaskPair pair = simulatedAnnealing.executeAlgorithm(); changedAnnealing = BetterPrices(changedAnnealing, order.OrdersProducts.ToList(), pair.X.ToList()); Genetic genetic = new Genetic(task); TaskPair pairGenetic = genetic.ExecuteAlgorithm(); changedGenetic = BetterPrices(changedGenetic, order.OrdersProducts.ToList(), pairGenetic.X.ToList()); ViewBag.ProductsFrank = changedFrank; ViewBag.ProductsAnnealing = changedAnnealing; ViewBag.ProductsGenetic = changedGenetic; var sumFrank = 0; var writeOffFrank = 0; foreach (var op in changedFrank) { sumFrank += op.Sum; writeOffFrank += op.WriteOffSum; } ViewBag.SumFrank = sumFrank; ViewBag.AllSumFrank = writeOffFrank; ViewBag.DisbalanceFrank = Math.Abs(sumFrank - writeOffFrank); var sumAnnealing = 0; var writeOffAnnealing = 0; foreach (var op in changedAnnealing) { sumAnnealing += op.Sum; writeOffAnnealing += op.WriteOffSum; } ViewBag.SumAnnealing = sumAnnealing; ViewBag.AllSumAnnealing = writeOffAnnealing; ViewBag.DisbalanceAnnealing = Math.Abs(sumAnnealing - writeOffAnnealing); var sumGenetic = 0; var writeOffGenetic = 0; foreach (var op in changedGenetic) { sumGenetic += op.Sum; writeOffGenetic += op.WriteOffSum; } ViewBag.SumGenetic = sumGenetic; ViewBag.AllSumGenetic = writeOffGenetic; ViewBag.DisbalanceGenetic = Math.Abs(sumGenetic - writeOffGenetic); } _context.SaveChanges(); return(View(order.OrdersProducts)); }
public override void RunEffect() { SendEffectToGame("set_seed", RandomHandler.Next(9999999).ToString()); SendEffectToGame("cryptic_effects", (Config.Instance.CrypticEffects ? 1 : 0).ToString()); SendEffectToGame(type, function, duration, "", multiplier); }
//a working name //builds all the objects in a certain surface unit //or if it already exists, increase its wuCount public void CreateSurfaceObjects(SurfaceUnit su) { //creates an empty surface holder SurfaceHolder sh = null; //Debug.Log (su); //only make the objects in this unit if it has not already been generated //and add it to the list so it is not generated again if (!surfList.TryGetValue(su, out sh)) { sh = new SurfaceHolder(); curSH = sh; //connect class wide reference surfList.Add(su, sh); //instance a random number generator with seed based on the su position sent through a hash function //NOTE: the last 1 parameter is used as a kind of planet identifier, but this may not be needed //System.Random rand = new System.Random((int)WorldManager.hash.GetHash(su.u, su.v, (int)su.side, 1)); System.Random rand = RandomHandler.surfaceRandom(su); //NOTE: all objects that are in the rect list are always in the radial list //create a list of radial collisions //(x,y,radius) List <RadialCol> radCols = new List <RadialCol>(); //create a list of rectangular collisions //List<Vector4> rectCols = new List<Vector4>(); //first add all roads, then buildings, then natural things //build all transportation segments and add them to the collision lists //buildTransport(su); //create a list of samples List <Sub> samples = new List <Sub>(); for (int i = 0; i < numSamples; i++) { SurfacePos surfPos = new SurfacePos(su.side, su.u + (float)rand.NextDouble(), su.v + (float)rand.NextDouble()); //convert the surface position to world position Vector3 worldPos = UnitConverter.getWP(surfPos, radius, sideLength); //TODO: make function to only retrieve the substance and not vox val float val; Sub sub; planet.noise.getVoxData(worldPos, out val, out sub); //Debug.Log(sub); samples.Add(sub); } foreach (Blueprint bp in blueprints) { int amount = bp.getAmount(samples, new WorldPos(), rand.NextDouble()); for (int i = 0; i < amount; i++) { //possibly later method to build all object in this su within the blueprint class and return a list //WorldObject wo = bp.buildObject(rand); Mesh mesh = bp.buildObject(rand.Next()); //choose random x and y position within the su float u = (float)rand.NextDouble(); float v = (float)rand.NextDouble(); //choose random rotation(will not be random for things like buildings later) Quaternion surfRot = Quaternion.Euler((float)rand.NextDouble() * 360, (float)rand.NextDouble() * 360, (float)rand.NextDouble() * 360); //the global surfaceposition of the object SurfacePos surfPos = new SurfacePos(su.side, su.u + u, su.v + v); //convert the surface position and rotation to world position and rotation Vector3 worldPos = UnitConverter.getWP(surfPos, radius, sideLength); Quaternion worldRot = getWorldRot(worldPos, surfRot, su.side); //adjust from point on sphere to correct altitude worldPos = planet.noise.altitudePos(worldPos); //build(intantiate) the actual gameobject MobileObjects wo = Build.buildObject <Rock>(worldPos, worldRot); //wo.setReferences(); wo.Render(); wo.setMesh(mesh); sh.objects.Add(wo); //add it to the surface holder list } } /*int count = rand.Next(30); * * * // MyDebug.placeMarker(UnitConverter.getWP(new SurfacePos(su.side, su.u, su.v), radius, sideLength)); * for(int i = 0; i<count; i++) * { * //Vector3 pos = new Vector3( * //choose random x and y position within the su * //Vector2 surfPos = new Vector2((float)rand.NextDouble(), (float)rand.NextDouble()); * float u = (float)rand.NextDouble(); * float v = (float)rand.NextDouble(); * * //choose random rotation(will not be random for things like buildings later) * Quaternion surfRot = Quaternion.Euler(0, (float)rand.NextDouble()*360, 0); * //Debug.Log(surfRot.eulerAngles); * //temp radius of tree used for testing * float wuRadius = 2; * //radius in world units/length of a surface unit = radius in surface units(less than 1) * float suRadius = wuRadius/suLength; * //Debug.Log("suRadius is " + suRadius); * * bool isColliding = false; * foreach(RadialCol oth in radCols) * { * //distance formula(move to struct later) * //if the distance between the two centers - their radii is less than zero, they are colliding * if(Mathf.Sqrt((oth.u-u)*(oth.u-u)+(oth.v-v)*(oth.v-v))-suRadius-oth.radius<0) * { * isColliding = true; * //Debug.Log("samwell"); * break; * } * } * //for the time being, if something is colliding, just discard it * //later it may be moved slightly or completely repositioned * if(isColliding) * { * continue; * } * * //add this obect to the radial collision list * //later, create the RadialCol object initially(replace x y and suRadius) * radCols.Add(new RadialCol(u,v,suRadius)); * * //surfacepos of the tree * SurfacePos treeSurf = new SurfacePos(su.side, su.u + u, su.v + v); * //Debug.Log (u + " " + v + " " + su.u + " " + su.v); * //convert to world unit and rotation * Vector3 worldPos = UnitConverter.getWP(treeSurf, radius, sideLength); * Quaternion worldRot = getWorldRot(worldPos, surfRot, su.side); * //Debug.Log (treeSurf+ " " + worldPos + " " + surfRot.eulerAngles + " " + worldRot); * * //adjust the pos to the correct altitude, later move to function * //worldPos = worldPos.normalized*planet.noise.getAltitude(worldPos); * worldPos = planet.noise.altitudePos(worldPos); * * //GameObject.Instantiate(tree, treeWorld, Quaternion.identity); * //build the tree object(adds it to builtobjects list and maybe eventually add it to the render list * //buildObject<TestTree>(worldPos, worldRot, sh).init(); * * //build(intantiate) the object * WorldObject wo = Build.buildObject<TestTree>(worldPos, worldRot); * wo.Render(); * sh.objects.Add(wo);//add it to the surface holder list * //wo.init();//initailize it (normally has parameters) * * }*/ /*GameObject go = Resources.Load("Test things/rottest") as GameObject; * Vector3 pos = UnitConverter.getWP(new SurfacePos(su.side, su.u+0.5f, su.v+0.5f), radius, sideLength); * Quaternion rot = getWorldRot(pos, Quaternion.identity, su.side); * * GameObject.Instantiate(go, pos, rot);*/ curSH = null; //disconnect reference to avoid possible confusion later/catch errors } //increase the worldunit count of the surface holder sh.wuCount++; }
private void ButtonTestSeed_Click(object sender, EventArgs e) { labelTestSeed.Text = $"{RandomHandler.Next(100, 999)}"; }
private void TextBoxSeed_TextChanged(object sender, EventArgs e) { Config.Instance.Seed = textBoxSeed.Text; RandomHandler.SetSeed(Config.Instance.Seed); }