예제 #1
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));
            }
        }
예제 #2
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);
                }
            }
        }
예제 #3
0
        public IState Play()
        {
            double shotProb    = 1.0;
            double clearProb   = 1.0;
            double ownShotProb = 0.05;

            shotProb  += (attacker.PAC + attacker.FIN - 20) / 20.0;
            clearProb += (defender.DEF + defender.PAC - 20) / 20.0;

            clearProb   += shotProb;
            ownShotProb += clearProb;

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

            if (p < shotProb)
            {
                return(new InboxShotAttemptState(attTeam, defTeam, attacker, defTeam.Any(Position.CB), assist));
            }
            else if (p < clearProb)
            {
                return(new ClearenceState(defTeam, attTeam));
            }
            else
            {
                return(new OwnShotState(attTeam, defTeam, defender));
            }
        }
예제 #4
0
        public IState Play()
        {
            if (StaticRandom.RandDouble() > (server.SP + server.LPS) / 40.0)
            {
                return(new GoalKickState(defTeam, attTeam));
            }

            double shotProb    = 1.0;
            double clearProb   = 2.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)
            {
                return(new ShotState(attTeam, defTeam, attacker, "header", server));
            }
            else if (p < clearProb)
            {
                return(new ClearenceState(defTeam, attTeam));
            }
            else
            {
                return(new OwnShotState(attTeam, defTeam, defender));
            }
        }
예제 #5
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'));
            }
        }
예제 #6
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));
                }
            }
        }
예제 #7
0
        public IState Play()
        {
            double accProb = goalkeeper.LPS / 20.1;

            if (StaticRandom.RandDouble() < accProb)
            {
                return(new CentrePitchHeaderState(attTeam, defTeam));
            }
            else
            {
                return(new NoMomentsState(attTeam, defTeam));
            }
        }
예제 #8
0
        public IState Play()
        {
            double successProb = 0.5 * (attacker.HEA + attacker.STR) / (defender.STR + defender.HEA);

            if (StaticRandom.RandDouble() < successProb)
            {
                return(new AttackCentreState(attTeam, defTeam));
            }
            else
            {
                return(new NoMomentsState(attTeam, defTeam));
            }
        }
예제 #9
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);
            }
        }
예제 #10
0
        public IState Play()
        {
            double mistakeProb = (20 - attacker.SP) / 45.0;

            if (StaticRandom.RandDouble() < mistakeProb)
            {
                /***Mistake***/
                return(new GoalKickState(defTeam, attTeam));
            }
            else
            {
                return(new FreeKickCrossState(attTeam, defTeam, attacker));
            }
        }
예제 #11
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));
            }
        }
예제 #12
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;
                }
            }
        }
예제 #13
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));
            }
        }
예제 #14
0
        public IState Play()
        {
            double successProb = (2.25 * attacker.DRB +
                                  2.25 * (15 - defTeam.All(Position.CB)
                                          .Sum(x => x.DEF) / 3) / 100.0);

            if (StaticRandom.RandDouble() > successProb)
            {
                /***Defender tackles***/
                switch (StaticRandom.Rand(2))
                {
                case 0:
                    return(new ClearenceState(defTeam, attTeam));

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

                default:
                    return(null);
                }
            }
            else
            /***Free kick/pass/shot***/
            if (StaticRandom.RandDouble() < 0.1)
            {
                return(new FreeKickState(attTeam, defTeam));
            }
            else
            {
                double y        = attacker.FIN;
                double shotProb = 0.0085 * y * y + 0.03 * y - 1;
                y = attacker.SPS;
                double passProb = shotProb + 0.0085 * y * y + 0.03 * y - 1;
                if (StaticRandom.RandDouble(0, passProb) < shotProb)
                {
                    Player newAttacker = attTeam.All(Position.CF, Position.AM, Position.RM, Position.LM)
                                         .Where(x => x != attacker)
                                         .GetRandomElement();
                    return(new InboxShotAttemptState(attTeam, defTeam, newAttacker, defTeam.Any(Position.CB), attacker));
                }
                else
                {
                    return(new InboxShotAttemptState(attTeam, defTeam, attacker, defTeam.Any(Position.CB)));
                }
            }
        }
