示例#1
0
 public void Play()
 {
     homeLineup = HomeTeam.ChooseLineupHungarian();
     awayLineup = AwayTeam.ChooseLineupHungarian();
     Stats      = new MatchFSM(HomeLineup, AwayLineup).Start();
     hasPlayed  = true;
 }
示例#2
0
        public Lineup ChooseLineupHungarian()
        {
            if (Squad.Count() < 11)
            {
                return(null);
            }
            Lineup          eleven        = new Lineup();
            double          minSum        = double.MaxValue;
            List <Position> bestFormation = new List <Position>();

            int[] bestLineup = new int[11];

            foreach (var formation in Formations)
            {
                double[,] m = new double[Squad.Count(), Squad.Count()];
                //Creating the matrix
                int i = 0;
                foreach (Player p in Squad)
                {
                    for (int j = 0; j < 11; j++)
                    {
                        m[i, j] = 20 - p.OVRByPosition(formation[j]);
                    }
                    for (int j = 11; j < Math.Max(formation.Count, Squad.Count()); j++)
                    {
                        m[i, j] = 20;
                    }
                    i++;
                }
                //Solving the system
                int[]  answer = new HungarianAlgorithm(m).Solve().Take(11).ToArray();
                double sum    = 0;
                for (int j = 0; j < 11; j++)
                {
                    sum += m[answer[j], j];
                }

                var newsum = sum;
                //If team has more skilled attacking players, offensive formations are in priority and vice versa
                if (Style() < 1 &&
                    formation.Count(x => x == Pos.CB || x == Pos.DM) > 3 &&
                    formation.Count(x => x == Pos.CF || x == Pos.AM) < 3)
                {
                    sum *= 1.005;
                }
                if (Style() > 1 &&
                    formation.Count(x => x == Pos.CF || x == Pos.AM) > 2)
                {
                    sum *= 1.005;
                }
                //Updating the best formation if necessary
                if (sum < minSum)
                {
                    minSum        = sum;
                    bestFormation = new List <Position>(formation);
                    bestLineup    = answer;
                }
            }
            for (int i = 0; i < 11; i++)
            {
                eleven.Add(Squad[bestLineup[i]], bestFormation[i]);
            }
            return(eleven);
        }
示例#3
0
 public MatchStats(Lineup h, Lineup a)
 {
     homeGoals = 0;
     awayGoals = 0;
     goals     = new List <Goal>();
 }