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();
                }
            }
        }