private void AdjustLinearly(Player player, double value, double spread)
 {
     if (player != null)
     {
         double adjustment = MathHelper.LinearAdjustment(value, spread, random.Value(0, 1));
         player.AdjustRating(adjustment);
     }
 }
 public void OnPass(Player passingPlayer, Player receiver, Player opponent, bool isSuccessful)
 {
     if (isSuccessful)
     {
         AdjustExponentiallyRight(passingPlayer, 0.000, 0.010);
         AdjustExponentiallyLeft(opponent, 0.000, 0.010);
     }
     else
     {
         AdjustLinearly(passingPlayer, -0.015, 0.005);
         AdjustLinearly(opponent, 0.020, 0.005);
     }
 }
 public void OnDribble(Player dribbler, Player opponent, bool isSuccessful)
 {
     if (isSuccessful)
     {
         AdjustExponentiallyRight(dribbler, 0.005, 0.010);
         AdjustLinearly(opponent, -0.015, 0.005);
     }
     else
     {
         AdjustLinearly(dribbler, -0.015, 0.005);
         AdjustLinearly(opponent, 0.020, 0.005);
     }
 }
        public void OnShoot(Player shooter, Player assistant, Player opponent, Player goalkeeper, ShotResult result)
        {
            if (result == ShotResult.Scored)
            {
                AdjustLinearly(shooter, 0.100, 0.020);
                AdjustExponentiallyRight(assistant, 0.030, 0.070);
                AdjustExponentiallyLeft(opponent, -0.020, 0.040);
                AdjustExponentiallyLeft(goalkeeper, -0.020, 0.060);

                foreach (var player in shooter.Team.Squad)
                {
                    AdjustLinearly(player, 0.025, 0.010);
                }

                foreach (var player in opponent.Team.Squad)
                {
                    AdjustLinearly(player, -0.025, 0.010);
                }
            }
            else if (result == ShotResult.Blocked)
            {
                AdjustLinearly(shooter, -0.005, 0.005);
                AdjustExponentiallyRight(opponent, 0.030, 0.030);
            }
            else if (result == ShotResult.Missed)
            {
                AdjustExponentiallyLeft(shooter, 0.010, 0.020);
                AdjustExponentially(opponent, -0.005, 0.010);
            }
            else if (result == ShotResult.Saved)
            {
                AdjustExponentially(shooter, 0.010, 0.030);
                AdjustExponentially(opponent, -0.005, 0.010);
                AdjustExponentiallyRight(goalkeeper, 0.040, 0.040);
            }
            else
            {
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Shot result {0} not supported", result));
            }
        }
Пример #5
0
        public ShotResult TryShoot(Player assistant, Player opponent, Player goalkeeper)
        {
            ShotResult result = randomizer.TryShoot(
                shooting: OffensiveSkills + Form,
                blocking: opponent.DefensiveSkills + opponent.Form,
                goalkeeping: goalkeeper.DefensiveSkills + goalkeeper.Form);

            if (result == ShotResult.Scored)
            {
                Goals += 1;
                ShotsOnTarget += 1;
                opponent.ShotsAllowed += 1;
                goalkeeper.ShotsNotSaved += 1;

                if (assistant != null)
                {
                    assistant.Assists += 1;
                }
            }
            else if (result == ShotResult.Saved)
            {
                ShotsOnTarget += 1;
                opponent.ShotsAllowed += 1;
                goalkeeper.ShotsSaved += 1;
            }
            else if (result == ShotResult.Missed)
            {
                ShotsMissed += 1;
                opponent.ShotsAllowed += 1;
            }
            else if (result == ShotResult.Blocked)
            {
                ShotsBlocked += 1;
                opponent.ShotsPrevented += 1;
            }
            else
            {
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Shot result {0} not supported", result));
            }

            return result;
        }
 private void AdjustExponentiallyRight(Player player, double value, double spread)
 {
     if (player != null)
     {
         double adjustment = MathHelper.RightExponentialAdjustment(value, spread, random.Value(0, 1));
         player.AdjustRating(adjustment);
     }
 }
