public override Hash GetRandomNumber(Hash input) { var randomNumberRequestInformation = State.RandomNumberInformationMap[input]; if (randomNumberRequestInformation == null || randomNumberRequestInformation.TargetRoundNumber == 0 || randomNumberRequestInformation.ExpectedBlockHeight > Context.CurrentHeight || !TryToGetRoundNumber(out var currentRoundNumber)) { return(Hash.Empty); } var targetRoundNumber = randomNumberRequestInformation.TargetRoundNumber; var provider = new RandomNumberProvider(randomNumberRequestInformation); while (targetRoundNumber <= currentRoundNumber) { if (TryToGetRoundInformation(targetRoundNumber, out var round)) { var randomHash = provider.GetRandomNumber(round); if (randomHash != Hash.Empty) { var finalRandomHash = Hash.FromTwoHashes(randomHash, input); Context.Fire(new RandomNumberGenerated { TokenHash = input, RandomHash = finalRandomHash }); return(finalRandomHash); } targetRoundNumber = targetRoundNumber.Add(1); } } return(Hash.Empty); }
public void Attack(IWeapon weapon, ICreature attacker, ICreature target, World world) { MessageTypes messageTypeToUse; bool attackHits = RandomNumberProvider.CheckIfChanceOccurs(_chanceOfHit); int amountOfDamage = RandomNumberProvider.GetRandomNumber(_minimumDamage, _maximumDamage); if (attacker.IsPlayer()) { messageTypeToUse = MessageTypes.PlayerAttack; } else { messageTypeToUse = MessageTypes.CreatureAttack; } if (attackHits) { target.Health.Current -= amountOfDamage; Announcer.Instance.Announce(attacker.Name + " hits " + target.Name + " for " + amountOfDamage + " damage!", MessageTypes.CreatureAttack); } else { Announcer.Instance.Announce(attacker.Name + " misses " + target.Name + "!", MessageTypes.CreatureAttack); } world.AddSpecialEffectToWorld(new Fireball(attacker.WorldIndex, target.WorldIndex, world)); }
public List <Vector <double> > GetData() { Point A = new Point(RandomNumberProvider.GetRandomNumber(-10, 10), RandomNumberProvider.GetRandomNumber(-10, 10)); Point B = new Point(RandomNumberProvider.GetRandomNumber(-10, 10), RandomNumberProvider.GetRandomNumber(-10, 10)); Point C = new Point(RandomNumberProvider.GetRandomNumber(-10, 10), RandomNumberProvider.GetRandomNumber(-10, 10)); List <Vector <double> > data = new List <Vector <double> >(); for (int i = 0; i < NumberOfPoints; i++) { var a = RandomNumberProvider.GetRandomNumber(0, 1); var b = RandomNumberProvider.GetRandomNumber(0, 1); if (a + b > 1) { a = 1 - a; b = 1 - b; } var c = 1 - a - b; var rndX = (a * A.x) + (b * B.x) + (c * C.x); var rndY = (a * A.y) + (b * B.y) + (c * C.y); data.Add(Vector <double> .Build.DenseOfArray(new[] { rndX, rndY })); } return(data); }
public void PositionNeurons(BackpropagationTrainingParameters trainingParameters, List <RadialNeuron> radialNeurons) { trainingParameters.Validate(); var inputPoints = trainingParameters.InputPoints; List <int> randomPositions = new List <int>(); for (int i = 0; i < radialNeurons.Count; i++) { int randomPosition; do { randomPosition = (int)RandomNumberProvider.GetRandomNumber(0, inputPoints.Count); } while (randomPositions.Exists(e => e == randomPosition)); randomPositions.Add(randomPosition); } int radialIndex = 0; foreach (var index in randomPositions) { for (int i = 0; i < inputPoints[0].Input.Count; i++) { radialNeurons[radialIndex].Position[i] = inputPoints[index].Input[i]; } radialIndex++; } }
public void TakeTurn(ICreature creature, World world) { _countdownToNextTurn -= 1; if (_countdownToNextTurn <= 0) { _countdownToNextTurn = _speed; bool turnOver = false; while (turnOver != true) { int roll = RandomNumberProvider.GetRandomNumber(1, 4); if (roll == 1) { turnOver = world.MoveCreatureInDirectionSuccessful(Direction.North, creature); } else if (roll == 2) { turnOver = world.MoveCreatureInDirectionSuccessful(Direction.South, creature); } else if (roll == 3) { turnOver = world.MoveCreatureInDirectionSuccessful(Direction.East, creature); } else if (roll == 4) { turnOver = world.MoveCreatureInDirectionSuccessful(Direction.West, creature); } } } }
private void AttackWithFire(ICreature attacker, ref ICreature creature) { int damage = RandomNumberProvider.GetRandomNumber(4, 10); Announcer.Instance.Announce(attacker.Name + " burned " + creature.Name + " with fire for " + damage + "damage", MessageTypes.CreatureAttack); creature.Health.Current -= damage; }
public void AttackCreature(ICreature attacker, ref ICreature creature) { int damage = RandomNumberProvider.GetRandomNumber(1, 2); Announcer.Instance.Announce(attacker.Name + " inflicted " + damage + " damage to " + creature.Name, MessageTypes.CreatureAttack); creature.Health.Current -= damage; }
public override Hash GetRandomNumber(Hash input) { var randomNumberRequestInformation = State.RandomNumberInformationMap[input]; if (randomNumberRequestInformation == null) { Assert(false, "Random number token not found."); // Won't reach here. return(Hash.Empty); } if (randomNumberRequestInformation.TargetRoundNumber == 0) { Assert(false, "Random number token was cleared."); // Won't reach here. return(Hash.Empty); } if (randomNumberRequestInformation.ExpectedBlockHeight > Context.CurrentHeight) { Assert(false, "Still preparing random number."); } var roundNumber = randomNumberRequestInformation.TargetRoundNumber; TryToGetRoundNumber(out var currentRoundNumber); var provider = new RandomNumberProvider(randomNumberRequestInformation); while (roundNumber <= currentRoundNumber) { if (TryToGetRoundInformation(roundNumber, out var round)) { var randomHash = provider.GetRandomNumber(round); if (randomHash != Hash.Empty) { var finalRandomHash = Hash.FromTwoHashes(randomHash, input); Context.Fire(new RandomNumberGenerated { TokenHash = input, RandomHash = finalRandomHash }); return(finalRandomHash); } roundNumber = roundNumber.Add(1); } else { Assert(false, "Still preparing random number, try later."); } } Assert(false, "Still preparing random number, try later."); // Won't reach here. return(Hash.Empty); }
public void AddParticles(Vector2 where, Vector2 direction) { // the number of particles we want for this effect is a random number // somewhere between the two constants specified by the subclasses. int numParticles = RandomNumberProvider.GetRandomNumber(minNumParticles, maxNumParticles); // create that many particles, if you can. for (int i = 0; i < numParticles && freeParticles.Count > 0; i++) { // grab a particle from the freeParticles queue, and Initialize it. Particle p = freeParticles.Dequeue(); InitializeParticle(p, where, direction); } }
public void InitNeuron(int radialNeuronCount, double minWeight, double maxWeight) { var weights = new double[radialNeuronCount]; for (int i = 0; i < radialNeuronCount; i++) { weights[i] = RandomNumberProvider.GetRandomNumber(minWeight, maxWeight); } Weights = Vector <double> .Build.DenseOfArray(weights); WeightsDeltas = Vector <double> .Build.DenseOfArray(new double[radialNeuronCount]); BiasWeight = RandomNumberProvider.GetRandomNumber(minWeight, maxWeight); BiasWeightDelta = 0; }
public bool CastSpell(ICreature caster, Vector2 targetWorldIndex, AreaOfEffect affectedArea, World world) { int healthRestored = RandomNumberProvider.GetRandomNumber(_minimumHealthToRestore, _maximumHealthToRestore); if (caster.Health.Current + healthRestored >= caster.Health.Maximum) { caster.Health.Current = caster.Health.Maximum; Announcer.Instance.Announce(caster.Name + " returned to full health!", MessageTypes.Spell); } else { caster.Health.Current += healthRestored; Announcer.Instance.Announce(caster.Name + " recovered " + healthRestored + " health.", MessageTypes.Spell); } world.AddSpecialEffectToWorld(new Heal(caster.WorldIndex, caster.WorldIndex, world)); return(true); }
public bool CastSpell(ICreature caster, Vector2 targetWorldIndex, AreaOfEffect affectedArea, World world) { affectedWorldIndicies = affectedArea.GetAffectedWorldIndices(targetWorldIndex); damage = RandomNumberProvider.GetRandomNumber(_minimumDamage, _maximumDamage); foreach (KeyValuePair <Vector2, double> affectedWorldIndex in affectedWorldIndicies) { ICreature target = world.GetCreatureAtIndex(affectedWorldIndex.Key); if (target != null) { int actualDamage = (int)(damage * affectedWorldIndex.Value); Announcer.Instance.Announce(target.Name + " was hit by a fireball for " + actualDamage + " damage!", MessageTypes.Spell); target.Health.Current -= actualDamage; } } world.AddSpecialEffectToWorld(new Inferno(targetWorldIndex, world, affectedArea)); return(true); }
public void TakeTurn(ICreature creature, World world) { _countdownToNextTurn -= 1; if (_countdownToNextTurn <= 0) { _countdownToNextTurn = _speed; bool turnOver = false; if (world.CanPlayerSeeWorldIndex(creature.WorldIndex) && RandomNumberProvider.CheckIfChanceOccurs(25) && world.GetStraightLineDistance(creature.WorldIndex, world.Player.WorldIndex) <= 5) { _spell.CastSpell(creature, world.Player.WorldIndex); } else { while (turnOver != true) { int roll = RandomNumberProvider.GetRandomNumber(1, 4); if (roll == 1) { turnOver = world.MoveCreatureInDirectionSuccessful(Direction.North, creature); } else if (roll == 2) { turnOver = world.MoveCreatureInDirectionSuccessful(Direction.South, creature); } else if (roll == 3) { turnOver = world.MoveCreatureInDirectionSuccessful(Direction.East, creature); } else if (roll == 4) { turnOver = world.MoveCreatureInDirectionSuccessful(Direction.West, creature); } } } } }