예제 #15
0
        public IState Play()
        {
            double throughBallProb = 1.0;
            double shotProb        = 1.0;
            double flankPassProb   = 1.0;
            double dribblingProb   = 1.0;

            double y = (attacker.SPS + attTeam.All(Position.LM, Position.RM, Position.AM, Position.CF)
                        .Where(x => x != attacker)
                        .Max(x => x.PAC)) / 2.0;

            throughBallProb += 0.0085 * y * y + 0.03 * y - 1;                            //0~20 -> -1~3
            y              = attacker.FIN;
            shotProb      += 0.0085 * y * y + 0.03 * y - 1;
            y              = (attacker.SPS + attacker.LPS) / 2.0;
            flankPassProb += 0.0085 * y * y + 0.03 * y - 1;
            if (!defTeam.IsTherePosition(Position.LB))
            {
                flankPassProb += 1.0;
            }
            y              = attacker.DRB;
            dribblingProb += 0.000001 * Math.Pow(y, 4) + 0.0071 * y * y - 1;             //0~20 -> -1~2

            shotProb      += throughBallProb;
            flankPassProb += shotProb;
            dribblingProb += flankPassProb;

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

            if (p < throughBallProb)
            {
                return(new ThroughPassState(attTeam, defTeam, attacker, counter));
            }
            else if (p < shotProb)
            {
                return(new OutboxShotAttemptState(attTeam, defTeam, attacker, defender, counter));
            }
            else if (p < flankPassProb)
            {
                return(new FlankPassState(attTeam, defTeam, attacker, counter));
            }
            else
            {
                return(new BoxDribblingState(attTeam, defTeam, attacker));
            }
        }
예제 #16
0
        public IState Play()
        {
            var defenders = defTeam.All(Position.CB, Position.DM);
            var attackers = attTeam.All(Position.CF, Position.AM, Position.LM, Position.RM)
                            .Where(x => x != attacker);
            double successProb = (2.25 * attacker.SPS - 10 * (1 + defenders.Count() - attackers.Count())) / 100.0;

            if (counter)
            {
                successProb += 2.25 * (20 - defenders.Average(x => x.DEF) / 2) / 100.0;
            }
            else
            {
                successProb += 2.25 * (20 - defenders.Average(x => x.DEF)) / 100.0;
            }
            if (StaticRandom.RandDouble() > successProb)
            {
                /***Pass is intercepted or too long***/
                switch (StaticRandom.Rand(4))
                {
                case 0:
                    return(new OutboxReboundState(attTeam, defTeam));

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

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

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

                default:
                    return(null);
                }
            }
            else
            /***Not intercepted***/
            {
                Player newAttacker = attackers
                                     .OrderByDescending(x => x.PAC + x.FIN)
                                     .GetRandomElementWithWeights();
                return(new InboxShotAttemptState(attTeam, defTeam, newAttacker, defTeam.Any(Position.CB), attacker));
            }
        }
예제 #17
0
        public static T GetRandomElementWithWeights <T>(this IEnumerable <T> collection, IEnumerable <double> weights)
        {
            if (collection.Count() != weights.Count())
            {
                return(default(T));
            }
            weights = weights.CumulativeSum();
            double prob = StaticRandom.RandDouble(0, weights.Last());

            for (int i = 0; i < weights.Count(); i++)
            {
                if (prob < weights.ElementAt(i))
                {
                    return(collection.ElementAt(i));
                }
            }
            return(default(T));
        }