Пример #7
0
        private double ChanceToConfrontPlayer(Player opponent)
        {
            Position oppositePosition = opponent.Position.Opposite();
            int distanceForward = oppositePosition.DistanceForward(Position);
            int distanceSideways = oppositePosition.DistanceSideways(Position);

            double chance = 10;

            if (distanceForward > 0)
            {
                chance = 2.0 / distanceForward;
            }
            else if (distanceForward == 0)
            {
                chance = 10.0;
            }
            else
            {
                chance = 5.0 / (-distanceForward);
            }

            if (distanceSideways > 0)
            {
                chance /= 2 * distanceSideways;
            }

            if (IsGoalkeeper)
            {
                chance /= 5;
            }

            return chance;
        }
Пример #8
0
 public double ChanceToConfrontShooter(Player shooter)
 {
     return ChanceToConfrontPlayer(shooter);
 }
Пример #9
0
 public void AddSquadPlayer(Player player)
 {
     squad.Add(player);
 }
Пример #10
0
        public void OnDribble(Player opponent, bool isSuccessful)
        {
            events.Add(new DribbleEvent(Minute, ExtendedMinute, CurrentPlayer, opponent));

            if (!isSuccessful)
            {
                PreviousPlayer = CurrentPlayer;
                CurrentPlayer = null;
            }
        }
Пример #11
0
 public void InitiateAttack(Player player)
 {
     PreviousPlayer = null;
     CurrentPlayer = player;
 }
Пример #12
0
        public bool TryDribble(Player opponent)
        {
            bool isSuccessful = randomizer.TryDribble(
                dribbling: OffensiveSkills + Form,
                tackling: opponent.DefensiveSkills + opponent.Form);

            if (isSuccessful)
            {
                DribblesCompleted += 1;
                opponent.TacklesFailed += 1;
            }
            else
            {
                DribblesFailed += 1;
                opponent.TacklesCompleted += 1;
            }

            return isSuccessful;
        }
Пример #13
0
        public bool TryPass(Player receiver, Player opponent)
        {
            bool isSuccessful = randomizer.TryPass(
                passing: OffensiveSkills + Form,
                positioning: receiver.OffensiveSkills + receiver.Form,
                marking: opponent.DefensiveSkills + opponent.Form);

            if (isSuccessful)
            {
                PassesCompleted += 1;
                opponent.PassesAllowed += 1;
            }
            else
            {
                PassesFailed += 1;
                opponent.PassesIntercepted += 1;
            }

            return isSuccessful;
        }
Пример #14
0
 public Player PickPlayerToConfrontShooter(Player shooter)
 {
     var chances = squad.Select(p => p.ChanceToConfrontShooter(shooter)).ToArray();
     return random.PlayerConfrontingShooter(squad, chances);
 }
Пример #15
0
 public Player PickPlayerToConfrontDribbler(Player dribbler)
 {
     var chances = squad.Select(p => p.ChanceToConfrontDribbler(dribbler)).ToArray();
     return random.PlayerConfrontingDribbler(squad, chances);
 }
Пример #16
0
 public Player PickPlayerToMarkPassReceiver(Player receiver)
 {
     var chances = squad.Select(p => p.ChanceToMarkPassReceiver(receiver)).ToArray();
     return random.PlayerMarkingPassReceiver(squad, chances);
 }
Пример #17
0
 public Player PickPlayerToReceivePass(Player passingPlayer)
 {
     var chances = squad.Select(p => p.ChanceToReceivePass(passingPlayer, Strategy)).ToArray();
     return random.PlayerReceivingPass(squad, chances);
 }
