Esempio n. 1
0
        public IState Play()
        {
            double goalProb = 10.0 / (goalkeeper.GK * 13.0 / 6.0 + 5.0);

            if (StaticRandom.RandDouble() < goalProb)
            {
                /***Goal***/
                return(new GoalState(attTeam, defTeam, defender));
            }
            else
            {
                /***GK saves***/
                switch (StaticRandom.Rand(3))
                {
                case 0:
                    return(new CornerState(attTeam, defTeam));

                case 1:
                    return(new GKStartState(defTeam, attTeam));

                case 2:
                    return(new InboxReboundState(attTeam, defTeam));

                default:
                    return(null);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a fully generated human character.
        /// </summary>
        /// <returns></returns>
        public Human GenerateHuman(Point2D location, int dimension)
        {
            int   health   = StaticRandom.Rand(this.MinHumanHealthPerLevel, this.MaxHumanHealthPerLevel);
            float movement = (float)StaticRandom.Rand(this.MinHumanMovement, this.MaxHumanMovement);

            return(new Human(health, movement, location, dimension));
        }
Esempio n. 3
0
        public void Eval()
        {
            population.Sort((a, b) => {
                if (a.Measure() > b.Measure())
                {
                    return(-1);
                }
                else if (a.Measure() == b.Measure())
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            });
            List <T> newPopulation = population.GetRange(0, Math.Max(1, (int)(PopulationSize * top)));

            newPopulation.AddRange(ParallelEnumerable.Range(0, PopulationSize - Math.Max(1, (int)(PopulationSize * top))).Select(i =>
            {
                if (StaticRandom.Rand(10) <= 2)
                {
                    return(creatorFunction());
                }
                return(mateFunction(population[i], population[GlobalImageData.rand.Next(0, Math.Max(1, (int)(PopulationSize * reproduction)))]));
            }
                                                                                                                                 ));
            population.Clear();
            population = newPopulation;
        }
Esempio n. 4
0
        protected override void GenerateDetails(ProtoArray <Chunk> map, Random random)
        {
            int chunkWidth  = map.Width;
            int chunkHeight = map.Height;

            int chunkX = StaticRandom.Rand(0, chunkWidth);
            int chunkY = StaticRandom.Rand(0, chunkHeight);

            int x = StaticRandom.Rand(0, Chunk.Width);
            int y = StaticRandom.Rand(0, Chunk.Height);

            while (map[chunkX, chunkY].Tiles[x, y].Resources != null)
            {
                chunkX = StaticRandom.Rand(0, chunkWidth);
                chunkY = StaticRandom.Rand(0, chunkHeight);

                x = StaticRandom.Rand(0, Chunk.Width);
                y = StaticRandom.Rand(0, Chunk.Height);
            }

            HumanFactory hFactory       = new HumanFactory();
            Point2D      entityLocation = new Point2D(((chunkX * Chunk.Width) + x), (chunkY * Chunk.Height) + y);
            Human        human          = hFactory.GenerateHuman(entityLocation, this.Dimension);

            map[chunkX, chunkY].Creatures.Add(human);
        }
Esempio n. 5
0
        public IState Play()
        {
            double accProb = goalkeeper.LPS / 20.1;

            if (StaticRandom.RandDouble() < accProb)
            {
                switch (StaticRandom.Rand(4))
                {
                case 0:
                    return(new AttackCentreState(attTeam, defTeam, "counter"));

                case 1:
                    return(new AttackSideState(attTeam, defTeam, 'l', "counter"));

                case 2:
                    return(new AttackSideState(attTeam, defTeam, 'r', "counter"));

                case 3:
                    return(new CentrePitchHeaderState(attTeam, defTeam));

                default:
                    return(null);
                }
            }
            else
            {
                return(new NoMomentsState(attTeam, defTeam));
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Finds a random location that can be walked upon by a creature.
        /// </summary>
        /// <param name="dimension"></param>
        /// <returns></returns>
        public static Point2D FindRandomLocation(int dimension)
        {
            Dimension dim = World.Data.World.Dimensions[dimension];

            //The coordinates of the random chunk
            int randomChunkX = StaticRandom.Rand(0, dim.Width);
            int randomChunkY = StaticRandom.Rand(0, dim.Height);

            //The coordinates of the tile within the chunk
            int randomX = StaticRandom.Rand(0, Chunk.Width);
            int randomY = StaticRandom.Rand(0, Chunk.Height);

            //The map coordinates of where to spawn the creature.
            int x = (randomChunkX * Chunk.Width) + randomX;
            int y = (randomChunkY * Chunk.Height) + randomY;

            if (dim[x, y].IsWalkable)
            {
                return(new Point2D(x, y));
            }
            else
            {
                return(WorldUtil.FindRandomLocation(dimension));
            }
        }
Esempio n. 7
0
        private static StaticTexture GetVisual()
        {
            int    r = StaticRandom.Rand(0, 4);
            string textureName;

            switch (r)
            {
            case 0:
                textureName = TextureLoader.TextureGrass1;
                break;

            case 1:
                textureName = TextureLoader.TextureGrass2;
                break;

            case 2:
                textureName = TextureLoader.TextureGrass3;
                break;

            default:
                textureName = TextureLoader.TextureGrass4;
                break;
            }

            return(new StaticTexture(AssetManager.GetTextureIndex(textureName), RenderLayer.GrassBase));
        }
Esempio n. 8
0
        private string GetRandomGrassTexture()
        {
            int    r = StaticRandom.Rand(0, 4);
            string ret;

            switch (r)
            {
            case 1:
                ret = TextureLoader.TextureGrass2;
                break;

            case 2:
                ret = TextureLoader.TextureGrass3;
                break;

            case 3:
                ret = TextureLoader.TextureGrass4;
                break;

            default:
                ret = TextureLoader.TextureGrass1;
                break;
            }

            return(ret);
        }
Esempio n. 9
0
        public static T PickRandom <T>(this IEnumerable <T> enumerable)
        {
            Guard.Argument(() => !enumerable.IsNullOrEmpty(), nameof(enumerable));

            var list = enumerable.ToList();

            return(list[StaticRandom.Rand() % list.Count]);
        }
Esempio n. 10
0
        public IState Play()
        {
            double successProb = (2 * (attacker.SPS + attacker.LPS) + 10) / 100.0;

            if (StaticRandom.RandDouble() > successProb)
            {
                /***Pass is intercepted***/
                switch (StaticRandom.Rand(3))
                {
                case 0:
                    if (counter)
                    {
                        return(new AttackSideState(defTeam, attTeam, 'l'));
                    }
                    else
                    {
                        return(new AttackSideState(defTeam, attTeam, 'l', "counter"));
                    }

                case 1:
                    if (counter)
                    {
                        return(new AttackSideState(defTeam, attTeam, 'r'));
                    }
                    else
                    {
                        return(new AttackSideState(defTeam, attTeam, 'r', "counter"));
                    }

                case 2:
                    return(new ClearenceState(defTeam, attTeam));

                default:
                    return(null);
                }
            }
            else if (StaticRandom.RandDouble() > 0.5)
            {
                /***Pass***/
                if (counter)
                {
                    return(new AttackSideState(attTeam, defTeam, 'l', "counter"));
                }
                else
                {
                    return(new AttackSideState(attTeam, defTeam, 'l'));
                }
            }
            else
            if (counter)
            {
                return(new AttackSideState(attTeam, defTeam, 'r', "counter"));
            }
            else
            {
                return(new AttackSideState(attTeam, defTeam, 'r'));
            }
        }
Esempio n. 11
0
        public IState Play()
        {
            double defProb = (2.25 * defender.DEF + 5) / 100;

            if (StaticRandom.RandDouble() < defProb)
            {
                /***Pass is intercepted***/
                switch (StaticRandom.Rand(3))
                {
                case 0:
                    if (left)
                    {
                        return(new AttackSideState(defTeam, attTeam, 'r', "counter"));
                    }
                    else
                    {
                        return(new AttackSideState(defTeam, attTeam, 'l', "counter"));
                    }

                case 1:
                    if (left)
                    {
                        return(new ThrowInState(attTeam, defTeam, 'l'));
                    }
                    else
                    {
                        return(new ThrowInState(attTeam, defTeam, 'r'));
                    }

                case 2:
                    return(new ClearenceState(defTeam, attTeam));

                default:
                    return(null);
                }
            }
            else
            /***Not intercepted***/
            {
                double y            = attTeam.All(Position.CF, Position.AM).Max(x => x.HEA);
                double boxCrossProb = 1 + 0.00061 * y * y * y - 0.0024 * y * y + 0.004 * y - 1;
                double lowCrossProb = 1 + 0.00085 * y * y * y - 0.0243 * y * y - 0.054 * y + 3;
                lowCrossProb += boxCrossProb;

                /***Cross***/
                if (StaticRandom.RandDouble(0, lowCrossProb) < boxCrossProb)
                {
                    return(new BoxCrossAttemptState(attTeam, defTeam, newAttacker, newDefender, left, counter));
                }
                /***Low cross***/
                else
                {
                    return(new LowCrossAttemptState(attTeam, defTeam, newAttacker, newDefender, left, counter));
                }
            }
        }
Esempio n. 12
0
 public static void LightShuffle <T>(this IList <T> cards)
 {
     for (int i = cards.Count - 1; i > 0; i--)
     {
         int j = StaticRandom.Rand(i + 1);
         var t = cards[i];
         cards[i] = cards[j];
         cards[j] = t;
     }
 }
Esempio n. 13
0
        private static string GenerateSalt()
        {
            const string pool = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

            return(new string(
                       Enumerable.Repeat(pool, 32)
                       .Select(s => s[StaticRandom.Rand(min: 0, max: s.Length)])
                       .ToArray()
                       ));
        }
Esempio n. 14
0
 static ControllerSettings GenerateRandomControllerSettings()
 {
     return(new ControllerSettings
     {
         BaseBet = StaticRandom.Rand(20),
         Target = (double)(StaticRandom.Rand(100) + 10) / 10,
         Multiplier = (double)(StaticRandom.Rand(300) + 50) / 100,
         PassGames = StaticRandom.Rand(10),
         Reducer = (double)StaticRandom.Rand(10) / 1000,
     });
 }
Esempio n. 15
0
        /// <summary>
        /// Returns a fully generated human character.
        /// </summary>
        /// <returns></returns>
        public Human GenerateHuman(Point2D location, int dimension, Guid playerID)
        {
            int   health   = StaticRandom.Rand(this.MinHumanHealthPerLevel, this.MaxHumanHealthPerLevel);
            float movement = (float)StaticRandom.Rand(this.MinHumanMovement, this.MaxHumanMovement);

            Human h = new Human(health, movement, location, dimension, playerID, this.GenerateRandomName());

            h.CreatureSkills.Add(new HarvestingSkill(new DataTypes.Attribute.ComboAttribute(1, 1), true));

            return(h);
        }
Esempio n. 16
0
 private EllipticArea GenerateRandomElipticArea()
 {
     return(new EllipticArea()
     {
         A = StaticRandom.Rand(1000) / 1000d,
         B = StaticRandom.Rand(1000) / 1000d,
         R = StaticRandom.Rand(500) / 1000d,
         U = StaticRandom.Rand(1000) / 1000d,
         V = StaticRandom.Rand(1000) / 1000d,
         Angle = StaticRandom.Rand(365) * Math.PI / 180,
     });
 }
Esempio n. 17
0
        public static void Shuffle <T>(this IList <T> collection)
        {
            int n = collection.Count;

            while (n > 1)
            {
                n--;
                int k     = StaticRandom.Rand(n + 1);
                T   value = collection[k];
                collection[k] = collection[n];
                collection[n] = value;
            }
        }
Esempio n. 18
0
        public static void Shuffle <T>(this IList <T> collection, int start, int end)
        {
            int n = end;

            while (n > start + 1)
            {
                n--;
                int k     = StaticRandom.Rand(start, n + 1);
                T   value = collection[k];
                collection[k] = collection[n];
                collection[n] = value;
            }
        }
Esempio n. 19
0
        // https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
        /// <summary>
        /// In place shuffle
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sequence"></param>
        /// <returns></returns>
        public static IList <T> Shuffle <T>(this IList <T> sequence)
        {
            for (int i = 0; i < sequence.Count; i++)
            {
                // for truly random
                int j    = StaticRandom.Rand(0, i + 1); // i+1 exclusive upper bound
                T   temp = sequence[i];
                sequence[i] = sequence[j];
                sequence[j] = temp;
            }

            return(sequence);
        }
Esempio n. 20
0
        private static string GetRandomDirtTexture()
        {
            int r = StaticRandom.Rand(0, 2);

            if (r == 0)
            {
                return(TextureLoader.TextureDirt1);
            }
            else
            {
                return(TextureLoader.TextureDirt2);
            }
        }
Esempio n. 21
0
        public static T GetRandomElementWithWeights <T>(this IEnumerable <T> collection)
        {
            int n = collection.Count();
            int k = StaticRandom.Rand(n * (n + 1) / 2);

            for (int i = 0; i < n; i++)
            {
                if (k < (i + 1) * (2 * n - i) / 2)
                {
                    return(collection.ElementAt(i));
                }
            }
            return(default(T));
        }
Esempio n. 22
0
        public IState Play()
        {
            Stats.fks++;
            double shotProb = attacker.SP / 25.0;
            double goalProb = (attacker.SP - goalkeeper.GK + 3) / 22.0;

            if (StaticRandom.RandDouble() > shotProb)
            {
                /***Miss or shot into the wall***/
                switch (StaticRandom.Rand(3))
                {
                case 0:
                    return(new ClearenceState(defTeam, attTeam));

                case 1:
                    return(new OutboxReboundState(attTeam, defTeam));

                case 2:
                    return(new GoalKickState(defTeam, attTeam));

                default:
                    return(null);
                }
            }
            if (StaticRandom.RandDouble() < goalProb)
            /***Shot on goal and GK doesn't save***/
            {
                Stats.fk_goal++;
                return(new GoalState(attTeam, defTeam, attacker));
            }
            else
            {
                /***GK saves***/
                Stats.fk_saves++;
            }
            switch (StaticRandom.Rand(3))
            {
            case 0:
                return(new GKStartState(defTeam, attTeam));

            case 1:
                return(new InboxReboundState(attTeam, defTeam));

            case 2:
                return(new CornerState(attTeam, defTeam));

            default:
                return(null);
            }
        }
Esempio n. 23
0
        public override ProtoArray <Tile> GenerateDetails(ProtoArray <Tile> map, Random r)
        {
            int xSize = map.Width;
            int ySize = map.Height;

            int x = StaticRandom.Rand(0, xSize);
            int y = StaticRandom.Rand(0, ySize);

            HumanFactory hFactory = new HumanFactory();

            map[x, y].Living = (hFactory.GenerateHuman(new Point(x, y)));

            return(map);
        }
Esempio n. 24
0
        /// <summary>
        /// Generates a random human name.
        /// </summary>
        /// <returns></returns>
        private string GenerateRandomName()
        {
            string[] names =
            {
                "James",
                "John",
                "Jon",
                "Jill",
                "Jane"
            };

            int max = names.Length;

            return(names[StaticRandom.Rand(0, max)]);
        }
Esempio n. 25
0
        public IState Play()
        {
            if (StaticRandom.RandDouble() < goalkeeper.HEA / 150.0)
            {
                /***GK interceptes/cleares/to the corner***/
                switch (StaticRandom.Rand(3))
                {
                case 0:
                    return(new GKStartState(defTeam, attTeam));

                case 1:
                    return(new ClearenceState(defTeam, attTeam));

                case 2:
                    return(new CornerState(attTeam, defTeam));

                default:
                    return(null);
                }
            }
            double shotProb    = 2.0;
            double clearProb   = 1.0;
            double ownShotProb = 0.05;

            shotProb  += (attacker.HEA + attacker.STR - 20) / 20.0;
            clearProb += (defender.HEA + defender.STR - 20) / 20.0;

            clearProb   += shotProb;
            ownShotProb += clearProb;

            double p = StaticRandom.RandDouble(0, ownShotProb);

            if (p < shotProb)
            {
                /***Header**/
                return(new ShotState(attTeam, defTeam, attacker, "header", assist));
            }
            else if (p < clearProb)
            {
                /***Defender cleares***/
                return(new ClearenceState(defTeam, attTeam));
            }
            else
            {
                /***Own shot***/
                return(new OwnShotState(attTeam, defTeam, defender));
            }
        }
Esempio n. 26
0
        private string GetRandomStoneTexture()
        {
            int    r = StaticRandom.Rand(0, 2);
            string ret;

            if (r == 0)
            {
                ret = TextureLoader.TextureStone1;
            }
            else
            {
                ret = TextureLoader.TextureStone2;
            }

            return(ret);
        }
Esempio n. 27
0
        protected override void GenerateDetails(ProtoArray <Chunk> map, Random r)
        {
            int chunkWidth  = map.Width;
            int chunkHeight = map.Height;

            int chunkX = StaticRandom.Rand(0, chunkWidth);
            int chunkY = StaticRandom.Rand(0, chunkHeight);

            int x = StaticRandom.Rand(0, Chunk.Width);
            int y = StaticRandom.Rand(0, Chunk.Height);

            HumanFactory hFactory = new HumanFactory();
            Point2D      location = new Point2D(((chunkX * Chunk.Width) + x), (chunkY * Chunk.Height) + y);

            map[chunkX, chunkY].Creatures.Add(hFactory.GenerateHuman(location, this.Dimension));
        }
Esempio n. 28
0
        private string GetRandomDirtTexture()
        {
            int    r = StaticRandom.Rand(0, 2);
            string ret;

            if (r == 0)
            {
                ret = TextureLoader.TextureDirt1;
            }
            else
            {
                ret = TextureLoader.TextureDirt2;
            }

            return(ret);
        }
Esempio n. 29
0
        private void eventHandler()
        {
            bool end = false;

            sechalf = false;
            int firstHalfEnd = StaticRandom.Rand(45, 49);
            int matchEnd     = StaticRandom.Rand(90, 97);

            while (!end)
            {
                setState(state.Play());
                switch (state.Type())
                {
                case State.ATTACK_CENTRE:
                case State.ATTACK_SIDE:
                case State.FREE_KICK:
                case State.CORNER:
                case State.PENALTY:
                case State.GOAL:
                    minute += 1;
                    break;

                case State.COUNTER_ATTACK_CENTRE:
                case State.COUNTER_ATTACK_SIDE:
                    minute += 0.5;
                    break;

                case State.NO_MOMENTS:
                    minute += StaticRandom.RandDouble(1, 4);
                    break;

                default:
                    break;
                }
                if (minute >= firstHalfEnd && !sechalf)
                {
                    sechalf = true;
                    minute  = 45;
                    setState(new StartState(awayTeam, homeTeam));
                    isHomeTeamAttacking = false;
                }
                if (minute >= matchEnd)
                {
                    end = true;
                }
            }
        }
Esempio n. 30
0
        public IState Play()
        {
            double successProb = (2.25 * attacker.SPS + 5) / 100.0;

            if (counter)
            {
                successProb += 2.25 * (20 - defTeam.Any(Position.CM, Position.DM).DEF / 6.0) / 100.0;
            }
            else
            {
                successProb += 2.25 * (20 - defTeam.Any(Position.CM, Position.DM).DEF / 4.0) / 100.0;
            }

            if (StaticRandom.RandDouble() > successProb)
            {
                /***Pass is intercepted***/
                switch (StaticRandom.Rand(3))
                {
                case 0:
                case 1:
                    if (counter)
                    {
                        return(new AttackCentreState(defTeam, attTeam));
                    }
                    else
                    {
                        return(new AttackCentreState(defTeam, attTeam, "counter"));
                    }

                case 2:
                    return(new ClearenceState(defTeam, attTeam));

                default:
                    return(null);
                }
            }
            else
            /***Not intercepted - pass***/
            if (counter)
            {
                return(new AttackCentreState(attTeam, defTeam, "counter"));
            }
            else
            {
                return(new AttackCentreState(attTeam, defTeam));
            }
        }