public static NeuralNetworkBuilder For(
     NeuralNetworkContext context,
     IProvideRandomNumberGeneration randomNumberGenerater = null)
 {
     randomNumberGenerater = randomNumberGenerater ?? RandomNumberProvider.For(new Random(1));
     return(new NeuralNetworkBuilder(context, randomNumberGenerater));
 }
Exemple #2
0
        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));
        }
Exemple #3
0
        /// <summary>
        /// Initializes a particle
        /// </summary>
        /// <param name="p"></param>
        /// <param name="where"></param>
        /// <param name="direction">set to null for a random direction for each particle</param>
        protected virtual void InitializeParticle(Particle p, Vector2 where, Vector2 direction)
        {
            if (direction == null)
            {
                direction = PickRandomDirection();
            }

            // pick some random values for our particle
            float velocity =
                RandomNumberProvider.RandomBetween(minInitialSpeed, maxInitialSpeed);
            float acceleration =
                RandomNumberProvider.RandomBetween(minAcceleration, maxAcceleration);
            float lifetime =
                RandomNumberProvider.RandomBetween(minLifetime, maxLifetime);
            float scale =
                RandomNumberProvider.RandomBetween(minScale, maxScale);
            float rotationSpeed =
                RandomNumberProvider.RandomBetween(minRotationSpeed, maxRotationSpeed);

            // then initialize it with those random values. initialize will save those,
            // and make sure it is marked as active.
            p.Initialize(
                where, velocity * direction, acceleration * direction,
                lifetime, scale, rotationSpeed);
        }
        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;
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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 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);
             }
         }
     }
 }
Exemple #8
0
        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++;
            }
        }
Exemple #9
0
        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);
        }
Exemple #10
0
 public void ApplyAdjustment()
 {
     if (RandomNumberProvider.Next() < RenewalFactor)
     {
         Weight = RandomNumberProvider.Next();
     }
     Weight += _cumulatedAdjustment;
     _cumulatedAdjustment = 0;
 }
        public AttackDto Attack()
        {
            AttackDto attackDto = new AttackDto
            {
                Damage             = RandomNumberProvider.GetNumber(15) + 25,
                ShouldBreakDefence = RandomNumberProvider.GetNumber(4) == 0
            };

            return(attackDto);
        }
Exemple #12
0
 public void AdjustWeight()
 {
     if (RandomNumberProvider.Next() < RenewalFactor)
     {
         Weight = RandomNumberProvider.Next();
     }
     {
         Weight += GetAdjustment();
     }
 }
Exemple #13
0
        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);
        }
Exemple #14
0
        public void TestMethod4()
        {
            var random = new Random();

            for (int i = 0; i < 10; i++)
            {
                Thread.Sleep(100);
                var inputs = new Random().NextDouble();
                Debug.WriteLine("Random is: " + RandomNumberProvider.Next());
            }
            Debug.WriteLine("End");
        }
        public SlotMachine()
        {
            InitializeComponent();

            this.randomProvider           = new RandomNumberProvider();
            this.matrixProvider           = new MatrixProvider();
            this.slotMachineItemsProvider = new SlotMachineItemsProvider();

            var dialogResult = Prompt.ShowEnterCreditsDialog("Deposit amount", "Enter Deposit");

            SetCreditsAmount(dialogResult);

            SetDefaultSlotMachineImages();
        }
Exemple #16
0
        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);
            }
        }
Exemple #17
0
 public void Initialize(Vector2 position, Vector2 velocity, Vector2 acceleration,
     float lifetime, float scale, float rotationSpeed)
 {
     this.InitialPosition = position;
     this.Position = position;
     this.Velocity = velocity;
     this.InitialVelocity = velocity;
     this.Acceleration = acceleration;
     this.Lifetime = lifetime;
     this.Scale = scale;
     this.RotationSpeed = rotationSpeed;
   
     this.TimeSinceStart = 0.0f;
     
     this.Rotation = RandomNumberProvider.RandomBetween(0, MathHelper.TwoPi);
 }
Exemple #18
0
        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;
        }
Exemple #19
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);
        }
Exemple #20
0
        private string GetUniqueKey(int maxSize)
        {
            var chars = "ABCDEFGHMPRSTUVWXYZ23456789".ToCharArray();
            var data  = new byte[1];

            RandomNumberProvider.GetNonZeroBytes(data);
            data = new byte[maxSize];
            RandomNumberProvider.GetNonZeroBytes(data);

            var result = new StringBuilder(maxSize);

            foreach (var b in data)
            {
                result.Append(chars[b % chars.Length]);
            }
            return(result.ToString());
        }
Exemple #21
0
        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);
        }
Exemple #22
0
        public static void FillCardAccountsWithFakeData(AtmEntities dbContext, CardAccountRepository cardAccountsRepo, IList <int> cardHolderIds)
        {
            dbContext.Configuration.AutoDetectChangesEnabled = false;
            dbContext.Configuration.ValidateOnSaveEnabled    = false;

            var randomDataProvider    = new RandomDataProvider();
            var numberProvider        = RandomNumberProvider.GetInstance();
            var registeredCardNumbers = new HashSet <long>();
            var currentCardNumbers    = cardAccountsRepo.GetAll().Select(ca => ca.CardNumber).ToArray();
            int currentCardsCount     = 0;

            foreach (var number in currentCardNumbers)
            {
                if (string.IsNullOrEmpty(number))
                {
                    continue;
                }

                registeredCardNumbers.Add(long.Parse(number));
                currentCardsCount += 1;
            }

            int length = FakeDataCount - currentCardsCount;

            for (int i = 0; i < length; i++)
            {
                CardAccount currentCardAccount = GenerateCardAccount(registeredCardNumbers, cardHolderIds, numberProvider, randomDataProvider);

                cardAccountsRepo.Insert(currentCardAccount);

                if (i % 133 == 0) // Randomly chosen value
                {
                    dbContext.SaveChanges();
                }
            }

            dbContext.Configuration.AutoDetectChangesEnabled = true;
            dbContext.Configuration.ValidateOnSaveEnabled    = true;
        }
Exemple #23
0
        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);
                        }
                    }
                }
            }
        }
 public bool Defend()
 {
     return(RandomNumberProvider.GetNumber(4) == 0);
 }
Exemple #25
0
        protected virtual Vector2 PickRandomDirection()
        {
            float angle = RandomNumberProvider.RandomBetween(0, MathHelper.TwoPi);

            return(new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)));
        }
Exemple #26
0
 public HandClassificator()
 {
     this.actions = new GameActions();
     this.random  = new RandomNumberProvider();
 }
 private void MethodInitialize()
 {
     Random rnd = new Random();
     this.rndNumProv = new RandomNumberProvider(rnd);
 }
Exemple #28
0
 public CardCombinations()
 {
     this.handClassificator = new HandClassificator();
     this.random            = new RandomNumberProvider();
 }
Exemple #29
0
 public Link(INeuron start, INeuron end)
 {
     this.start = start;
     this.end   = end;
     Weight     = RandomNumberProvider.Next();
 }