예제 #18
0
        public IState Play()
        {
            double reboundProb = attacker.PAC / (defender.PAC + 20.0);

            if (StaticRandom.RandDouble() < reboundProb)
            {
                return(new OutboxShotAttemptState(attTeam, defTeam, attacker, defender));
            }
            else
            if (StaticRandom.RandDouble() < 0.5)
            {
                return(new AttackCentreState(defTeam, attTeam, "counter"));
            }
            else
            {
                return(new ClearenceState(defTeam, attTeam));
            }
        }
예제 #19
0
        public NoMomentsState(Lineup _team1, Lineup _team2)
        {
            team1       = _team1;
            team2       = _team2;
            type        = State.NO_MOMENTS;
            haveChanged = false;
            double att1Prob;                                                             //First team
            double x = team1.Power / team2.Power;                                        //attack probability

            att1Prob = x >= 1 ? 1.0 / Math.PI * Math.Atan(0.6 * (x - 1.0)) + 0.5 :
                       1.0 - 1.0 / Math.PI * Math.Atan(0.6 * (1.0 / x - 1.0)) - 0.5;
            att1Prob = Math.Pow(att1Prob + 0.5, 12) - 0.5;
            if (StaticRandom.RandDouble() > att1Prob)
            {
                team1       = _team2;
                team2       = _team1;
                haveChanged = true;
            }
        }