Пример #18
0
        public double ChanceToReceivePass(Player passingPlayer, TeamStrategy strategy)
        {
            if (passingPlayer == this)
            {
                return 0;
            }
            else
            {
                int distanceForward = passingPlayer.Position.DistanceForward(Position);
                int distanceSideways = passingPlayer.Position.DistanceSideways(Position);

                double chance = 1;
                
                if (distanceForward > 0)
                {
                    chance = 10.0 / distanceForward;
                }
                else if (distanceForward == 0)
                {
                    chance = 5.0;
                }
                else
                {
                    chance = 1.0 / (-distanceForward);
                }

                if (distanceSideways > 0)
                {
                    chance /= distanceSideways;
                }

                if (IsStrategicPlayer(strategy) && !passingPlayer.IsStrategicPlayer(strategy))
                {
                    chance *= 1.5;
                }

                if (IsForward)
                {
                    chance *= 2.0;
                }

                if (IsGoalkeeper)
                {
                    chance /= 5;
                }

                return chance;
            }
        }
Пример #19
0
 public double ChanceToMarkPassReceiver(Player receiver)
 {
     return ChanceToConfrontPlayer(receiver);
 }
Пример #20
0
        public void OnPass(Player receiver, Player opponent, bool isSuccessful)
        {
            events.Add(new PassEvent(Minute, ExtendedMinute, CurrentPlayer, receiver, opponent));

            PreviousPlayer = CurrentPlayer;
            CurrentPlayer = isSuccessful ? receiver : null;
        }
Пример #21
0
 public double ChanceToConfrontDribbler(Player dribbler)
 {
     return ChanceToConfrontPlayer(dribbler);
 }
Пример #22
0
        public void OnShoot(Player opponent, ShotResult result)
        {
            events.Add(new ShootEvent(Minute, ExtendedMinute, CurrentPlayer, opponent, result));

            if (result == ShotResult.Scored)
            {
                IncreaseScore(CurrentPlayer.Team);
                events.Add(new GoalEvent(CurrentPlayer.Team == Team1, Minute, ExtendedMinute, CurrentPlayer, PreviousPlayer));
            }

            PreviousPlayer = CurrentPlayer;
            CurrentPlayer = null;
        }
Пример #23
0
        public IMatchAction NextAction(int level, Player player)
        {
            Func<IMatchAction>[] actions =
            {
                () => new PassAction(),
                () => new DribbleAction(),
                () => new ShootAction()
            };

            if (player.Position.Location == Location.Goal)
            {
                return new PassAction();
            }
            else if (player.Position.Location == Location.Back)
            {
                switch (level)
                {
                    case 1: return random.Choose(actions, 0.90, 0.10, 0)();
                    case 2: return random.Choose(actions, 0.85, 0.10, 0.05)();
                    case 3: return random.Choose(actions, 0.75, 0.10, 0.15)();
                    case 4: return random.Decide(0.1) ? (IMatchAction)new ShootAction() : new NullAction();
                    default: return new NullAction();
                }
            }
            else if (player.Position.Location == Location.Defensive)
            {
                switch (level)
                {
                    case 1: return random.Choose(actions, 0.80, 0.20, 0)();
                    case 2: return random.Choose(actions, 0.80, 0.15, 0.05)();
                    case 3: return random.Choose(actions, 0.70, 0.15, 0.15)();
                    case 4: return random.Decide(0.1) ? (IMatchAction)new ShootAction() : new NullAction();
                    default: return new NullAction();
                }
            }
            else if (player.Position.Location == Location.Forward)
            {
                switch (level)
                {
                    case 1: return random.Choose(actions, 0.50, 0.50, 0)();
                    case 2: return random.Choose(actions, 0.35, 0.55, 0.10)();
                    case 3: return random.Choose(actions, 0.35, 0.45, 0.20)();
                    case 4: return random.Decide(0.1) ? (IMatchAction)new ShootAction() : new NullAction();
                    default: return new NullAction();
                }
            }
            else
            {
                switch (level)
                {
                    case 1: return random.Choose(actions, 0.67, 0.33, 0)();
                    case 2: return random.Choose(actions, 0.65, 0.30, 0.05)();
                    case 3: return random.Choose(actions, 0.60, 0.25, 0.15)();
                    case 4: return random.Decide(0.1) ? (IMatchAction)new ShootAction() : new NullAction();
                    default: return new NullAction();
                }
            }
        }