예제 #20
0
        public IState Play()
        {
            double shooterAbility = (attacker.FIN + attacker.SP) / 2.0;
            double goalProb       = shooterAbility + 2 - goalkeeper.GK;

            double[] shotWeights = { 2 / shooterAbility, 1.0, 0.5, 1.0 };                //miss, left, centre, right
            double[] gkWeights = { 1.0, 0.4, 1.0 };                                      //left, centre, right
            char     shotDir = new char[] { 'm', 'l', 'c', 'r' }.GetRandomElementWithWeights(shotWeights);
            char     gkDir;

            if (StaticRandom.RandDouble() < 0.33)                                        //GK reacts
            {
                gkDir     = shotDir;
                goalProb += 1;
            }
            else
            {
                gkDir = new char[] { 'l', 'c', 'r' }
            }.GetRandomElementWithWeights(gkWeights);
예제 #21
0
        public IState Play()
        {
            double successProb = (4 * attacker.LPS + 10) / 100.0;

            if (StaticRandom.RandDouble() < successProb)
            {
                /***Not intercepted***/
                if (left)
                {
                    return(new AttackSideState(attTeam, defTeam, 'r'));
                }
                else
                {
                    return(new AttackSideState(attTeam, defTeam, 'l'));
                }
            }
            else
            {
                /***Switch is intercepted***/
                switch (StaticRandom.Rand(3))
                {
                case 0:
                    return(new NoMomentsState(attTeam, defTeam));

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

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

                default:
                    return(null);
                }
            }
        }
예제 #22
0
        public IState Play()
        {
            double reboundProb = attacker.PAC / (defender.PAC + 20.0);

            if (StaticRandom.RandDouble() < reboundProb)
            {
                /***Rebound by offence***/
                return(new ShotState(attTeam, defTeam, attacker, "inbox"));
            }
            else
            /***rebound by defence***/
            if (StaticRandom.RandDouble() < 0.5)
            {
                return(new CornerState(attTeam, defTeam));
            }
            else
            {
                return(new ClearenceState(defTeam, attTeam));
            }
        }
예제 #23
0
        public IState Play()
        {
            double successProb = (2.25 * attacker.LPS + 5 + 2.25 * 10) / 100.0;

            if (!counter)
            {
                successProb += 2.25 * (10 - defender.DEF) / 100;
            }
            if (StaticRandom.RandDouble() > successProb)
            {
                /***Cross is blocked***/
                switch (StaticRandom.Rand(3))
                {
                case 0:
                    if (left)
                    {
                        return(new ThrowInState(attTeam, defTeam, 'l'));
                    }
                    else
                    {
                        return(new ThrowInState(attTeam, defTeam, 'r'));
                    }

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

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

                default:
                    return(null);
                }
            }
            else
            {
                /***Not blocked - cross***/
                return(new LowCrossState(attTeam, defTeam, attacker));
            }
        }
예제 #24
0
        public IState Play()
        {
            double y        = attacker.FIN - defender.DEF + 7;
            double shotProb = (-0.0125 * y * y + 3 * y + 50) / 100;

            if (counter)
            {
                shotProb = 1.5 * shotProb / (shotProb + 0.5);
            }
            if (StaticRandom.RandDouble() > shotProb)
            /***Shot is blocked***/
            {
                switch (StaticRandom.Rand(3))
                {
                case 0:
                    return(new CornerState(attTeam, defTeam));

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

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

                default:
                    return(null);
                }
            }
            else
            /***Not blocked - shot***/
            if (StaticRandom.RandDouble() < 0.16)
            {
                return(new FreeKickState(attTeam, defTeam));
            }
            else
            {
                return(new ShotState(attTeam, defTeam, attacker, "outbox"));
            }
        }
예제 #25
0
        public IState Play()
        {
            double defProb;
            double y = attacker.FIN - defender.DEF + 7;

            defProb = (-0.0125 * y * y + 3 * y + 50) / 100;
            if (StaticRandom.RandDouble() > defProb)
            /***Shot is blocked***/
            {
                switch (StaticRandom.Rand(4))
                {
                case 0:
                    return(new CornerState(attTeam, defTeam));

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

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

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

                default:
                    return(null);
                }
            }
            else
            /***Not blocked - penalty/shot***/
            if (StaticRandom.RandDouble() < 0.05)
            {
                return(new PenaltyState(attTeam, defTeam));
            }
            else
            {
                return(new ShotState(attTeam, defTeam, attacker, "inbox", assist));
            }
        }
예제 #26
0
        public IState Play()
        {
            double shotProb  = 1.0;
            double crossProb = 1.0;

            crossProb += (attTeam.All()
                          .Select(x => x.HEA)
                          .OrderByDescending(y => y)
                          .Take(6)
                          .Average() - 14) / 10.0;

            crossProb += shotProb;
            double p = StaticRandom.RandDouble(0, crossProb);

            if (p < shotProb)
            {
                return(new FreeKickShotState(attTeam, defTeam, attacker));
            }
            else
            {
                return(new FreeKickCrossState(attTeam, defTeam, attacker));
            }
        }
예제 #27
0
        public IState Play()
        {
            double shortThrow = 1.0;
            double longThrow  = 0.3 + (attacker.SP - 12) / 12.0;

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

            if (p < shortThrow)
            {
                if (left)
                {
                    return(new AttackSideState(attTeam, defTeam, 'l'));
                }
                else
                {
                    return(new AttackSideState(attTeam, defTeam, 'r'));
                }
            }
            else
            {
                return(new BoxCrossState(attTeam, defTeam, attacker));
            }
        }
예제 #28
0
        public IState Play()
        {
            double y;
            double shotProb;
            double goalProb;

            if (type == State.INBOX_SHOT)
            {
                y        = attacker.FIN;
                shotProb = (-1.0 / 12.0 * y * y + 39.0 / 12.0 * y + 30.0) / 100.0;
                goalProb = y / (goalkeeper.GK * 13.0 / 6.0 + 5.0);
            }
            else if (type == State.OUTBOX_SHOT)
            {
                y        = attacker.FIN;
                shotProb = (1.0 / 12.0 * y * y + 13.0 / 12.0 * y + 15.0) / 100.0;
                goalProb = y / (goalkeeper.GK * 33.0 / 6.0 + 5.0);
            }
            else if (type == State.HEADER)
            {
                y        = (attacker.FIN + attacker.HEA) / 2.0;
                shotProb = (1.0 / 12.0 * y * y + 13.0 / 12.0 * y + 15.0) / 100.0;
                goalProb = y / (goalkeeper.GK * 27.0 / 6.0 + 5.0);
            }
            else
            {
                return(null);
            }
            if (StaticRandom.RandDouble() > shotProb)
            {
                /***Miss***/
                return(new GoalKickState(defTeam, attTeam));
            }
            else
            {
                if (StaticRandom.RandDouble() < goalProb)
                {
                    /***Goal***/
                    return(new GoalState(attTeam, defTeam, attacker, assist));
                }
                else
                {
                    /***GK saves***/
                    switch (StaticRandom.Rand(4))
                    {
                    case 0:
                    case 1:
                        return(new CornerState(attTeam, defTeam));

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

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

                    default:
                        return(null);
                    }
                }
            }
        }
예제 #29
0
 public static double AttributesDistribution(double a)
 {
     return(a > 0 ? a : Math.Round(StaticRandom.RandDouble((-2 * a), (-2 * a + 2)), 1));
 }
예제 #30
0
        public IState Play()
        {
            double boxCrossProb    = 1.5;
            double lowCrossProb    = 1.5;
            double pitchCrossProb  = 0.5;
            double centrePassProb  = 1.0;
            double shotProb        = 0.5;
            double dribblingProb   = 1.0;
            double defenderRunProb = 1.0;

            if (left & (!attTeam.IsTherePosition(Position.LB) ||
                        !attTeam.IsTherePosition(Position.LM)) ||
                !left & (!attTeam.IsTherePosition(Position.RB) ||
                         !attTeam.IsTherePosition(Position.RM)))
            {
                defenderRunProb = 0;
            }
            double y = (attTeam.All(Position.CF, Position.AM)
                        .Max(x => x.HEA) + attacker.LPS) / 2.0;

            boxCrossProb += 0.00061 * y * y * y - 0.0024 * y * y + 0.004 * y - 1;        //0~20 -> -1~3
            lowCrossProb += 0.00085 * y * y * y - 0.0243 * y * y - 0.054 * y + 3;        //0~20 -> 3~-1
            y             = attacker.FIN;
            shotProb     += 0.0085 * y * y + 0.03 * y - 1;                               //0~20 -> -1~3
            y             = (attacker.SPS + attTeam.All(Position.DM, Position.AM, Position.CM)
                             .Max(x => x.BestOVR)) / 2.0;
            centrePassProb += 0.0085 * y * y + 0.03 * y - 1;
            y = (attacker.LPS + (left ? attTeam.All(Position.RM, Position.RB)
                                 .Max(x => x.BestOVR)
                                : attTeam.All(Position.LM, Position.LB)
                                 .Max(x => x.BestOVR))) / 2.0;
            pitchCrossProb += 0.0085 * y * y + 0.03 * y - 1;
            y              = attacker.DRB;
            dribblingProb += 0.000001 * Math.Pow(y, 4) + 0.0071 * y * y - 1;             //0~20 -> -1~2

            lowCrossProb    += boxCrossProb;
            pitchCrossProb  += lowCrossProb;
            centrePassProb  += pitchCrossProb;
            shotProb        += centrePassProb;
            dribblingProb   += shotProb;
            defenderRunProb += dribblingProb;

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

            if (p < boxCrossProb)
            {
                return(new BoxCrossAttemptState(attTeam, defTeam, attacker, defender, left, counter));
            }
            else if (p < lowCrossProb)
            {
                return(new LowCrossAttemptState(attTeam, defTeam, attacker, defender, left, counter));
            }
            else if (p < pitchCrossProb)
            {
                return(new PitchCrossState(attTeam, defTeam, attacker, left));
            }
            else if (p < centrePassProb)
            {
                return(new CentrePassState(attTeam, defTeam, attacker, counter));
            }
            else if (p < shotProb)
            {
                return(new OutboxShotAttemptState(attTeam, defTeam, attacker, defender, counter));
            }
            else if (p < dribblingProb)
            {
                return(new BoxDribblingState(attTeam, defTeam, attacker));
            }
            else
            {
                return(new DefenderRunState(attTeam, defTeam, defender, left, counter));
            }
        }